Along with practicing parametric grid simulations, I also want you to practice assessing and analyzing your simulation results (a la Question 2). This type of analysis above and beyond simply obtaining simulation results will be required on future assignments (including, possibly, the coding portion of your midterm exam).
Submission instructions
Submit a link to your rendered html for this assignment.
Question 1
Recall the following problem. Let \(X\) represents the number of cars driving past a parking ramp in any given hour, and suppose that \(X\sim POI(\lambda)\). Given \(X=x\) cars driving past a ramp, let \(Y\) represent the number that decide to park in the ramp, with \(Y|X=x\sim BIN(x,p)\). We’ve shown analytically that unconditionally, \(Y\sim POI(\lambda p)\). Verify this result via a simulation study over a grid of \(\lambda \in \{10, 20, 30\}\) and \(p\in \{0.2, 0.4, 0.6\}\) using the framework presented in your notes, with 10,000 simulated outcomes per \((\lambda, p)\) combination. Create a faceted plot of the overlaid analytic and empirial CDFs as well as the p-p plot.
In this problem we will study the relationship between \(\alpha\) and \(Var(Y)\) for fixed \(\mu\) for the beta distribution.
Recall that if \(Y\sim BETA(\alpha,\beta)\) and with \(\mu \equiv E(Y)\), \(\beta = \alpha \cdot \frac{1-\mu}{\mu}\).
Use this fact to simulate 10,000 realizations of \(Y\sim BETA(\alpha,\beta)\) for each combination of \(\alpha \in \{2,4,8,16\}\) and \(\mu\in\{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7\}\).
N <-10000set.seed(227)(beta_sim <-parameters(~ alpha, ~ mu,c(2, 4, 8, 16), seq(0.1, 0.7, by =0.1))%>%add_trials(N)%>%mutate(beta = alpha*(1-mu)/mu)%>%mutate(Y =pmap_dbl(list(alpha, beta), \(a, b) rbeta(1, shape1 = a, shape2 = b)))%>%mutate(f_Y =dbeta(Y, shape1 = alpha, shape2 = beta)))
Create a plot of the simulated variances as a function of \(\alpha\). Use lines as your geometry, and color-code each line by \(\mu\).
(ggplot(aes(x = alpha, y = var_Y, color =factor(mu)), data = beta_var)+geom_line()+geom_point()+scale_x_continuous(breaks =c(2, 4, 8, 16))+labs(x =expression(alpha), y ='Simulated Var(Y)', color =expression(mu))+theme_classic(base_size =12))
D)
Comment on how the combination of \(\alpha\) and \(\mu\) impact variance.
For a fixed μ, the variance of Y goes down as α increases, with the biggest drop happening between α = 2 and α = 4. After that, the changes get smaller. Since α + β = α/μ when μ is fixed, a larger α makes the distribution more concentrated around its mean. For a fixed α, the variance generally increases as μ goes from 0.1 to 0.6, but the curves for μ = 0.6 and 0.7 are almost the same and cross each other. This happens because the numerator of the variance formula reaches its highest point around μ = 2/3. The differences in variance between the μ values are also bigger when α = 2 and get smaller as α increases, meaning μ has a bigger effect on variance when α is small.