In Chapter 2, one repetition usually generated one value of a random variable:
\[
X.
\]
Now one repetition will generate an entire sample:
\[
X_1,X_2,\ldots,X_n.
\]
The number of observations in the sample,
\[
n,
\]
is called the sample size.
Suppose again that
\[
X\sim U(2,5).
\]
This is the parent distribution. Every observation in every sample will be generated from this same parent distribution.
Because the observations are generated independently from the same parent distribution, they are independent and identically distributed, usually abbreviated iid.
The terms sample mean and sample average mean the same thing. We will usually use sample mean.
What changes from sample to sample are the realized values. Because the sample changes, the sample mean changes too.
If one sample contains \(n\) observations, its sample mean is
n <-5# Number of observations in one samplex <-runif(n, min =2, max =5) # Generate one sample from the parent U(2,5)cat("sample =", round(x, 3), "\n") # Print all observations in the sample
sample = 4.756 4.727 4.304 4.359 2.054
x.bar <-mean(x) # Calculate the sample meancat("x.bar =", round(x.bar, 3), "\n") # Print the sample mean
x.bar = 4.04
These five observations make one sample, and that sample gives us one value of \(\bar X\).
Notice that \(n\) tells us how many observations are inside one sample.
3.2 Ten samples from the same parent distribution
One sample gives one sample mean.
To understand the distribution of \(\bar X\), we need many samples.
Just as in Chapters 1 and 2, it is useful to watch several repetitions explicitly. So now we generate 10 samples.
There are now two numbers to keep track of:
\[
n=\text{number of observations in each sample}
\]
and
\[
R=\text{number of Monte Carlo repetitions (here, the number of samples we generate)}.
\]
For now, let
\[
n=5
\qquad\text{and}\qquad
R=10.
\]
Remember: every sample still comes from the same parent distribution,
\[
X\sim U(2,5).
\]
n <-5# Number of observations in each sampleR <-10# Number of Monte Carlo repetitionsx.bar <-rep(0, R) # Create space to save one mean from each samplefor (i in1:R) { x <-runif(n, min =2, max =5) # Generate one sample from the same U(2,5) parent x.bar[i] <-mean(x) # Calculate and save its sample meancat("rep =", i,"sample =", round(x, 3),"x.bar =", round(x.bar[i], 3), "\n")}
Now the repetition structure is different from the earlier chapters.
In Chapter 2, one repetition usually gave one value of \(X\).
Here, one repetition gives
\[
\boxed{
\text{one sample of size }n
\rightarrow
\text{one sample mean }\bar X
}.
\]
After \(R\) repetitions we have
\[
\bar X_1,\bar X_2,\ldots,\bar X_R.
\]
The R output above lets us watch 10 different samples from the same parent distribution produce 10 different sample means.
The key distinction is
\[
\boxed{n=\text{observations in each sample}}
\]
versus
\[
\boxed{R=\text{number of Monte Carlo repetitions}}.
\]
Increasing \(R\) gives us more sample means with which to study the distribution of \(\bar X\).
Increasing \(n\) changes the sample mean itself and, as we will see, changes its distribution.
3.3 The distribution of the sample mean
We now know how to generate many sample means:
\[
\bar X_1,\bar X_2,\ldots,\bar X_R.
\]
These sample means have their own distribution.
The distribution of a statistic across repeated samples is called its sampling distribution. Here, we are studying the sampling distribution of \(\bar X\).
To understand this distribution, we can ask the same three questions we asked about distributions in Chapter 2:
Where is it centered?
How spread out is it?
What is its shape?
Let’s answer these questions using the same parent distribution as before:
\[
X\sim U(2,5).
\]
From Chapter 2, we know that
\[
\mu=3.5
\]
and
\[
\sigma^2=0.75.
\]
Suppose we repeatedly draw samples of size
\[
n=5
\]
from this same parent distribution and calculate \(\bar X\) for each sample.
Center
The distribution of the sample mean has the same center as the parent distribution:
\[
E(\bar X)=\mu.
\]
In our example,
\[
E(\bar X)=3.5.
\]
Individual samples give different sample means, but across many samples those means are centered around 3.5.
Spread
The sample means are less spread out than the individual observations from the parent distribution.
So averaging five observations reduces the variation.
As \(n\) increases,
\[
\frac{\sigma^2}{n}
\]
gets smaller. Sample averages from larger samples therefore tend to be more tightly concentrated around \(\mu\).
Shape
What about the shape of the distribution?
This is where the Central Limit Theorem becomes important.
For sufficiently large \(n\), the distribution of the sample mean is approximately normal:
\[
\bar X
\approx
N\left(\mu,\frac{\sigma^2}{n}\right).
\]
In our example,
\[
\bar X
\approx
N(3.5,0.15).
\]
Notice something remarkable here. The parent distribution is uniform:
\[
X\sim U(2,5),
\]
but the distribution of its sample means becomes approximately normal.
That is the central idea of the Central Limit Theorem.
Parent distribution versus distribution of the sample mean
The parent distribution describes the individual observations in each sample.
The distribution of \(\bar X\) describes sample means obtained from repeated samples from that same parent distribution.
We can summarize the difference:
Parent distribution \(X\)
Distribution of \(\bar X\)
Center
\(\mu=3.5\)
\(\mu=3.5\)
Variance
\(\sigma^2=0.75\)
\(\sigma^2/n=0.15\)
Shape
Uniform
Approximately normal
The two distributions have the same center, but the sample means have less spread. And even though the parent distribution need not be normal, the distribution of the sample mean becomes approximately normal as \(n\) becomes sufficiently large.
The figure below shows the complete movement from the parent distribution to the distribution of sample means.
Figure 3.1: From a parent distribution to the distribution of the sample mean.
The Central Limit Theorem tells us about its approximately normal shape.
3.4 Seeing the Central Limit Theorem with Monte Carlo
The Central Limit Theorem predicts that, for sufficiently large \(n\),
\[
\bar X
\approx
N\left(\mu,\frac{\sigma^2}{n}\right).
\]
For our example,
\[
X\sim U(2,5),
\]
with
\[
\mu=3.5
\]
and
\[
\sigma^2=0.75.
\]
Using samples of size
\[
n=5,
\]
the theoretical prediction is
\[
\bar X
\approx
N\left(3.5,\frac{0.75}{5}\right)
=
N(3.5,0.15).
\]
1. Theoretical Prediction
The theoretical distribution of the sample mean is approximately
\[
\bar X
\approx
N(3.5,0.15).
\]
2. Numerical Simulation
In the previous section we generated 10 samples so that we could see each sample and its corresponding sample mean.
Now increase the number of Monte Carlo repetitions to
\[
R=10{,}000.
\]
n <-5# Number of observations in each sampleR <-10000# Number of Monte Carlo repetitionsx.bar <-rep(0, R) # Create space for the sample meansfor (i in1:R) { x <-runif(n, min =2, max =5) # Generate one sample from the parent U(2,5) x.bar[i] <-mean(x) # Calculate and save its sample mean}cat("number of sample means =", length(x.bar), "\n")
number of sample means = 10000
cat("mean of sample means =", round(mean(x.bar), 3), "\n")
mean of sample means = 3.499
cat("variance of sample means =", round(var(x.bar), 3), "\n")
variance of sample means = 0.152
After the simulation, we have
\[
\bar X_1,\bar X_2,\ldots,\bar X_{10000}.
\]
These are 10,000 sample means, each calculated from a different sample of \(n=5\) observations drawn from the same parent distribution.
3. Comparison
The graph below compares the simulated distribution of the sample means with the normal distribution predicted by the Central Limit Theorem.
R’s dnorm() command uses the standard deviation, so we use
Figure 3.2: Monte Carlo distribution of sample means from X ~ U(2,5), with the normal distribution predicted by the Central Limit Theorem.
The comparison lets us check all three features.
Center
The simulated sample means are centered near
\[
3.5.
\]
Spread
Their theoretical variance is
\[
0.15,
\]
which is much smaller than the parent variance of \(0.75\).
Shape
The simulated distribution is close to the normal distribution predicted by the Central Limit Theorem.
So Monte Carlo lets us see the CLT directly:
\[
\boxed{
\text{generate a sample}
\rightarrow
\text{calculate }\bar X
\rightarrow
\text{repeat many times}
\rightarrow
\text{compare the distribution of }\bar X
}.
\]
Complete Monte Carlo Algorithm
1. Theoretical Prediction
If the parent distribution has mean \(\mu\) and variance \(\sigma^2\), then for sufficiently large \(n\),
\[
\bar X
\approx
N\left(\mu,\frac{\sigma^2}{n}\right).
\]
2. Numerical Simulation
Generate a sample of \(n\) observations from the parent distribution.
Calculate the sample mean \(\bar X\).
Save \(\bar X\).
Repeat steps 1–3 \(R\) times.
Examine the distribution of the \(R\) saved sample means.
3. Comparison
Compare the simulated distribution of the sample means with
\[
N\left(\mu,\frac{\sigma^2}{n}\right).
\]
3.5 Different parent distributions, same result
The parent distribution does not have to be normal.
It can be discrete, flat, or strongly skewed. When we repeatedly draw samples and calculate their averages, the distribution of those sample means tends to become approximately normal.
The same logic applies to other parent distributions, including \(F\) and Student \(t\) distributions, provided the parent distribution has a finite mean and variance.
Let’s look at three very different parent distributions.
For all three examples, we will use the same sample size,
\[
n=30,
\]
and the same number of Monte Carlo repetitions,
\[
R=10{,}000.
\]
Keeping \(n\) and \(R\) the same lets us focus on what happens when the parent distribution changes.
Three very different parent distributions
First, consider a binary random variable:
\[
X=
\begin{cases}
1 & \text{with probability }0.5,\\
0 & \text{with probability }0.5.
\end{cases}
\]
This parent distribution has only two possible outcomes.
Next, consider our familiar uniform distribution:
\[
X\sim U(2,5).
\]
This parent distribution is flat.
Finally, consider
\[
X\sim\chi^2(2).
\]
This parent distribution is strongly right-skewed.
These distributions look very different.
Monte Carlo simulation
For each parent distribution we do exactly the same thing:
Draw a sample of \(n=30\) observations.
Calculate the sample mean \(\bar X\).
Save the sample mean.
Repeat \(R=10{,}000\) times.
Look at the distribution of the saved sample means.
The only thing that changes is the parent distribution from which each sample is drawn.
n <-30R <-10000# Binary parent distributionxbar.binary <-rep(0, R)for (i in1:R) { x <-sample(c(0, 1), size = n, replace =TRUE) # One sample from the binary parent xbar.binary[i] <-mean(x) # Save its sample mean}# Uniform parent distributionxbar.uniform <-rep(0, R)for (i in1:R) { x <-runif(n, min =2, max =5) # One sample from U(2,5) xbar.uniform[i] <-mean(x) # Save its sample mean}# Chi-square parent distributionxbar.chisq <-rep(0, R)for (i in1:R) { x <-rchisq(n, df =2) # One sample from chi-square(2) xbar.chisq[i] <-mean(x) # Save its sample mean}cat("binary: mean =", round(mean(xbar.binary), 3),"variance =", round(var(xbar.binary), 3), "\n")
binary: mean = 0.5 variance = 0.008
cat("uniform: mean =", round(mean(xbar.uniform), 3),"variance =", round(var(xbar.uniform), 3), "\n")
uniform: mean = 3.499 variance = 0.025
cat("chi-square: mean =", round(mean(xbar.chisq), 3),"variance =", round(var(xbar.chisq), 3), "\n")
chi-square: mean = 2.009 variance = 0.133
The figure below shows the parent distributions in the top row and the corresponding distributions of sample means in the bottom row.
Figure 3.3: Very different parent distributions can produce approximately normal distributions of sample means. The top row shows the parent distributions; the bottom row shows Monte Carlo distributions of the corresponding sample means.
The parent distributions in the top row look dramatically different.
The distributions of the sample means in the bottom row are all approximately bell-shaped.
The parent distributions themselves do not become normal. They remain binary, uniform, and chi-square.
It is the distribution of the sample mean
\[
\bar X
\]
that becomes approximately normal.
Center and spread still follow the same rules
Although the three parent distributions look very different, the same results apply in every case:
So the binary sample means cluster around \(0.5\), the uniform sample means cluster around \(3.5\), and the chi-square sample means cluster around \(2\).
They do not all approach the same normal distribution. Each approaches the normal distribution appropriate for its own parent mean and variance:
\[
\boxed{
\text{very different parent distributions}
\longrightarrow
\text{approximately normal distributions of }\bar X
}.
\]
The normal approximation is not equally good for every \(n\). In general, the approximation improves as \(n\) increases, and a strongly skewed parent distribution may require a larger \(n\) than a more symmetric parent distribution.
For now, the main point is more important:
The normal shape of the distribution of \(\bar X\) does not require the parent distribution itself to be normal.
3.6 A 95% probability interval for the sample mean
The Central Limit Theorem tells us that, for sufficiently large \(n\),
\[
\bar X
\approx
N\left(\mu,\frac{\sigma^2}{n}\right).
\]
Once we know the distribution of \(\bar X\), we can ask a familiar question from Chapter 2:
What interval contains\(\bar X\) with probability 0.95?
For an approximately normal distribution, a 95% probability interval is
\[
\boxed{
\mu-1.96\sqrt{\frac{\sigma^2}{n}}
<
\bar X
<
\mu+1.96\sqrt{\frac{\sigma^2}{n}}
}
\]
We can check this probability directly with Monte Carlo simulation.
Here, one repetition means
\[
\boxed{
\text{draw a sample of size }n
\rightarrow
\text{calculate }\bar X
\rightarrow
\text{check whether }\bar X\text{ is inside the interval}
}.
\]
Start with 10 repetitions so we can watch what happens.
R <-10success.total <-0for (i in1:R) { x <-runif(n, min =2, max =5) # Draw one sample from the parent distribution x.bar <-mean(x) # Calculate its sample mean success <-0# Start this repetition as a failureif ((x.bar > lower) && (x.bar < upper)) { success <-1# Success if the sample mean is inside the interval } success.total <- success.total + successcat("rep =", i,"x.bar =", round(x.bar, 3),"success =", success,"total =", success.total, "\n")}
With only 10 repetitions, the simulated probability may be some distance from \(0.95\).
Now use many repetitions.
R <-10000success.total <-0for (i in1:R) { x <-runif(n, min =2, max =5) # Draw one sample from the same parent distribution x.bar <-mean(x) # Calculate its sample meanif ((x.bar > lower) && (x.bar < upper)) { success.total <- success.total +1 }}p.hat <- success.total / R # Fraction of sample means inside the intervalcat("Monte Carlo probability =", round(p.hat, 3), "\n")
Monte Carlo probability = 0.948
cat("Theoretical probability = 0.950\n")
Theoretical probability = 0.950
3. Comparison
The theoretical prediction is
\[
p\approx0.95.
\]
The Monte Carlo simulation gives
\[
\hat p
=
\frac{\text{number of sample means inside the interval}}{R}.
\]
Compare
\[
\hat p\approx0.95.
\]
About 95% of the sample means generated from repeated samples should fall inside the interval.
Complete Monte Carlo Algorithm
1. Theoretical Prediction
According to the Central Limit Theorem,
\[
\bar X
\approx
N\left(\mu,\frac{\sigma^2}{n}\right).
\]
Therefore, a 95% probability interval for \(\bar X\) is