University | Singapore University of Social Science (SUSS) |
Subject | ANL252: Python for Data Analytics |
Question
The probability density function (pdf) of the normal distribution is given by
where x is the observed value of a random variable X, π is the value of the constant pi (≈ 3.14159), µ is the mean and σ2 is the variance of the distribution, and exp() is the exponential function.
As an analyst and Python programming specialist, you are asked to construct a program to compute the probability of a normally distributed random variable given the distribution mean and variance.
Note: Include your Python program code in the answers and show them in the “Consolas” or “Courier New” fonts (size 12). Make a screenshot of the program output if required.
(a) Prepare the programming of the function by importing the “math” package into your program which is needed for the square root and the exponential functions. You can also find a much more exact value for π in the math package. Refer to the official website of the math package https://docs.python.org/3/library/math.html for more details of the functions.
(b) Employ a Python program to ask the user to enter the mean and variance of the distribution. Tell the user that the mean can be any value between minus infinity (–∞) and plus infinity (+∞), but the variance must be a value larger than 0. Integrate certain control mechanism to ensure that the variance condition is fulfilled, and the input is numeric. If the user press ENTER without providing any values, the program will automatically set µ to 0 and σ2 to 1.
(c) Design an input screen for the user to enter the value of X. Tell the user that the value can be any value between minus infinity (–∞) and plus infinity (+∞). Integrate certain control mechanism to ensure that the input is numeric.
(d) Construct a user-defined function using the formula of the probability density function given above to compute the corresponding probability density fX(x) based on the user inputs in (b) and (c).
(e) Use formatted printing to display the result of (d) to the user.
(f) The probability of a normally distributed random variable X smaller equal to a value k can be determined by the cumulative distribution function (cdf) which can be approximated by the weighted sum of the density function of X from –∞ to k:
𝑃𝑃(𝑋𝑋 ≤ 𝑘𝑘) ≈ 𝛼𝛼[𝑓𝑓𝑋𝑋(𝑎𝑎) + ⋯ + 𝑓𝑓𝑋𝑋(𝑘𝑘 − 2𝛼𝛼) + 𝑓𝑓𝑋𝑋(𝑘𝑘 − 𝛼𝛼) + 𝑓𝑓𝑋𝑋(𝑘𝑘)],
where α is the range of each step and a is a number close to –∞. For example, if we choose α = 0.01, a = -100 and k = 0, then the summation is
𝑃𝑃(𝑋𝑋 ≤ 0) ≈ 0.01[𝑓𝑓𝑋𝑋(−100) + ⋯ + 𝑓𝑓𝑋𝑋(−0.02) + 𝑓𝑓𝑋𝑋(−0.01) + 𝑓𝑓𝑋𝑋(0)]
The accuracy of the approximation increases with the decrease of the step range α. That means, the smaller the step width is, the more terms we can put between a and k, and the more accurate is the probability.
Design a program to compute P(X ≤ k) where k is the value that the user entered in (c). Use the user input in (b) as the values for the parameters µ and σ2 and display the result to the user by formatted printing. Furthermore, check the results for k = 0, 1.64, and 1.96 with a mean of 0 and variance of 1 as well.
(g) Explain your program for the calculation of P(X ≤ k) in (f) in less than 200 words.
(h) Create a dictionary to store the probabilities of the normal distribution for x = {-5, -4.9, -4.8, …, 0, 0.1, 0.2, …, 4.8, 4.9, 5} where x are the keys, and the corresponding probabilities are the values of the dictionary.
The distribution mean here is 0 and variance is 1. Print all the probabilities (with the corresponding x) of those x’s between -2 and 2 with a step width of 0.5 from the dictionary onto the screen.
Are you a Singapore university student? Need cheap assignment help to complete your ANL252: Python for Data Analytics Assignment? then don't need to look further. At Singapore Assignment Help we have a huge team of experts who have a great ability to serve step by step guidance on creating authentic and plagiarism free answers on python programming assignments at a nominal price. So hurry up and get an outstanding grade on your python assignment.
Looking for Plagiarism free Answers for your college/ university Assignments.
- BUS 304 Assignment: Strategic Analysis of Accounting Standards & Corporate Ethics
- RBP020L056 A Strategic Management Assignment Report: External & Internal Analysis with Strategic Options for Business Growth
- Capital Budgeting Assignment Report: PIONG Corporation Case Study on Risk & Investment Analysis
- BCAF003 Business Accounting Assignment : Temasek Polytechnic Case Study on Transactions, Equity & Trial Balance
- 304SE Energy Systems Assignment: Boiler Efficiency & 3-Bus Power Flow Case Study with Carbon Emission Analysis
- SM9532 International Expansion Strategy Assignment Report: CAGE, PND & AAA Analysis for Global Market Entry
- PSB6023CL Strategy and International Business Simulation Assignment Report: Automotive Case Study on Strategic Decision-Making and Performance Review
- ESG in Maritime Industry Assignment : Literature Review on Environmental, Social and Governance Practices
- CVE2332 Seepage and Flownet Analysis Assignment : Singapore River Cofferdam Case Study for Cost-Effective Sheet Pile Design
- DSWSH MC2 Electronic Security Assignment: Protection in Depth Plan for American International School (AIS) Singapore