Central Limit Theorem Using R Language
Theory: Central Limit Theorem (CLT)
The Central Limit Theorem (CLT) states:
For a large enough sample size, the sampling distribution of the sample mean will be approximately normally
distributed, regardless of the shape of the population distribution.
Key Points:
- Population distribution: Can be any shape (uniform, skewed, etc.)
- Sample size (n): Typically greater than or equal to 30 is considered sufficient
- Sampling distribution: Distribution of means of repeated samples
- CLT Importance: Allows us to use normal distribution for inference, even if population is not normal.
Simulation of CLT in R
We'll demonstrate CLT using the rexp() function (exponential distribution - which is skewed).
# Set seed for reproducibility
set . seed(123)
# Parameters
sample_size <- 30 # Number of observations in each sample
num_samples <- 1000 # Number of samples
lambda <- 1 # Rate parameter of exponential distribution
# Create a matrix: 1000 samples of size 30 from exponential distribution samples
<- replicate(num_samples, rexp(sample_size, rate lambda))
# Calculate the mean of each sample sample_means
<- colMeans(samp1es)
# Plot histogram of sample means hist(sample_means,
breaks = 30, col " skyblue " , main - "Central Limit
Theorem Demonstration" , xlab - "Sample Means" ,
probability — TRUE)
# Add a normal curve curve(dnorm(x, mean =
col - "red" , lwd — 2, add
- TRUE)
# Add true mean line abline(v — 1/ lambda, col "blue", lwd
- 2, lty = 2)
legend( "topright" , legend - c("Norma1 Curve", "True Mean"),
col c( " red" , "blue"), 1 ty = c(l, 2), bty — "n")
Explanation of Output
- Even though the original exponential distribution is skewed,
- The histogram of sample means looks approximately normal,
- This confirms the Central Limit Theorem.
OUTPUT:-