https://classroom.github.com/a/4X9qFO7N

Due: 2020-04-06 by 11:59pm

  1. Assume the population distribution of interest is \(\text{Exponential}(\lambda = 3)\).

    1. Generate a random sample of \(N = 314\) observations from the population of interest and store it into a vector named x.

    2. In a for loop of length R = 1001, repeatedly sample with uniform probabilities and with replacement observations from the vector x. For each re-sampled vector, calculate and store the sample mean. Don’t forget to pre-allocate your memory.

    3. Make a density plot of the R sample means.

    4. Describe the sampling distribution of the sample mean. What approximate shape does it take on? Why? Explain.

    5. Will the width of the sampling distribution get wider or narrower as your sample size increase? If you’re not sure, change N above and repeat a. through c to find out.

    6. Use the function quantile(), along with the vector of bootstrap re-sampled means, to calculate an 80% confidence interval for population mean. Interpret this confidence interval.

  2. Assume the population distribution of interest in \(\text{Binomial}(K = 15, p = 0.4)\).

    1. Use the function rbinom(N, K, p) to generate a random sample of \(N = 314\) observations from the population of interest and store it into a vector named x.

    2. Write in R a function that returns negative one times the simplified log-likelihood for N observations from the population of interest. The function signature should be

    ll_binomial <- function(p, K, X) {...}
    1. Use the function optim(...), along with the vector named x that you generated in a., to find the maximum likelihood estimate of \(p\), \(\hat{p}\) by minimizing the function your wrote in part b.. Remember that \(p\) is bounded between \(0\) and \(1\), such that you should set the lower and upper bounds as arguments to optim().