Using Python 3
Exercise 4: Numeric integration (challenging)
Recall from your statistics or econometrics class that the probability density function (pdf) of a normal distribution with mean ΓΒΌ and variance ΓΖ^2 is given by 1/(ΓΖΓ’ΛΕ‘(2Γβ¬)) * e^(-(x-ΓΒΌ)^2/(2ΓΖ^2)).
The corresponding cumulative distribution function (cdf) is F(x).
Unfortunately, the cdf F(x) does not have a closed-form expression, so we cannot compute this integral by hand. Instead, we use a technique called numeric integration (i.e., a computer) to calculate the value of the cdf at a given point.
One simple but reasonably accurate numeric integration technique is the trapezoid rule, which is taught in every introductory calculus course. The trapezoid rule approximates the area under a curve g(x) with the area of N trapezoids of equal width. Formally,
Γ’ΛΒ«f(x)dx Γ’β°Λ ΓΒ£(0.5 * (f[k] + f[k + 1]) * x)
where x = (b-a)/N.
In this exercise, your task is to calculate the value of the cdf of the standard normal distribution (i.e., ΓΒΌ = 0 and ΓΖ^2 = 1) at x = 1.96. We will do it two ways. First on our own (to practice some list comprehensions) and then, the easy way, using the norm function from scipy.