jackknifeAfterBootstrap(boot.obj, ..., frame.eval, ...) limits.bca(boot.obj, ..., frame.eval, ...) summary.bootstrap(object, ..., frame.eval, ...) resampGetIndices(object, frame.eval)
,
,
and other resampling functions
return objects that do not include copies of the original data.
But various functions
that use these objects need access to that data.
This is done symbolically, by using the same name or other
expression originally used. But this may fail in some circumstances,
if the data no longer exists by that name.
Or it may give incorrect results, if the data has changed.
The various
frame.eval
arguments provide a mechanism for specifying
that data; or for that matter, any other object named when
calling the original
or other function.
For example, suppose you define
B <- bootstrap(myData, mean)
.
B
does not contain a copy of
myData
, but
B$call
contains the name
myData
.
Now call
limits.bca(B)
;
this creates and evaluates a new
call
jackknife(myData, mean)
in order to perform some of its
calculations. This works only if
myData
exists
where
can find it.
That is no problem if
myData
is stored on a permanent database, but may be a problem
if it is defined only within a function. The solution is for
to do
eval(jack.call, frame.eval)
,
which tells
eval
where to find
myData
.
Normally
frame.eval
should just be the frame number
that
was called from in the first place.
The default behavior of these functions is to let
the
frame.eval
argument be the frame number from which
the object (
boot.obj
or
object
) was originally created,
if possible.
In newer versions of the resampling code, the frame number
is stored with the object itself, as the
parent.frame
component;
this is used as the default value. If that information is not
stored (say if
B
were created in an earlier version of S-PLUS),
then these functions make a guess.
The
frame.eval
argument is passed as the
local
argument to
eval
;
hence it may be anything that
eval
accepts, either a frame number
or a frame. The latter is necessary in some cases, in order to make
available one or more objects originally used in arguments to
bootstrap
; see the loop example below.
##### Simple example -- no special action needed myData <- stack.loss[1:20] B <- bootstrap(myData, mean) trace(jackknife) limits.bca(B) # note that jackknife was called untrace(jackknife) rm(myData) # limits.bca(B) # Fails, myData was not found limits.bca(B, frame.eval = list(myData = stack.loss[1:20])) # Explicitly specify a list containing myData as the frame. ##### Loop example rm(j) dataList <- split(market.frame$usage, market.frame$age) k <- length(dataList) Blist <- vector("list", k); names(Blist) <- names(dataList) for(j in 1:k) Blist[[j]] <- bootstrap(dataList[[j]], mean) Blist[[1]] # No problem - but note that data = dataList[[j]] # summary(Blist[[1]]) # fails -- "j" is not found # traceback() # Note that summary calls summary.bootstrap which calls limits.bca # which calls jackknife, referring to dataList[[j]] # Specifically note that j=1 summary(Blist[[1]], frame.eval = list(j = 1)) # Compute BCa limits for each of those bootstrap computations lapply(1:k, function(j) limits.bca(Blist[[j]], frame.eval=list(j=j))) ##### Function example -- no special action needed rm(myData, dataList, k, Blist) f <- function(data, column){ # compute BCa limits for data[,column] myData <- data[,column] B <- bootstrap(myData, colMeans) limits.bca(B) } f(fuel.frame, "Weight") # There is no problem here, because limits.bca was called from # the same function that B and myData were defined in. ##### Function example -- demonstrate a problem f <- function(data, column){ g <- function(data, column){ myData <- data[,column] bootstrap(myData, colMeans) } B <- g(data, column) limits.bca(B) } # f(fuel.frame, "Weight") # Fails, myData not found. myData was only defined in g's frame, # which no longer exists when limits.bca is called. # # Workaround would be to replace the call to limits.bca(B) with: # limits.bca(B, frame.eval = list(myData=data[,column]))