# new function
= function(n, lambda) {
sim_CLT_pois = rpois(n = n, lambda = lambda)
sims mean(sims)
}= 10000
i = map_dbl(1:i, .f = ~ sim_CLT_pois(n = n, lambda = lambda)) many_means
Data Simulation with Monte Carlo Methods
University of Hohenheim
Adapt the code from the examples to check whether the CLT also holds for a Poisson distribution.
Random numbers are sampled with rpois(n, lambda)
, where n
is the sample size and lambda
is the mean (and also the variance) of the distribution.
The population standard deviation is \(\sqrt{\lambda}\).
d_many_means = tibble(sim = 1:i, mu_hat = many_means)
d_many_means %>%
ggplot(aes(mu_hat)) + geom_histogram() +
geom_vline(xintercept = c(mu - sigma / sqrt(n), mu, mu + sigma / sqrt(n))) +
geom_vline(xintercept = c(mean(many_means)-sd(many_means),
mean(many_means),
mean(many_means)+sd(many_means)),
color = "red", linetype = 2)
d_many_means %>%
ggplot(aes(sample = many_means)) +
geom_qq(distribution = qnorm,
dparams = c(mean = mu, sd = sigma / sqrt(n)),
geom = "line") +
geom_abline(slope = 1)
Select another suitable distribution from ?Distributions
Read the documentation to understand which arguments must be provided.
Find the definition of the population distribution’s standard deviation to calculate the analytical standard deviation of the sampling distribution.
Adapt the simulation and analysis code accordingly.
d_many_means = tibble(sim = 1:i, mu_hat = many_means)
d_many_means %>%
ggplot(aes(mu_hat)) + geom_histogram() +
geom_vline(xintercept = c(mu - sigma / sqrt(n), mu, mu + sigma / sqrt(n))) +
geom_vline(xintercept = c(mean(many_means)-sd(many_means),
mean(many_means),
mean(many_means)+sd(many_means)),
color = "red", linetype = 2)
d_many_means %>%
ggplot(aes(sample = many_means)) +
geom_qq(distribution = qnorm,
dparams = c(mean = mu, sd = sigma / sqrt(n)),
geom = "line") +
geom_abline(slope = 1)