Sahaj.blogs
28 Jun 2024 · StudyPhase 6 · Probability and Statistics

Probability and Statistics · Point and interval estimation

Estimators and their bias, standard error, and building and interpreting 95% confidence intervals with the t distribution.

  • A point estimate is one best guess, e.g. x̄ for μ. An estimator is unbiased if its average over repeated samples equals the true value. The sample variance with n − 1 is unbiased; with n it isn’t.
  • An interval estimate adds a margin: x̄ ± t* · s/√n, where t* comes from the t distribution with n − 1 degrees of freedom. We use t because σ is estimated, which adds uncertainty.

How to read a 95% CI correctly: the procedure captures the true μ in about 95% of repeated samples. It does not mean “there’s a 95% probability μ is in this particular interval.” I checked that coverage claim by simulation.

import numpy as np
from scipy import stats

rng = np.random.default_rng(5)
mu, sigma, n = 50, 10, 25

sample = rng.normal(mu, sigma, n)
xbar, s = sample.mean(), sample.std(ddof=1)
tstar = stats.t.ppf(0.975, df=n - 1)
print(f"x̄={xbar:.2f}, s={s:.2f}, t*={tstar:.3f}, CI=({xbar - tstar * s / n**0.5:.2f}, {xbar + tstar * s / n**0.5:.2f})")
print("scipy:", tuple(round(v, 2) for v in stats.t.interval(0.95, n - 1, loc=xbar, scale=stats.sem(sample))))

trials = 10_000
X = rng.normal(mu, sigma, (trials, n))
m, sd = X.mean(1), X.std(1, ddof=1)
half = tstar * sd / np.sqrt(n)
print("coverage over 10k samples:", ((m - half <= mu) & (mu <= m + half)).mean())

v_n, v_n1 = X.var(1, ddof=0).mean(), X.var(1, ddof=1).mean()
print("avg var with n:", round(v_n, 1), "| with n-1:", round(v_n1, 1), "| true:", sigma ** 2)

Output:

x̄=48.29, s=8.85, t*=2.064, CI=(44.64, 51.94)
scipy: (np.float64(44.64), np.float64(51.94))
coverage over 10k samples: 0.9481
avg var with n: 96.3 | with n-1: 100.3 | true: 100

#statistics#inference

Sources

  1. MIT 18.05 Reading 22: Confidence intervals for the normal distribution — MIT OpenCourseWare
  2. scipy.stats.t — SciPy
  3. Seeing Theory: frequentist inference — Brown University