# The Normal distribution

# The Normal distributionΒΆ

The Normal (or Gaussian) distribution is a ubiquitous one. It appears over and over again. You must already have seen it when playing with the Binomial or the Poisson. There are two explanations as to why the Normal appears so often:

It is the distribution of maximum uncertainty that matches a known mean and a known variance variance. This comes from the principle of maximum entropy, a rather advanced concept that we are not going to deal with.

It is the distribution that arises when you sum up a lot of independent random variables together. This result is known as the central limit theorem.

We write:

\(X\) follows a Normal distribution with mean \(\mu\) and variance \(\sigma^2\).

So, for \(\mu=0\) and \(\sigma^2=1\), we get the standard Normal.

The PDF is of \(X\) is:

The mean of \(X\) is:

and the variance is:

Of course, the standard deviation of \(X\) is just \(\sigma\).

Here is how to define a Normal variable in `scipy.stats`

:

```
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
```

```
mu = 5.0
sigma = 2.0
X = st.norm(loc=mu, scale=sigma)
```

Here are some samples:

```
X.rvs(size=10)
```

```
array([4.71298088, 2.02774527, 4.15434688, 7.33551347, 7.46140639,
4.99374955, 7.37227007, 3.90204533, 4.59752625, 1.44135215])
```

Here is the PDF of \(X\):

```
fig, ax = plt.subplots()
xs = np.linspace(mu - 6.0 * sigma, mu + 6.0 * sigma, 100)
ax.plot(xs, X.pdf(xs))
ax.set_xlabel('$x$')
ax.set_ylabel('$p(x)$');
```

Notice that this is just a scaled version of of the standard Normal PDF:

So the PDF of \(X\) is the same as the standard Normal but at a different scale. This is a very useful observation as it allows us to prove the formula for the mean of \(X\). Indeed we have:

Change integration variable to \(z = \frac{x-\mu}{\sigma}\), and you get:

since \(\mathbf{E}[Z]=0\). Similarly, you can show that \(\mathbf{V}[X] = \sigma^2\).

There is also a connection between the CDF of \(X\), call it \(F(x) = p(X\le x)\) and the CDF of the standard Normal \(\Phi(z)\). It is:

We can formally prove this as follows:

Now change integration variable to \(\tilde{z} = \frac{\tilde{x} - \mu}{\sigma}\). We have that:

Okay, so if you plot the CDF of \(X\) it looks exactly like the CDF of the standard normal at a different scale. Here it is:

```
fig, ax = plt.subplots()
ax.plot(xs, X.cdf(xs))
ax.set_xlabel('$x$')
ax.set_ylabel('$F(x)$');
```