S1. Consider problem 3. For n∈{20,40,80,160,320,640} and β∈{0.5,2,4}, investigate coverage of the asymptotic 95% confidence interval for S(5) when Y_1,…,Y_n are i.i.d. EXP(β). Plot your coverage as a function of n. Does the value of the β influence how quickly the asymptotics “kick in”?
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.2 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.1.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(purrrfect)
Attaching package: 'purrrfect'
The following objects are masked from 'package:base':
replicate, tabulate
(many_sims <-parameters(~n, ~beta,c(20,40,80,160,320,640), c(0.5,2,4))%>%add_trials(10000)%>%mutate(Ysample =pmap(list(n,beta), .f = \(n,b) rexp(n, rate =1/b)))%>%mutate(ybar =map_dbl(Ysample, mean),# MLE of S(5)mle =exp(-5/ybar) )) %>% head
We can see from our plot that as our Beta value grows we converge quicker/our asymptotics kick in. We can also see that as our n grows our coverage grows.
S2. Consider problem 4. Given a sample of observed data values y_1,…,y_n from a GAM(α,β) distribution we want to find the MLEs of (α,β). We will turn this into a one-parameter optimization problem, as outlined above, as single parameter optimization problems are usually easier numerically. Write a function loglik.alpha(alpha,yvals) that takes as input alpha and a vector of data values yvals and returns the log-likelihood as a function of α given the observed y_i’s. Write a function called get.mle(yvals) that takes a sample as input and uses loglik.alpha() and optimize() to return the joint MLEs of (α,β). Verify that your function works using these particular observations: For α=4 and β=2, and each of n∈{5,20,50,100,150,200}, simulate 10,000 realizations of α ̂_MLE and β ̂_MLE. Create histograms of the MLEs faceted by sample size with vertical lines indicating the true values of the parameters. Verify that the MLEs are indeed asymptotically unbiased and normally distributed. (hint: restrict the x-axis to (0,15) for α ̂ and (0,5) for β ̂).
mle_summary <- many_mles %>%summarize(alpha_bias =mean(alpha_hat -4),beta_bias =mean(beta_hat -2),.by = n)ggplot(data = mle_summary) +geom_line(aes(x = n, y = alpha_bias)) +geom_line(aes(x = n, y = beta_bias, col ="beta")) +geom_hline(yintercept =0, linetype =2) +theme_classic() +ylab("Bias")
S3. In this problem we will explore some of the regularity conditions necessary for asymptotic efficiency and normality of MLEs. Consider Warmup Problem 1, where we have a sample of n i.i.d. BERN(p) data and we want to estimate τ(p)=p(1-p) using the MLE τ ̂(p)=p ̂(1-p ̂) (where p ̂ is the sample proportion of 1’s observed). The CRLB for any unbiased estimator of τ(p) we derived as (p(1-p) (1-2p)^2)/n. Using asymptotic normality and efficiency of MLEs, we derived the following asymptotic 95% confidence interval: τ ̂(p)±1.96√((CRLB,) ̂ ) with plug-in estimators to estimate the CRLB.
For each n∈{10,20,40,80,160,320,640,1280} and p∈{0.1,0.2,0.3,0.4,0.5}, simulate 10,000 realizations of τ ̂(p) and 95% CIs for τ(p). Then: Plot the simulated densities of τ ̂(p) faceted by each {n,p} combination (hint: free up the scales). How does the size of p impact how quickly asymptotic normality “kicks in” for τ ̂? Are there any values of p for which normality never kicks in? Plot the 95% CI coverage of τ(p) as a function of n for each p. Make sure to add a horizontal reference line at 95%. How can your results of a) be used to explain your results? Note that this study illustrates one of the regularity conditions necessary to ensure asymptotic normality of the MLE, essentially, that the MLE is not likely to occur on the boundary of the parameter space. What is the parameter space of τ(p) (that is, what are the possible values τ(p) can take on?)
The size of p imapcts how quickly we converge to normality as at 1 it takes lomger and .2-.4 we converge quicker and at .5 we have a maxed tau which leads our graph to go nonnormal.
Our results from a can be useful here as we can see that .5 doesn’t converge and that .2-.4 converge quicker than .1 which is what we would expect to happen based on part a.
The possible values tau can take on is 0 to .25 and thats why at .5 when we reach our parameter boundary we have issues.