Load required library

library(ggplot2)

Step 1: Population Parameters

(Assuming ‘Diamonds’ is loaded and ‘TotalPrice’ is in thousands of dollars)

mu <- mean(Diamonds\(TotalPrice) sigma <- sd(Diamonds\)TotalPrice)

Step 2: Simulation Setup (1,000 samples of size n = 30)

set.seed(123) # Set seed for reproducibility n <- 30 num_sims <- 1000

Draw 1,000 samples and compute their means

sample_means <- replicate(num_sims, { sample_data <- sample(Diamonds$TotalPrice, size = n, replace = TRUE) mean(sample_data) })

Create dataframe for plotting

sim_data <- data.frame(sample_means = sample_means)

Step 3: CLT Overlay Plot

SE <- sigma / sqrt(n) # Standard Error

ggplot(sim_data, 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 = “darkred”, size = 1.2 ) + labs( title = “Simulated Sample Means with CLT Normal Curve Overlay”, x = “Sample Mean Total Price”, y = “Density” ) + theme_minimal()

Step 4: Probability Calculation (P(Sample Mean > 60))

Theoretical probability using CLT

prob_clt <- pnorm(60, mean = mu, sd = SE, lower.tail = FALSE)

Empirical proportion from simulation

prop_sim <- mean(sample_means > 60)

Step 5: Quantile Calculation (10th percentile cutoff)

Theoretical cutoff using CLT

cutoff_clt <- qnorm(0.10, mean = mu, sd = SE)

Empirical cutoff from simulation

cutoff_sim <- quantile(sample_means, 0.10)