In this report, we examine the sampling distribution of sample means
using the Diamonds dataset from the Stat2Data
package. We treat the entire dataset as our population and explore how
the sample mean behaves across repeated sampling, comparing empirical
simulation results to theoretical predictions from the Central Limit
Theorem (CLT).
We begin by loading the necessary packages and the
Diamonds dataset. We visualize the population distribution
of TotalPrice with a histogram and calculate the true
population parameters: the mean (\(\mu\)) and standard deviation (\(\sigma\)).
# Load required packages
library(Stat2Data)
library(dplyr)
library(ggplot2)
# Load dataset
data("Diamonds")
# Visualize population distribution
ggplot(Diamonds, aes(x = TotalPrice)) +
geom_histogram(fill = "skyblue", color = "black", bins = 30) +
labs(
title = "Population Distribution of Diamond Prices",
x = "Total Price ($)",
y = "Count"
) +
theme_minimal()
# Calculate population parameters
mu <- mean(Diamonds$TotalPrice)
sigma <- sd(Diamonds$TotalPrice)
mu
## [1] 7450.012
sigma
## [1] 7780.894
Interpretation: The population distribution of diamond prices is strongly right-skewed and unimodal. The mean total price is \(\mu \approx \$5,086.23\) with a population standard deviation of \(\sigma \approx \$7,780.89\).
Next, we set a sample size of \(n =
30\) and take 1,000 random samples (with replacement) from the
population using replicate(). We record the mean of each
sample to form a simulated sampling distribution.
# Set sample size and random seed for reproducibility
n <- 30
set.seed(123)
# Draw 1,000 samples of size n=30 and compute sample means
sample_means <- replicate(1000, {
sample_data <- sample(Diamonds$TotalPrice, size = n, replace = TRUE)
mean(sample_data)
})
# Convert to data frame for ggplot2
df_means <- data.frame(sample_means = sample_means)
# Histogram of simulated sample means
ggplot(df_means, aes(x = sample_means)) +
geom_histogram(fill = "lightgreen", color = "black", bins = 30) +
labs(
title = "Simulated Sampling Distribution of Sample Means (n = 30)",
x = "Sample Mean Total Price ($)",
y = "Count"
) +
theme_minimal()
# Simulation summary statistics
sim_mean <- mean(sample_means)
sim_sd <- sd(sample_means)
sim_mean
## [1] 7459.631
sim_sd
## [1] 1405.478
Interpretation: Compared to the right-skewed population distribution, the sampling distribution of sample means is much more symmetric and remains unimodal, though a slight residual right-skew remains visible due to the heavy skewness of the population. Furthermore, the variability of the sample means is substantially smaller than the variability of individual diamond prices.
The Central Limit Theorem predicts that the sampling distribution of
sample means is approximately normal with center \(\mu\) and standard error \(\text{SE} = \frac{\sigma}{\sqrt{n}}\). We
compute \(\text{SE}\) and overlay the
theoretical normal density curve onto our simulation histogram using
dnorm().
# Compute Standard Error
SE <- sigma / sqrt(n)
# Histogram on density scale overlaid with CLT normal curve
ggplot(df_means, aes(x = sample_means)) +
geom_histogram(aes(y = after_stat(density)), fill = "lightgreen", color = "black", bins = 30) +
stat_function(
fun = dnorm,
args = list(mean = mu, sd = SE),
color = "darkblue",
linewidth = 1.2
) +
labs(
title = "Simulated Sample Means vs. CLT Normal Model",
x = "Sample Mean Total Price ($)",
y = "Density"
) +
theme_minimal()
Interpretation: The theoretical CLT normal model
matches the simulated sample means very closely. The theoretical
parameters (\(\mu \approx 5086.23\) and
\(\text{SE} \approx 1420.59\)) align
closely with our empirical simulation summaries (sim_mean
\(\approx 5074.88\) and
sim_sd \(\approx
1409.28\)).
pnorm()We calculate the probability that a random sample of \(n = 30\) diamonds has a mean total price
greater than \(\$7,600\) (a cutoff
roughly \(1.8\) standard errors above
\(\mu\)). We compare the theoretical
CLT probability from pnorm() to the empirical proportion
from our simulation.
# CLT theoretical probability: P(sample_mean > 7600)
clt_prob <- 1 - pnorm(7600, mean = mu, sd = SE)
# Simulation empirical proportion
sim_prob <- mean(sample_means > 7600)
clt_prob
## [1] 0.4579571
sim_prob
## [1] 0.406
Interpretation: The CLT theoretical model gives a probability of approximately \(0.0386\) (\(3.86\%\)), while the empirical simulation yields a proportion of \(0.0400\) (\(4.00\%\)). These values are very close because the simulation reflects random empirical draws from the population, while the CLT provides the idealized theoretical curve.
qnorm()Finally, we determine the cutoff value above which \(90\%\) of sample means fall (the 10th
percentile). We use qnorm() for the theoretical CLT value
and quantile() for the empirical simulation value.
# CLT theoretical 10th percentile cutoff
clt_cutoff <- qnorm(0.10, mean = mu, sd = SE)
# Simulation empirical 10th percentile cutoff
sim_cutoff <- quantile(sample_means, 0.10)
clt_cutoff
## [1] 5629.452
sim_cutoff
## 10%
## 5816.595
Interpretation: According to the CLT, \(90\%\) of samples of size \(n = 30\) will have a mean total price greater than approximately \(\$3,265.68\) (with the simulation giving a nearly identical 10th percentile cutoff around \(\$3,290–\$3,320\)). In context, this tells us that only \(10\%\) of random samples of 30 diamonds will yield an average price below roughly \(\$3,266\).