<jupyter_start><jupyter_text>Recap of Classical Parameter Estimation and Confidence Intervals for Gaussian Distributions<jupyter_code>import numpy as np
from scipy.stats import norm<jupyter_output><empty_output><jupyter_text>Alwas important to fix the random state for reproducibility<jupyter_code>np.random.seed(6563)<jupyter_output><empty_output><jupyter_text>Creating a random sample<jupyter_code>rv = norm(loc=5.5, scale=2.5)
sample = rv.rvs(size=8)
print(sample)<jupyter_output>[-0.5262254  10.34254082  5.96780767  6.50309614  2.3285979   6.21960724
  8.32043191  3.75429883]<jupyter_text>t-Student eqs. $$\frac{\bar{\mu} - \mu}{\bar{\sigma}/\sqrt{N}} \sim t_{N-1}$$$$\mu = \bar{\mu} -  t_{N-1} \frac{\bar{\sigma}}{\sqrt{N}}$$<jupyter_code>mean_est = np.mean(sample)
std_est = np.std(sample, ddof=1)
print(mean_est)
print(std_est)
from scipy.stats import t

t_rv = t(len(sample)-1)
t_low, t_up = t_rv.ppf([0.16, 0.84])
print(t_low)
print(t_up)
mu_low = mean_est - t_up * std_est / np.sqrt(len(sample))
mu_up = mean_est - t_low * std_est / np.sqrt(len(sample))

print(mu_low, mu_up)<jupyter_output>4.065326125051029 6.662212653954428<jupyter_text>What happens with a larger sample?<jupyter_code>sample = rv.rvs(size=16)
sample
t_rv = t(len(sample)-1)
t_low, t_up = t_rv.ppf([0.16, 0.84])
mean_est = np.mean(sample)
std_est = np.std(sample, ddof=1)

mu_low = mean_est - t_up * std_est / np.sqrt(len(sample))
mu_up = mean_est - t_low * std_est / np.sqrt(len(sample))

print(mu_low, mu_up)<jupyter_output>5.232366650427018 6.217363512548744<jupyter_text>We get narrower confidence intervals.  Outliers Let's add a couple of outliers by hand to see what happens to our analysis.<jupyter_code>sample = np.append(sample, [50., 55.])
sample
import matplotlib.pyplot as plt

plt.hist(sample)
plt.show()
t_rv = t(len(sample)-1)
t_low, t_up = t_rv.ppf([0.16, 0.84])
mean_est = np.mean(sample)
std_est = np.std(sample, ddof=1)

mu_low = mean_est - t_up * std_est / np.sqrt(len(sample))
mu_up = mean_est - t_low * std_est / np.sqrt(len(sample))

print(mu_low, mu_up)
n_pix = np.pi * (2.5 / 2 / 0.3)**2 
std = np.sqrt(n_pix) * 49
print(std)<jupyter_output>361.8759945598762
{'fraction_non_alphanumeric': 0.1510392609699769, 'fraction_numerical': 0.09237875288683603, 'mean_word_length': 5.465671641791045, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '562903', 'license': 'MIT', 'n_tokens_mistral': 1056, 'n_tokens_neox': 932, 'n_words': 173, 'path': 'W01-simple-demo.ipynb', 'repo_name': 'thevalentino/AS450-astroinformatica', 'size': '2165'}