Hands-on: Kolmogorov-Smirnov test

In [90]:
from scipy import stats
import numpy as np
import matplotlib.pyplot as plt
In [91]:
np.random.seed(82154321)
g_normal = stats.norm.freeze(scale=1) # Gaussian with sigma = 1
g_wide = stats.norm.freeze(scale=1.4) # Gaussian with sigma = 1.4

# generate data from wide Gaussian
x = g_wide.rvs(size=100)
In [95]:
# plot generated data and the two distributions
plt.hist(x, bins=20, histtype='step', density=True);
xv = np.linspace(-4, 4, 100)
plt.plot(xv, g_normal.pdf(xv), color='blue')
plt.plot(xv, g_wide.pdf(xv), color='red')
Out[95]:
[<matplotlib.lines.Line2D at 0x122c89850>]

Can you reject the hypothesis that the data come from a standard normal distribution at a 95\% confidence level?

In [1]:
# your code here
# hint: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.kstest.html