library(ggplot2)
mu <- mean(Diamonds\(TotalPrice) sigma <- sd(Diamonds\)TotalPrice)
set.seed(123) # Set seed for reproducibility n <- 30 num_sims <- 1000
sample_means <- replicate(num_sims, { sample_data <- sample(Diamonds$TotalPrice, size = n, replace = TRUE) mean(sample_data) })
sim_data <- data.frame(sample_means = sample_means)
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()
prob_clt <- pnorm(60, mean = mu, sd = SE, lower.tail = FALSE)
prop_sim <- mean(sample_means > 60)
cutoff_clt <- qnorm(0.10, mean = mu, sd = SE)
cutoff_sim <- quantile(sample_means, 0.10)