Interactive explanations

Law of Large Numbers

Observe how the sample mean stabilizes as the sample size increases.

Learning objective

The Law of Large Numbers explains why averages calculated from increasingly large random samples become reliable estimates of the population mean.

If X1, X2, … are i.i.d. with finite mean μ, then
X̄n = (1/n) Σ Xi → μ in probability as n → ∞.

How to explore

  1. Select a distribution.
  2. Change the sample size.
  3. Generate several trajectories.
  4. Compare the final error.

What does choosing n actually mean?

If you choose n = 20, the lab generates one sequence of 20 observations: X1, X2, …, X20. It then recalculates the cumulative mean every time a new observation is added.

Step 1X̄1 = X1
Step 2X̄2 = (X1+X2)/2
Step 3X̄3 = (X1+X2+X3)/3
Continue to nX̄n = ΣXi/n
The important idea: the graph shows X̄1, X̄2, …, X̄20. These are not 20 unrelated samples. They are nested prefixes of the same sequence: {X1} ⊂ {X1,X2} ⊂ … ⊂ {X1,…,X20}. Therefore, the slider selects the maximum sample size displayed.

Running Sample Mean

Running sample mean X̄ₙTheoretical mean μ
Theoretical mean μ—
Final sample mean—
Absolute error—
Sample size—
What to notice: for small n, the sample mean can fluctuate strongly. As n grows, the trajectory usually settles near μ. Convergence does not mean that every trajectory is monotonic.
Discussion question: Which distribution appears to require more observations before the running mean becomes stable?

Experiment settings

Distribution
—
Mean E[X]—
Variance Var(X)—
—

Animated Example — Rolling a Fair Die

Each roll is an independent observation Xi. The running mean uses every result obtained so far and should progressively approach the theoretical mean 3.5.

Fair die distribution
P(X = x) = 1/6,  x ∈ {1,2,3,4,5,6}
E[X] = 3.5
Var(X) = 35/12 ≈ 2.9167
Last roll—
Number of rolls0
Running mean—
|X̄ₙ − 3.5|—

Running mean after each roll

Running meanTheoretical mean 3.5

Early averages can move sharply because each roll has a large influence. Later, one additional roll has much less effect on the cumulative mean.

Central Limit Theorem

The Central Limit Theorem explains why the sample mean often behaves like a normal random variable, even when the original data do not.

1. The main idea

Original variable
X

May be discrete, skewed, or non-normal.

→
Take a sample
X₁,…,Xₙ

Use n independent observations.

→
Compute the mean
X̄ = (1/n) ΣXᵢ

Repeat this experiment many times.

CLT statement: if the observations are independent and identically distributed, with finite mean μ and variance σ², then for sufficiently large n,
X̄ ≈ N( μ , σ² / n )    and    (X̄ − μ)/(σ/√n) ≈ N(0,1).

2. What becomes normal?

A common mistake is to think that the original observations become normal. They do not.

One observation
X

Still follows the original distribution.

One sample
X₁,…,Xₙ

A collection of original observations.

Many sample means
X̄₁,X̄₂,…

Their distribution becomes approximately normal.

3. LLN vs CLT

Law of Large Numbers:
X̄ₙ → μ
tells us where the sample mean goes.
Central Limit Theorem:
X̄ₙ ≈ N(μ,σ²/n)
tells us how the sample mean fluctuates around μ.

4. Why do we repeat the sampling experiment M times?

The simulation uses two numbers, n and M. They have completely different roles.

n
Sample size

n is the number of observations inside one experiment / one sample.

X₁, X₂, …, Xₙ → one X̄

Increasing n changes the sampling distribution itself:

SE(X̄) = σ / √n

Therefore, larger n makes the distribution of X̄ narrower and, under the CLT, generally more bell-shaped.

M
Number of repeated experiments

M is the number of times we repeat the whole sampling procedure.

X̄₁, X̄₂, …, X̄_M

Each experiment gives one sample mean. Increasing M gives us more sample means, so the histogram becomes smoother and represents the theoretical sampling distribution more accurately.

Example: n = 30 and M = 1000
Perform 1000 experiments. In each experiment, roll the die 30 times and calculate one mean. At the end:
X̄₁, X̄₂, …, X̄₁₀₀₀
These 1000 means are the values used to construct the histogram.
Experiment 1: n observations
153 62
→
Compute one mean
X̄₁ = 3.40
→
Repeat M times
X̄₁ = 3.40 X̄₂ = 3.67 X̄₃ = 3.27 …
Important: increasing M does not make the CLT stronger, and it does not reduce SE = σ/√n. M is mainly used here so that we can see the sampling distribution.
If n increases

