sim_means <- function(n, reps = 2000) {
replicate(reps, mean(rexp(n, rate = 1))) |>
tibble::tibble(mean_val = _) |>
dplyr::mutate(n = n)
}
clt_df <- purrr::map_dfr(c(1, 5, 30, 100), sim_means)
ggplot2::ggplot(clt_df, ggplot2::aes(x = mean_val)) +
ggplot2::geom_histogram(bins = 50, fill = "#2563eb", alpha = 0.75) +
ggplot2::facet_wrap(~n, scales = "free",
labeller = ggplot2::labeller(n = ~ paste0("n = ", .x))) +
ggplot2::labs(title = "CLT in action: sample means from Exponential(1)",
x = "Sample mean", y = "Count") +
theme_di()
