ggplot(data = exp_scale_sims) +geom_histogram(aes(x = U, y =after_stat(density)), fill ='goldenrod', bins =40) +geom_line(aes(x = U, y = f_U), col ='cornflowerblue', linewidth =1) +facet_grid(theta ~ lambda, labeller = label_both, scales ='free') +labs(x ='u', y =expression(f[U](u))) +theme_classic(base_size =14)
Question 2
N <-10000(unif_sum_sims <-parameters(~theta, c(2, 4, 6, 8))%>%add_trials(N)%>%mutate(X =map_dbl(theta, \(t) runif(1, min =0, max = t)),Y =map_dbl(theta, \(t) runif(1, min =0, max = t)))%>%mutate(U = X + Y)%>%mutate(Fhat =cume_dist(U), .by = theta,F =punif(U, min =0, max =2*theta))) %>% head
# CDF overlay plotggplot(data = unif_sum_sims) +geom_step(aes(x = U, y = Fhat, col ='Empirical')) +geom_line(aes(x = U, y = F, col ='Analytic')) +labs(y ='CDF', x ='u', color ='') +facet_wrap(~theta, labeller = label_both) +theme_classic(base_size =14) +ggtitle('CDF Comparison')