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.

**Exercise 1**

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.

**Exercise 2**

Using an appropriate function from the MASS library, evaluate the log-likelihood for this dataset.

**Exercise 3**

From this evaluation, also obtain MLEs for the shape and rate parameters.

**Exercise 4**

Obtain the standard errors for the shape parameter.

**Exercise 5**

Use a wald test to calculate a test statistic to determine if the shape MLE differs from 2 at the 5% level.

**Exercise 6**

Generate an exact p-value for this test.

**Exercise 7**

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)

**Exercise 8**

Create a single bootstrapped sample and calculate the variance from this.

**Exercise 9**

Turn your solution from step 8 into a for loop, generating 100 bootstrapped samples and test statistics.

**Exercise 10**

Calculate a 95% confidence interval for your bootstrapped test statistic.

## Leave a Reply