我目前的理解是 1)如果未指定层,则引导从整个数据集中随机选择替换行。如果数据集实际上是分层的,那么引导通常会返回不均匀的样本大小。相反 2) 如果指定了层,则引导从每个层中随机选择具有替换的行,并且独立于其他层。在这种情况下,boot 将始终返回相同的样本大小。
我的统计数据是来自两个不同组的平均值的比率,因此我使用 Strata 设置了我的引导调用,我相信它会在运行我的函数之前从每个组内收集引导样本。然而,为了仔细检查我的理解,我在有和没有地层的情况下运行了 boot,并惊讶地发现结果非常相似。我是否误解了引导如何处理地层?或者这些方法会很少有不同,例如当 boot 随机收集一组非常不均匀的 bootstrap 样本时?
任何解释为什么这两种方法会产生相似的结果都值得赞赏。
下面是一个示例数据集的 R 代码,它表示我的统计数据的真实值为 10。我在指定和不指定层的情况下运行引导。我发现当指定层时估计的置信区间会稍微窄一些,但我预计会有更大的差异。
require(boot)
# relative yield takes a matrix or dataframe and finds the ratio
# of the means: treatmentMean/controlMean.
# data structure:
# first column is strata, control = 1 and treatment = 2
# second column is response, or the data to be bootstrapped
rel.yield <- function(D,i) {
trt <- D[i,1]
resp <- D[i,2]
mean(resp[trt==2]) / mean(resp[trt==1])
}
# some data that has a true rel.yield of 10
sub.pop <- matrix(data = c(rep(1,15),rep(2,15),rnorm(15,2,1),rnorm(15,20,1)),
nrow = 30, ncol = 2, dimnames = list((1:30),c('trt','resp')))
# with strata specified
b <- boot(sub.pop, rel.yield, R = 1000, strata = sub.pop[,1])
#without strata specified
c <- boot(sub.pop, rel.yield, R = 1000)
# note the distributions of t* are similar
par(mfrow=c(1,2))
hist(b$t)
abline(v=mean(b$t))
hist(c$t)
abline(v=mean(c$t))
# and the CI estimates are also similar
boot.ci(b)
boot.ci(c)