<jupyter_start><jupyter_text>Consistency--- Example 1: Sample MeanSuppose that $X_1,X_2,\dots,X_n,\dots$ is a sequence of independent random variable with mean $\mu$ and variance $\sigma^2$. Then\begin{equation*} \lim_{n\to\infty}\Pr\{|\bar X_n - \mu|\geqq \epsilon\}=0,\quad \bar X_n = \frac1{n}\sum_{i=1}^n X_i,\end{equation*}for any given number $\epsilon>0$.<jupyter_code>np.random.seed(99)
fig1 = plt.figure(num=1, facecolor='w')
n = np.array([20, 80, 320, 1280])
m = 100000
for idx in range(n.size):
    sample_mean = st.uniform.rvs(loc=-np.sqrt(3.0), scale=2.0*np.sqrt(3.0), size=(m, n[idx])).mean(axis=1)
    plt.hist(sample_mean, density=True, histtype='step', bins=40)
plt.legend(['n = 20', 'n = 80', 'n = 320', 'n = 1280'], loc='best', frameon=False)
plt.xlabel('$\\bar{X}_n - \\mu$')
plt.xlim((-0.7, 0.7))
# plt.savefig('ms_fig_lln.eps', dpi=600)
plt.show()<jupyter_output><empty_output><jupyter_text>Example 2: Sample Variance$X_1, X_2, \dots, X_n$ are independently sampled from the uniform distirbution between $-\sqrt{3}$ and $\sqrt{3}$.The sample variance$$ s_n^2 = \frac1{n-1}\sum_{i=1}^n(X_i-\bar X_n)^2,$$is also consistent under certain conditions.<jupyter_code>np.random.seed(99)
fig1 = plt.figure(num=1, facecolor='w')
n = np.array([20, 80, 320, 1280])
m = 100000
for idx in range(n.size):
    sample_variance = st.uniform.rvs(loc=-np.sqrt(3.0), scale=2.0*np.sqrt(3.0), size=(m, n[idx])).var(axis=1, ddof=1)
    plt.hist(sample_variance - 1.0, density=True, histtype='step', bins=40)
plt.legend(['n = 20', 'n = 80', 'n = 320', 'n = 1280'], loc='best', frameon=False)
plt.xlabel('$s_n^2 - \\sigma^2$')
plt.xlim((-0.7, 0.7))
plt.show()<jupyter_output><empty_output><jupyter_text>Asymptotic Normality---Suppose $X_1,\dots,X_n$ are independent random variables with mean $\mu$ and variance $\sigma^2$, and define\begin{equation*} \bar X_n = \frac1n\sum_{i=1}^n X_i,\quad s_n^2 = \frac1{n-1}\sum_{i=1}^n(X_i - \bar X_n)^2.\end{equation*}Then\begin{equation*} \frac{\bar X_n - \mu}{s_n/\sqrt{n}}\rightsquigarrow\mathcal{N}(0,1).\end{equation*}  Example 1: Uniform Distribution<jupyter_code>np.random.seed(99)
fig2 = plt.figure(num=2, facecolor='w')
x = np.linspace(-6.0, 6.0, 101)
plt.plot(x, st.norm.pdf(x))
n = np.array([2, 4, 50])
m = 100000
for idx in range(n.size):
    sample = st.uniform.rvs(loc=-np.sqrt(3.0), scale=2.0*np.sqrt(3.0), size=(m, n[idx]))
    sample_mean = sample.mean(axis=1)
    se = sample.std(axis=1, ddof=1) / np.sqrt(n[idx])
    t_value = sample_mean / se
    plt.hist(t_value, density=True, histtype='step', bins=100, range=(-6.0, 6.0))
plt.legend(['N(0,1)', 'n = 2', 'n = 4', 'n = 50'], loc='best', frameon=False)
plt.xlabel('$\\sqrt{n}(\\bar{X}_n - \\mu)/s_n$')
plt.xlim((-6.0, 6.0))
# plt.savefig('ms_fig_clt.eps', dpi=600)
plt.show()<jupyter_output><empty_output><jupyter_text>Example 2: Exponential Distribution<jupyter_code>np.random.seed(99)
fig2 = plt.figure(num=2, facecolor='w')
x = np.linspace(-7.0, 5.0, 101)
plt.plot(x, st.norm.pdf(x))
n = np.array([5, 50, 500])
m = 100000
for idx in range(n.size):
    sample = st.expon.rvs(size=(m, n[idx]))
    sample_mean = sample.mean(axis=1)
    se = sample.std(axis=1, ddof=1) / np.sqrt(n[idx])
    t_value = (sample_mean - 1.0) / se
    plt.hist(t_value, density=True, histtype='step', bins=100 , range=(-7.0, 5.0))
plt.legend(['N(0,1)', 'n = 5', 'n = 50', 'n = 500'], loc='best', frameon=False)
plt.xlabel('$\\sqrt{n}(\\bar{X}_n - \\mu)/s_n$')
plt.xlim((-7.0, 5.0))
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.23011120615911035, 'fraction_numerical': 0.06444254348445966, 'mean_word_length': 4.817578772802653, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '168055', 'license': 'MIT', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1516, 'n_words': 279, 'path': 'Mathematics/Statistics/Statistics and Probability Python Notebooks/Concepts_Notebooks--probability_and_statistics-notebooks/notebook-b/large_sample.ipynb', 'repo_name': 'okara83/Becoming-a-Data-Scientist', 'size': '3507'}