General Instructions
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.
Bias Estimation
Section 10.3 in Efron and Tibshirani.
Comments
Everything pretty obvious here.
- The function
ratiocalculates the estimator we are investigating. - The bootstrap is just like other bootstraps we have done that
use the
k.startrick. - The bootstrap estimate of bias is the mean of the
theta.starminustheta.hat. This is the obvious analog in thebootstrap world
of the actual bias, which is the mean oftheta.hatminus the true unknown parameter valuetheta.
Improved
Bias Estimation
Section 10.3 in Efron and Tibshirani.
Comments
-
The main comment is about the rather strange form of the functions
rmeanandrratiothat calculate the ratio estimator.These functions use what Efron and Tibshirani call the resampling vector (pp. 130–132) and the resampling form (pp. 189–190) of the estimator.
The resampling vector is the vector of weights given to the original data points in a resample X1*, . . ., Xn*. The weight pi* given to the original data point Xi is the fraction of times Xi appears in the resample. This is calculated by the statement
p.star <- tabulate(k.star, n) / n
in the bootstrap loop, wherek.staris the by now familiar resample of indices. The analogous vector for the original sample is calculated by the statementp.star <- rep(1 / n, n)
We now have to write a function that calculates the estimator given the data
yandzthe resampling vectorp.star.Unfortunately, this is, in general, hard.
Fortunately, this is, for moments, quite straightforward.
For any function
g, any data vectorx, and any probability vectorp, the expressioncalculates the expectation of the random variable g(X) in the probability model that assigns probabilitysum(g(x) * p)p[i]to the pointx[i]for eachi(and probability zero to everywhere else).Thus
sum(x * p)
calculates the meansum((x - a)^2 * p)
calculates the second moment about the pointa, and so forth. -
The function
rmean(p, x)calculates the sample mean of the data vectorxin resampling form.The
stopcommands for various error situations are, of course, not required. If the function call is done properly they don't do anything. But it will save you endless hours of head scratching sometime if you get in the habit of putting error checks in the functions you write.The function
rratio(p, x, y)calculates the ratio estimator for dataxandyusing thermeanfunction in the obvious fashion. -
In the bootstrap loop the vector
p.baraccumulates the sum of thep.starvectors. After the bootstrap loop terminates, it is divided bynbootto give the average of thep.starvectors. -
Ideally, if
nbootwere infinity,p.barwould be the same asp.hat. Sincenbootis considerably less than infinity,p.baris different fromp.hatSince
sd(theta.star)is based on resamples that yielded thep.barvector, it makes sense to subtract offrratio(p.bar, y, z)rather thantheta.hatto estimate bias.The logic is that that the Monte Carlo errors in
sd(theta.star)andrratio(p.bar, y, z)tend to be in the same direction and cancel to some degree, giving animproved
estimator. -
This method of expressing estimators in
resampling form
is an important bootstrap technique, which will be used again for the ABCbetter
bootstrap confidence interval technique.