import numpy as np
import matplotlib.pyplot as plt
import scipy as spCentral Limit Theorem
Suppose \(X_1, \ldots, X_N\) are random variables from any distribution with common location \(\mathbb{E}[X] = \mu\) and common variance \(\mathbb{V}[X] = \sigma^2 < \infty\), then a properly shifted and scaled mean of the random variable approximately follows a standard Normal distribution:
\[\frac{\frac{1}{N}\sum_n^N X_n - \mu}{\sqrt{\sigma^2 / N}} \sim \text{Normal}(0, 1)\].
The approximation improves as \(N \to \infty\).
K = 10
p = 0.75
N = 1000
B = sp.stats.binom(K, p)
R = 10000
means = np.zeros(R)
for r in range(R):
x = B.rvs(size = N)
means[r] = np.mean(x)m = B.mean()
v = B.var()
z = means # (means - m) / np.sqrt(v / N)
plt.hist(z, density = True, histtype = "step");
#x = np.linspace(np.min(z), np.max(z), 101)
#Normal = sp.stats.norm()
#plt.plot(x, Normal.pdf(x)); # don't need this for Exam 02x = B.rvs(size = N)ndx = np.arange(1, N + 1)
cm = np.cumsum(x) / ndx
plt.plot(ndx, cm);B.mean()np.float64(7.5)