List 8 — Statistical Inference
LLN, CLT, confidence intervals, hypothesis tests
Law of Large Numbers
Flip a fair coin repeatedly and track the running relative frequency of heads after each flip. What happens to the relative frequency as the number of flips grows? State the Law of Large Numbers precisely.
Relative frequency of heads converges to p = 0.5 as the number of flips grows.
Let be i.i.d. Bernoulli(p) random variables (1 = heads, 0 = tails). The running relative frequency after n flips is the sample mean.
The Weak LLN states that for any , the probability that the sample mean deviates from the true expected value by more than goes to zero as .
For a fair coin, . The simulator above draws from Bernoulli(0.5) and plots vs . Watch the running frequency bounce wildly at first, then stabilize near the red reference line at 0.5.
Relative frequency of heads converges to p = 0.5 as the number of flips grows.
The LLN guarantees convergence in probability, not almost-sure equality for any finite n. Early fluctuations are large; they shrink as . The LLN is the theoretical foundation for using observed frequencies to estimate true probabilities.
Sample Size vs Number of Samples
A simulation draws R independent samples of size n from Bernoulli(p=0.5) and records each sample proportion . Investigate separately: (a) what happens to the histogram shape and spread when you increase n (holding R fixed), and (b) what happens when you increase R (holding n fixed).
- a)(a) Fix R = 500. Compare histograms for n = 10, 50, 200. Describe the change in center, spread, and shape.
- b)(b) Fix n = 50. Compare histograms for R = 50, 500, 5000. Describe the change.
- c)(c) Which parameter controls statistical precision of the estimator, and which controls the smoothness of the simulation picture?
Mean of estimates ≈ 0.500. Larger n → narrower (smaller spread); the shape approaches a normal curve.
Increasing n reduces the standard error of . The histogram of values becomes narrower and more concentrated around the true p. This reflects real statistical precision: you are collecting more data per estimate.
Mean of estimates ≈ 0.502. Larger n → narrower (smaller spread); the shape approaches a normal curve.
Increasing R does NOT change the spread of the histogram; it only makes the histogram smoother and less ragged. You are simply drawing more replications to better approximate the theoretical sampling distribution. R is a simulation parameter, not a data parameter.
Mean of estimates ≈ 0.503. Larger n → narrower (smaller spread); the shape approaches a normal curve.
n governs statistical precision (real-world quantity). R governs simulation quality (computational quantity). Confusing the two is a common mistake: running more simulations does not make your estimator more accurate in practice.
Larger n narrows the sampling distribution (better real estimates). Larger R smooths the histogram (better picture of the distribution).
Sampling Distribution of a Proportion
Let be i.i.d. Bernoulli(p). Define the sample proportion . Derive the mean and standard error of , then use a simulator to verify that the sampling distribution is approximately normal for large n.
Mean of estimates ≈ 0.398. Larger n → narrower (smaller spread); the shape approaches a normal curve.
Because for each i, linearity of expectation gives the mean of the sampling distribution.
Since the are independent with , the variance of the sum scales by .
By the Central Limit Theorem, for large n the standardized is approximately standard normal.
With p = 0.4, n = 100, the theoretical SE = . Run the simulator and check that the histogram spread matches this value and that the bell shape is visible.
Mean of estimates ≈ 0.398. Larger n → narrower (smaller spread); the shape approaches a normal curve.
The normal approximation is reliable when and . Here and , both well above 10.
Central Limit Theorem
Let be i.i.d. with mean and finite variance . State the Central Limit Theorem and illustrate it by drawing repeated samples from a non-normal (exponential) source and plotting the distribution of sample means.
Mean of estimates ≈ 0.994. Larger n → narrower (smaller spread); the shape approaches a normal curve.
No matter the shape of the population distribution (provided it has finite mean and variance), the standardized sample mean converges in distribution to the standard normal as .
The sample mean is approximately normal for large n, regardless of the shape of the population.
An Exponential() distribution is right-skewed with and . Individual values are nowhere near normal. But the simulator draws n = 30 values, computes their mean, and repeats R = 600 times.
Mean of estimates ≈ 1.011. Larger n → narrower (smaller spread); the shape approaches a normal curve.
Even with n = 30, the histogram of is approximately bell-shaped and centered at . The spread is .
The CLT is why so many statistical procedures (z-tests, t-tests, confidence intervals) work even when the data are not normally distributed. The normality is in the estimator, not the raw data.
Confidence Intervals for a Proportion
You observe from n = 100 Bernoulli trials. Construct a 95% confidence interval for p. Interpret what "95% confidence" means using a simulation that generates many such intervals.
Empirical coverage ≈ 95% (target 95%). The vertical line is the true p = 0.5; red intervals miss it.
Using the normal approximation and the fact that the 97.5th percentile of N(0,1) is 1.96, the two-sided 95% CI is:
The total width of the 95% CI depends on and n. The maximum width (over p) occurs at .
Run the confidence simulator: for each of many simulations, a fresh is drawn and its 95% CI plotted. Green intervals contain the true p = 0.5; red ones miss it. About 95% should be green.
Empirical coverage ≈ 98% (target 95%). The vertical line is the true p = 0.5; red intervals miss it.
A 95% CI does NOT mean "there is a 95% probability that p is in this interval." The true p is fixed. The interval is random. The correct statement: if we repeated this procedure many times, 95% of the resulting intervals would contain the true p.
Increasing n from 100 to 400 cuts the interval width roughly in half (since width ). You need 4 times as much data to halve the margin of error.
Confidence Intervals for a Mean
You observe a random sample of size n with sample mean and sample standard deviation s. Construct a confidence interval for the population mean . When should you use a t-distribution instead of a normal, and why?
Empirical coverage ≈ 95% (target 95%). The vertical line is the true p = 0.5; red intervals miss it.
If the population standard deviation is known (rare in practice), use the z-based interval.
In practice is unknown and estimated by s. Replacing with s introduces extra variability, which the t-distribution accounts for. With degrees of freedom :
The t-distribution with degrees of freedom is wider than N(0,1). For small n, can be much larger than 1.96, leading to a wider (more honest) interval. As , .
For large n the CLT makes the t-interval valid regardless of the data distribution. For small n, the t-interval requires approximately normal data. The interval is more sensitive to skewness when n is small.
The same coverage idea from Problem 8.5 applies: run the confidence simulator to see that about 95% of t-intervals contain the true mean when the data are normal.
Empirical coverage ≈ 93% (target 95%). The vertical line is the true p = 0.5; red intervals miss it.
Hypothesis Testing: Coin Fairness
You flip a coin 100 times and observe 61 heads. Test vs at significance level using (a) a simulation-based p-value and (b) a z-test. Interpret the result.
Mean of estimates ≈ 0.498. Larger n → narrower (smaller spread); the shape approaches a normal curve.
The null hypothesis is that the coin is fair; the alternative is two-sided (coin could be biased either way).
The observed proportion is . Under , the standard error is computed using .
Use the simulator to generate 800 samples of size 100 from Bernoulli(0.5) (the null distribution). The p-value is the fraction of simulated values at least as extreme as 0.61.
Mean of estimates ≈ 0.499. Larger n → narrower (smaller spread); the shape approaches a normal curve.
Standardize the observed under to get a z-score, then find the two-tailed p-value from the standard normal.
The two-tailed p-value is where is the standard normal CDF.
Since we reject at the 5% level. There is statistically significant evidence that the coin is not fair. However, statistical significance does not imply practical significance: 61% vs 50% may or may not be meaningful depending on context.
Chi-Square Goodness-of-Fit Test
Roll a six-sided die 120 times and observe the counts: [18, 22, 17, 25, 19, 19]. Test whether the die is fair using a chi-square goodness-of-fit test at .
Under the null, each face has probability 1/6; the expected count for each face is .
Compute the chi-square test statistic by summing the squared deviations of observed from expected, divided by expected.
With observed counts [18, 22, 17, 25, 19, 19] and expected 20 for each:
Summing the terms: .
Under , D follows approximately a chi-square distribution with degrees of freedom. The critical value at is .
Since , we fail to reject . The data are consistent with a fair die. Use the die simulator to see what typical D values look like from a fair die.
You can also simulate D under by rolling a fair die 120 times, computing D, and repeating thousands of times. The resulting histogram should match , confirming the theoretical result.
Comparing Two Groups: Permutation Test
Group A (n=20): mean = 52.3, Group B (n=20): mean = 47.8. The observed difference in means is 4.5. Test whether this difference is statistically significant using a permutation test, and construct a 95% CI for the difference in population means.
Under the null hypothesis , all group labels are exchangeable. We can shuffle the 40 observations between the two groups, recompute the mean difference, and repeat many times to build the null distribution.
The observed test statistic is the difference in sample means.
Pool all 40 values. For each of B = 5000 permutations: randomly assign 20 to "group A" and 20 to "group B", compute . The collection approximates the null distribution of the test statistic.
Count the fraction of permuted differences at least as extreme as the observed value (two-tailed).
Assuming approximately normal data (or invoking the CLT), a 95% CI uses the Welch t-approximation with pooled standard error.
The permutation test makes no distributional assumptions beyond exchangeability under . It is especially valuable for small samples or non-normal data. The t-based CI is complementary: it quantifies the magnitude and uncertainty of the difference.
If the permutation p-value is below , the observed difference is unlikely under exchangeability — evidence that the groups differ. The CI tells us the plausible range of the true difference .
Final Investigation: Complete Statistical Framework
Design and carry out a complete statistical investigation. Starting from a random experiment of your choice, work through every stage of the inferential process: from defining the experiment and identifying parameters, through data collection, estimation, confidence intervals, and hypothesis testing, to a careful final interpretation.
Mean of estimates ≈ 0.498. Larger n → narrower (smaller spread); the shape approaches a normal curve.
Clearly describe the data-generating process. Identify the population, the sampling mechanism, and the outcome variable. Example: "We recruit 80 visitors to a website and record whether each one clicks a call-to-action button (1) or not (0)." State what makes the outcomes random and whether independence is plausible.
Separate the fixed unknowns (parameters) from the random quantities (statistics). The true click probability p is a fixed but unknown parameter. The sample proportion is a random variable that varies across repetitions of the experiment.
Obtain the data. For a simulation, draw n = 80 Bernoulli(p) values. For a real study, collect observations from the population. Record , the individual outcomes, and any relevant covariates. Check for obvious data quality issues (missing values, implausible entries).
Mean of estimates ≈ 0.498. Larger n → narrower (smaller spread); the shape approaches a normal curve.
Calculate point estimates of the parameters of interest. Verify their properties: unbiasedness (), standard error, and consistency (SE as ).
Construct a 95% CI for the parameter using the appropriate method (Wald z-interval for proportions; t-interval for means). State it in plain language: "We are 95% confident the true click rate is between a% and b%."
State the null and alternative hypotheses, choose (usually 0.05), compute the test statistic and p-value, and state the decision. Example: test vs .
Draw conclusions that are consistent with both the CI and the hypothesis test. Address four key questions: (1) Is the result statistically significant? (2) Is it practically meaningful? (3) What are the limitations (sample size, non-randomness, confounding)? (4) What would you do next?
The LLN guarantees your estimate is close to the truth for large n. The CLT justifies the normal-based CI and z-test. The CI tells you precision; the test tells you whether chance alone could explain the result. Neither replaces subject-matter judgment.
Do not say "the probability that p is in the CI is 95%" (p is not random). Do not equate statistical significance with practical importance. Do not ignore multiple testing. Do not extrapolate beyond the sampled population. Report effect sizes and CIs, not just p-values.