One waiting time
Your wait Y is equally likely to be anything between 0 and 10 minutes: Y ~ Uniform(0, 10). Each draw is one simulated trip to the bus stop: the computer picks a random arrival time within the 10 minutes between buses and records how long you wait, which is what runif(1, 0, 10) does in R. Draw waits one at a time, then thousands, and watch the histogram flatten out. This flat shape is the population we will average from.
What is a draw?
A draw is one random waiting time. Imagine arriving at the stop at a random moment: the time until the next bus is your wait. The computer imitates this by picking a number between 0 and 10 at random, with every value equally likely. In R this is runif(1, 0, 10).
“Draw 1 wait” does this once and adds one line to the strip. “Draw 10” does it ten times, giving ten separate waits.
Each line is one waiting time
Histogram of all the waits
Average n waits
Now wait for the bus n times and take the mean. Each sample gives one mean ȳ (tall bar); its n waits are the crosses. Repeat many times and look at the histogram of the means: it is centred on 5, gets narrower as n grows, and turns into a bell curve.
What is a sample here?
One sample is n draws, that is n separate waiting times. Its mean ȳ is a single number, shown as the tall line. “Draw one sample” takes one new sample of n waits and adds its mean to the strip.
Side by side: n = 2, 5, 20, 100
Same population, same x-axis, four sample sizes. The centre never moves from μ = 5. The spread, the standard error, shrinks like σ/√n, and the table checks the simulation against that formula.
Mean and standard error of the sample means
Standardise the means
Subtract μ and divide by the standard error σ/√n. The histogram keeps its shape and only the x-axis changes: every sampling distribution becomes N(0, 1). That is why ±1.96 marks the middle 95% for any n.
Original sample means
Standardised: Z = (Ȳ − μ)/(σ/√n)
Start from a strange population
What if the population is lumpy or lopsided? Pick a shape, sample n values with replacement, and average. With n large enough the means still come out Normal: that is the "regardless of the original distribution" part of the CLT.
σ known or estimated: z versus t
Population N(μ = 10, σ = 2). For each sample we standardise ȳ twice: with the true σ (z) and with the sample s (t). Because s is itself random, and often too small when n is small, t has heavier tails than N(0, 1). Student's t with n − 1 degrees of freedom describes it exactly.
Red: |z| or |t| above 3. Values like that are rare for z but common for t when n is small, usually because s came out small.
z: standardised with σ
t: standardised with s
Is this sample unusual if μ = 11?
Twelve sugar concentrations have mean 11.43. Suppose the true mean were 11. Simulate many samples of 12 from N(11, s²) and ask how often chance alone gives a sample mean at least as large as the one observed. This is the idea behind the hypothesis tests that come next.
Do the intervals really cover μ?
Same N(10, 2²) population. Each simulated sample gives an interval, and since μ = 10 is known we can count how often it is inside. With σ known the z-interval works; with σ estimated, only the t-interval keeps its promised coverage for small n.