The standard Normal distribution#
The standard normal distribution is perhaps the most recognizable continuous distribution. It has that characteristic bell shape. We write:
and we read it as:
follows the standard Normal.
Now the 0 in
The PDF of the standard Normal#
We commonly use the function
So, this is an exponential that has
Here is how you can make a standard Normal in scipy.stats
:
Show code cell source
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set(rc={"figure.dpi":100, 'savefig.dpi':300})
sns.set_context('notebook')
sns.set_style("ticks")
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('retina', 'svg')
import numpy as np
import scipy.stats as st
Z = st.norm()
And here are some samples from it:
Z.rvs(size=10)
array([ 0.07650491, -0.55433992, 0.35401783, 0.26572118, -0.5496704 ,
0.47381155, -0.53989222, 1.13163748, 1.23093609, 0.42745344])
And here is the PDF of the standard normal:
fig, ax = plt.subplots()
zs = np.linspace(-6.0, 6.0, 100)
ax.plot(zs, Z.pdf(zs))
ax.set_xlabel('$z$')
ax.set_ylabel('$\phi(z)$');
Here are some important properties of the PDF of the standard Normal:
First,
is positive for all .Second, as
goes to or , goes to zero.Third,
has a unique mode (maximum) at . In other words, is the most probable point under this distribution.Fourth,
is symmetric about . Mathematically:
Let’s test some of them using scipy.stats
.
Z.pdf(np.inf)
0.0
Z.pdf(-np.inf)
0.0
Z.pdf(-5) == Z.pdf(5)
True
Expectation of the standard normal#
The expectation of
You can prove this quite easily by invoking the fact that
Here it is in scipy.stats
:
Z.expect()
0.0
Variance of the standard normal#
The variance of
You need integration by parts to prove this. Let’s do it.
Note that the standard deviation of
Again, here it is in scipy.stats
:
Z.var()
1.0
The CDF of the standard Normal#
The CDF of
where
fig, ax = plt.subplots()
ax.plot(zs, Z.cdf(zs))
ax.set_xlabel('$z$')
ax.set_ylabel('$\Phi(z)$');
Some properties of the CDF of the standard normal#
First, note that:
This follows very easily from the symmetry of the PDF
Now here is a non-trivial property.
Take any number
Before attempting to prove this property, let’s demonstrate it visually.
Take
On other hand,
Notice that we used the fact that
Alright, so visually, the expression
Show code cell source
fig, ax = plt.subplots()
ax.plot(zs, Z.pdf(zs))
z = 1
zsb = np.linspace(-6.0, -z, 100)
zsa = np.linspace(z, 6.0, 100)
ax.fill_between(zsb, 0.0, Z.pdf(zsb), color='b', alpha=0.5)
ax.fill_between(zsa, 0.0, Z.pdf(zsa), color='r', alpha=0.5)
ax.set_xlabel('$z$')
ax.set_ylabel('$\phi(z)$');
And this makes a lot of sense since
The probability that
is smaller than is the same as the probability that is greater than .
The formal proof is actually trivial. It goes like this:
after applying the transformation
which as we saw above is the same as
Let’s demonstrate this in scipy.stats
:
print('p(Z <= -1) = {0:1.3f}'.format(Z.cdf(-1)))
p(Z <= -1) = 0.16
And this should be the same as the probability that
print('p(Z >= 1) = {0:1.3f}'.format(1 - Z.cdf(1)))
p(Z >= 1) = 0.16
What is the probability that
In scipy.stats
:
print('p(-1 < Z < 1) = {0:1.3f}'.format(1 - 2.0 * Z.cdf(-1)))
p(-1 < Z < 1) = 0.683
Questions#
Modify the code above to find the probability that
is between -2 and 2.Repeat for
between -3 and 3.