DATA 352/551: Homework 7

Use the nCoV_simple dataset for the following questions.

  1. In class, we used parametric bootstrap (with a Weibull model) to study the \(90th\) percentile of the incubation period. We now use the nonparametric bootstrap to study the \(90th\) percentile.

    1. What is the \(90th\) percentile of the incubation period among patients in the dataset? Recall, in R, you can use the quantile function.

    2. Obtain \(B=1000\) (nonparametric) bootstrap samples; record the \(90th\) percentile of each bootstrap sample. What is the SD of the \(90th\) percentile based on your bootstrap samples?

    3. Compared to the median (we have estimated its SD in class), does the \(90th\) percentile have more or less variation?

    4. Obtain a \(95\%\) confidence interval for the \(90th\) percentile of the incubation period.

Show solution
ncov_simple <- read.csv("../all_lectures/nCoV_simple.csv")

# a
quantile(ncov_simple$incubation, probs = 0.9)
  90% 
6.785 
# b
bootsize <- 1000
bootresult <- rep(NA, bootsize)
for (i in seq_len(bootsize)) {
  bootresult[i] <- quantile(sample(ncov_simple$incubation, replace = TRUE), probs = 0.9)
}
sd(bootresult)
[1] 1.091851
# The 90th percentile has more variation than the median.

# d
quantile(bootresult, probs = c(0.025, 0.975))
 2.5% 97.5% 
5.500 9.104 
  1. Suppose we want to use nonparametric bootstrap to study the maximum incubation period.

    1. What is the maximum incubation period among patients in the dataset?

    2. Obtain \(B=1000\) bootstrap samples and construct a \(95\%\) confidence interval for the maximum incubation period.

    3. Briefly explain why bootstrap does not work well for estimating the maximum incubation period.

Show solution

The maximum incubation period in the dataset is 11 days. The bootstrap confidence interval is 8.5 to 11 days, which underestimates uncertainty because bootstrap samples cannot produce a maximum greater than 11.

# a
max(ncov_simple$incubation)
[1] 11
# b
bootsize <- 1000
bootresult <- rep(NA, bootsize)
for (i in seq_len(bootsize)) {
  bootresult[i] <- max(sample(ncov_simple$incubation, replace = TRUE))
}
quantile(bootresult, probs = c(0.025, 0.975))
 2.5% 97.5% 
  8.5  11.0 
  1. In this question, we use parametric bootstrap to obtain confidence intervals for the parameters of a log-normal model.

    1. What is the plug-in distribution in this case?

    2. Generate one bootstrap sample from the plug-in distribution and re-fit the log-normal model. What are the new parameter estimates?

    3. Repeat (b) for 1000 times to obtain 1000 estimates for each of the log-normal model parameters. Construct \(99\%\) confidence intervals for each of the parameters.

Show solution

The plug-in distribution is a log-normal distribution with parameters meanlog = 1.209 and sdlog = 0.731.

# a
library(MASS)
model1 <- fitdistr(ncov_simple$incubation, "lognormal", lower = 0)
model1$estimate
  meanlog     sdlog 
1.2092543 0.7307774 
# b
samplesize <- nrow(ncov_simple)  # sample size is 50 for the dataset
bootdata <- rlnorm(samplesize, meanlog = model1$estimate[1], sdlog = model1$estimate[2])
fitdistr(bootdata, "lognormal", lower = 0)
    meanlog       sdlog   
  1.27433563   0.68582472 
 (0.09699026) (0.06858247)
# c
bootsize <- 1000
bootresult1 <- rep(NA, bootsize)
bootresult2 <- rep(NA, bootsize)
for (i in seq_len(bootsize)) {
  bootdata <- rlnorm(samplesize, meanlog = model1$estimate[1], sdlog = model1$estimate[2])
  modelboot <- fitdistr(bootdata, "lognormal", lower = 0)
  bootresult1[i] <- modelboot$estimate[1]
  bootresult2[i] <- modelboot$estimate[2]
}
quantile(bootresult1, c(0.005, 0.995))
    0.5%    99.5% 
0.950586 1.464269 
quantile(bootresult2, c(0.005, 0.995))
     0.5%     99.5% 
0.5386822 0.8979159 
# We can also compare the SDs of the estimated model parameters
# calculated with and without bootstrap.
model1$sd
   meanlog      sdlog 
0.10334753 0.07307774 
sd(bootresult1)
[1] 0.1008653
sd(bootresult2)
[1] 0.07290932