This is part 2 in a series on statistical theory using R. For part 1, go here.
This tutorial concerns itself with MLE calculations and bootstrapping.
Answers to the exercises are available here.
Set a seed to 123 and create the following dataframe:
lifespans = data.frame(index = 1:200, lifespans = rgamma(200, shape = 2, rate = 1.2)*50)
It is thought that this data of bacteria’s lifespan may follow a gamma distribution. Confirm this assumption through an exploratory plot.
Using an appropriate function from the MASS library, evaluate the log-likelihood for this dataset.
From this evaluation, also obtain MLEs for the shape and rate parameters.
Obtain the standard errors for the shape parameter.
Use a wald test to calculate a test statistic to determine if the shape MLE differs from 2 at the 5% level.
Generate an exact p-value for this test.
The goal parameters of our bootstrap are the variance. From the new dataset below, calculate the variance.
durations = c(35.8, 33.4, 34.9, 17.9, 35.6, 10.3, 14.9, 28.3, 39.2, 25.4, 23.4, 7.1, 38.9, 9.2, 8.1)
Create a single bootstrapped sample and calculate the variance from this.
Turn your solution from step 8 into a for loop, generating 100 bootstrapped samples and test statistics.
Calculate a 95% confidence interval for your bootstrapped test statistic.