The distribution of X̄ changes.

n ↑ → σ/√n ↓

The histogram becomes narrower around μ.

If M increases

The theoretical distribution of X̄ does not change.

M ↑ → more X̄ values

The histogram simply becomes smoother and more stable.

Quick check
Choose A or B.

5. Interactive experiment

Choose a distribution, select the sample size n, and choose the number of experiments M. In each experiment, the computer generates n observations and computes one sample mean. After M repetitions, we obtain X̄₁, X̄₂, …, X̄_M. The histogram below is therefore a histogram of sample means, not of the original observations.

Theoretical μ3.500
Theoretical σ1.708
SE = σ/√n0.764
Observed mean of X̄—
Click Run simulation, or use Animate to increase n automatically from 1 to 100, one value at a time. Watch the distribution of sample means become smoother and narrower around μ.

6. Numerical example: fair die

For one fair die roll,

μ = E[X] = (1+2+3+4+5+6)/6 = 3.5
σ² = 35/12 ≈ 2.917
σ ≈ 1.708

If we roll the die 30 times and compute the average, then

X̄ ≈ N(3.5, (1.708/√30)²)
SE = 1.708/√30 ≈ 0.312.

So the sample means are centered near 3.5 and most of them stay relatively close to 3.5.

7. Why the curve gets narrower

The standard deviation of the sampling distribution is

SE(X̄) = σ / √n.

Therefore increasing n reduces the variability of the sample mean.

n = 4 → SE = σ/2
n = 25 → SE = σ/5
n = 100 → SE = σ/10

This is why larger samples give more stable estimates of the population mean.

8. Final intuition

Imagine repeating the same sampling procedure again and again. Every repetition gives one value of X̄. The CLT says that the cloud of these sample means approaches a bell-shaped distribution centered at μ, with spread σ/√n.

This is why the CLT is fundamental for confidence intervals, hypothesis tests, estimation, and statistical inference.

Hypothesis Testing

Hypothesis testing is a formal way to decide whether the evidence in a sample is strong enough to question a claim about a population.

1. The idea

We begin with a claim called the null hypothesis, denoted by H₀. We then ask:

If H₀ were true, would our observed sample result be reasonably common, or surprisingly extreme?

Null hypothesis

H₀: μ = μ₀

The reference claim. We assume it is true while calculating the probability of observing results as extreme as ours.

Alternative hypothesis

H₁: μ ≠ μ₀

The competing claim. Depending on the question, it may also be μ > μ₀ or μ < μ₀.

2. The five-step logic

1
State H₀ and H₁

Define the population claim being tested.

2
Choose α

Typical value: α = 0.05.

3
Compute a statistic

Measure how far the sample is from what H₀ predicts.

4
Find the p-value

Quantify how extreme the result is under H₀.

5
Decision

Compare the p-value with α.

3. Which test statistic?

Case 1 — Population variance known

Use the population standard deviation σ and the standard normal distribution.

z = (X̄ − μ₀) / (σ/√n)
Case 2 — Population variance unknown

Replace σ by the sample standard deviation s and use Student's t distribution.

t = (X̄ − μ₀) / (s/√n),    df = n − 1

In both cases, the statistic measures how many estimated standard errors the observed sample mean is away from the value assumed by H₀.

4. The p-value

The p-value is the probability, assuming H₀ is true, of obtaining a test statistic at least as extreme as the one observed.

Important: the p-value is not the probability that H₀ is true.
p ≤ α → reject H₀ p > α → fail to reject H₀

5. Choose the case and study the corresponding example

First choose whether the population variance is known or unknown. The worked example below changes automatically according to your choice. The same choice is then used in the interactive demonstration in Part 6.

Case 1 — Population variance known → z-test

A manufacturer claims that the mean lifetime of a battery is μ = 100 hours. The population standard deviation is known: σ = 12 hours.

A sample of n = 36 batteries gives X̄ = 104 hours. We use a two-tailed test with α = 0.05.

H₀: μ = 100
H₁: μ ≠ 100
SE = σ/√n = 12/√36 = 2 z = (104 − 100)/2 = 2 p ≈ 0.0455
Since p ≈ 0.0455 < 0.05, Reject H₀.

6. Interactive hypothesis test for a population mean

This demonstration uses the variance case selected in Part 5. Change the sample information below and observe the test statistic, critical region, p-value, and decision update automatically.

Selected in Part 5: Case 1 — z-test, population standard deviation σ is known.
Standard Error2.000
z statistic2.000
p-value0.0455
Critical value(s)±1.960
DecisionReject H₀