1
$\begingroup$

I've been working through a book Modern Data Science with R and I have a conceptual question about bootstrapping and confidence intervals.

Say you do a bootstrap for a mean 1000 times. How do you get the 95% confidence interval? According to the demonstration in the book, you simply calculate the .025, .975 quantile. Can anybody explain why this is so? I'm wondering why this process doesn't include the familiar steps of calculating a confidence interval like you'd do in a t-test.

Just in case there are any R users that want a reference to a specific example of the book exercise I am working with, it is here:

https://mdsr-book.github.io/instructor/foundations-ex.html

I am using R and the data for the 2nd exercise is the Gestation dataset available in the MosaicData package.

This question was prompted by the difference between the 1st exercise and the 2nd one. The 1st exercise simply asked to calculate a confidence interval which I solved simply with the t.test function.

The 2nd exercise I first solved with the Mosaic package (following book demonstration) but didn't really know "why" the answer works. (Book showed the procedure but didn't explain)

So I'm basically wondering WHY the 95% confidence interval can be obtained by getting 1,000 or so means with resampling (e.g. bootstrap) and then getting the appropriate quantile.

$\endgroup$
  • $\begingroup$ There are many varieties of bootstraps: parametric (distribution family assumed) and non-parametric (re-sample from data themselves); bias-corrected and not. From an (admittedly impatient) browsing of your link, I was not able to fill in the blanks. Please state the specific context of your question. $\endgroup$ – BruceET Jun 23 '18 at 20:40
0
$\begingroup$

Here is an example of a nonparametric bootstrap confidence interval -- with some explanation of how it is obtained.

Suppose I have $n = 30$ observations from an unknown distribution and want a 95% confidence interval for the population mean $\mu.$ (Ignore numbers in brackets.)

y
 [1] 22.1 25.9 30.3  6.7 18.1 13.6 13.4 40.4 14.9 37.3 16.9 22.1 26.3 24.7 39.6
[16] 27.0 22.5 11.1 10.8 31.4 38.4 22.3 30.4 24.3 26.5 31.7 14.0 13.9 49.2 47.9
mean(y)
[1] 25.12333

I take $\bar Y = 25.12333,$ denoted a.obs in the program below, as a point estimate of $\mu.$

In order to make a confidence interval (CI), I have to know about the variability of the population around its mean. If I knew the distribution pf $D = \bar Y = \mu,$ I could find numbers $L$ and $U,$ such that $P(L \le D = \bar Y - \mu \le U) = 0.95.$ Then I would have $P(\bar Y - U \le \mu \le \bar Y - L) = 0.95$ and a 95% CI for $\mu$ would be of the form $(\bar Y - U, \bar Y - L).$

Not knowing the values $L$ and $U,$ I enter the 'bootstrap world' in order to get estimates $L^*$ and $U^*$ of these values, respectively. Momentarily, I take the observed $\bar Y$ as a proxy for the unknown $\mu.$ I take a large number $B$ of "re-samples" of of the data. Each re-sample is of size $n = 30$ and re-samples are taken with replacement from the original sample.

For each re-sample, I find the mean $\bar Y^*$ and $D^* = \bar Y^* - \bar Y.$ This gives me a $B$ values $D^*.$ I cut 2.5% from the lower and upper ends of this collection of $D^*$'s to find the required values $L^*$ and $U^*.$

Returning, to the "real world", $\bar Y$ returns to it's original role as the observed mean of the sample, and a 95% nonparametric bootstrap CI for $\mu$ is of the form $\bar Y - U^*, \bar Y - L^*).$

In the following R program, suffixes .re are used instead of $*$'s to indicate quantities that result from re-sampling and the observed $\bar Y$ is called a.obs. The program assumes that the data y are already present.

set.seed(624);  B = 10^4;  d.re = numeric(B)
a.obs = mean(y);  n = length(y)
for (i in 1:B) {
  a.re = mean(sample(y, n, repl=T))
  d.re[i] = a.re - a.obs }
L.re = quantile(d.re, .025);  U.re = quantile(d.re, .975)
c(a.obs - U.re,  a.obs - L.re)
   97.5%     2.5% 
21.14325 28.88333 

Thus a 95% nonparametric bootstrap CI for $\mu$ is $(21.1, 28.9).$ Each run of the program gives a slightly different result if you omit the set.seed statement; retain that statement to replicate the exact answer above. However, with $B = 10,000$ iterations differences from one run to another will be small; a second run with an unknown seed gave the interval $(21.2, 29.0).$

A 95% t confidence interval is $(21.0, 29.2).$ It is based on the assumption that the data are normal (and contemplates the symmetrical tails of a normal population). The bootstrap CI assumes that the data are a random sample from a population with mean $\mu$. It assumes only that the population is capable of producing the values observed.

Notes: (1) The data y were randomly sampled from a gamma distribution with shape parameter 5 and mean 25.

(2) This is a 'bias-corrected' bootstrap CI. A version without bias correction would be to bootstrap a.re and use quantile(a.re, c(.025,.975)) as the CI. Some authors do that and then apply bias correction retroactively, using 2*a.obs - quantile(a.re, c(.025,.975)). (This is equivalent to the program above, but then it's not so easy to explain the role of 2*a.obs.)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.