你看看boot的帮助文档,
>?boot
这个里面说的意思是statistic是一个函数,
statistic
A function which when applied to data returns a vector containing the statistic(s) of interest. When sim = "parametric", the first argument to statistic must be the data. For each replicate a simulated dataset returned by ran.gen will be passed. In all other cases statistic must take at least two arguments. The first argument passed will always be the original data. The second will be a vector of indices, frequencies or weights which define the bootstrap sample. Further, if predictions are required, then a third argument is required which would be a vector of the random indices used to generate the bootstrap predictions. Any further arguments can be passed to statistic through the ... argument.
看他的例子:
# Usual bootstrap of the ratio of means using the city data
ratio <- function(d, w) sum(d$x * w)/sum(d$u * w)
boot(city, ratio, R = 999, stype = "w")
运行一下:
> ratio <- function(d, w) sum(d$x * w)/sum(d$u * w)
> boot(city, ratio, R = 999, stype = "w")
ORDINARY NONPARAMETRIC BOOTSTRAP
Call:
boot(data = city, statistic = ratio, R = 999, stype = "w")
Bootstrap Statistics :
original bias std. error
t1* 1.520313 0.02101307 0.2211474
> ratio
function(d, w) sum(d$x * w)/sum(d$u * w)
> city
u x
1 138 143
2 93 104
3 61 69
4 179 260
5 48 75
6 37 63
7 29 50
8 23 48
9 30 111
10 2 50 |