# Part A(ggplot(data = mean_of_dice_rolls)+geom_histogram(aes(x = y_bar, y =after_stat(density)),fill ='goldenrod',center =0.025, binwidth =0.05)+facet_wrap(~n, labeller = label_value)+theme_classic()+labs(title ='Simulated sampling distributions of y_bar'))
We are able to use map() instead of pmap() because we only have one parameter: n. The visualization reveals that as we increase our sample size n, the center remains unchanged but the variation/spread of the sampling distribution decreases.
# Part B(mean_of_dice_rolls%>%summarize('Simulated E(y_bar)'=mean(y_bar),'Var(y_bar)'=var(y_bar), .by = n)%>%mutate('Analytic E(y_bar)'=3.5)%>%mutate('Analytic Var(y_bar)'= (35/12)/n))
(ggplot(data = sum_of_pois, aes(x = u))+geom_step(aes(y = F_u, col ='Analytic CDF'))+geom_step(aes(y = Fhat, col ='Empirical CDF'))+facet_grid(n~lambda, labeller = label_both)+labs(y =expression(P(u)), title ='Simulated and analytic CDFs of sample sum from POI population', color ='')+theme_classic())