To do each example, just click the "Submit" button. You do not have to type in any R instructions or specify a dataset. That's already done for you.
library(bootstrap)
says we are going to
use code in the bootstrap
library, which is not available
without this command.
Inspection of the lutenhorm
dataset shows that column 4
is the data described in Table 8.1 in Efron and Tibshirani.
foo
calculates the estimator of the
autoregressive coefficient described by Efron and Tibshirani.
The vector z
is the data supplied to the function with
the mean subtracted off. The number m
is the length of
the data.
The vector z[-1]
is all the elements of z
except the first and the vector z[-m]
is all the elements of
z
except the last.
Thus the statement
out <- lm(z[-1] ~ z[-m] + 0)regresses z_{t} on z_{t - 1} with no intercept (the
+ 0
means no intercept).
n
and blocks of b
there are exactly
n - b + 1
such blocks. Generally, we use them all.
No need for random samples.
beta.star
shows. However, this does not matter,
so long as b
is long enough so the samples are representative
of the behavior of the whole series.
As usual, Efron and Tibshirani are using a ridiculously small sample size in this toy problem. There is no reason to believe the subsampling bootstrap here. But it is reasonable for (much) larger data sets.
beta.star
shows that the simple method
of estimation being used here is badly biased. That's why this method
is not recommended by time series books. We only use it here because
it is easy to explain.
sqrt(b / n)
in the last line adjusts for the relative
sample sizes of the subsample and the whole series. Note that
the sqrt
here is only valid for estimators obeying the
square root law. If the rateis not
root n, then a different function of
b / n
is needed, as in the
following example.
theta.star
stores max(x)
for samples
from the subsampling bootstrap.
theta.bogo
stores max(x)
for samples
from the ordinary (Efron) bootstrap.
sample
statement is quite different for the
regular (Efron) bootstrap and the (Politis and Romano) subsampling bootstrap.
For the Efron bootstrap, we sample with replacement at the original sample size with something like
x.star <- sample(x, replace = TRUE)
The subsampling bootstrap samples without replacement at the
much smaller sample size b
with something like
x.star <- sample(x, b, replace = FALSE)
Both the size
and the replace
arguments
of sample
differ.
(For the Efron bootstrap the size
argument is missing so the
default length(x)
is used.)
z.star <- b * (theta.hat - theta.star)which is supposed to have an Exp(1 / θ) distribution according to the theory, are plotted against the appropriate quantiles of this distribution. If the points lie near the line y = x, then
z.star
does indeed have the claimed distribution.
We emphasize that we don't need to know the asymptotic distribution
to use the bootstrap samples z.star
to construct a confidence
interval for θ. We can't do it yet because we haven't covered
Chapters 12, 13, and 14 in Efron and Tibshirani. When we've done them,
we can return to this example and finish it.
theta.bogo
samples on the Q-Q
plot, so it can be clearly seen they do the Wrong Thing (with a capital W
and a capital T).