【发布时间】:2016-05-26 17:18:35
【问题描述】:
我想使用boot.ci() 计算多阶段引导的 BCa 置信区间。以下是来自:Non-parametric bootstrapping on the highest level of clustered data using boot() function from {boot} in R 的示例
它使用boot 命令。
# creating example df
rho <- 0.4
dat <- expand.grid(
trial=factor(1:5),
subject=factor(1:3)
)
sig <- rho * tcrossprod(model.matrix(~ 0 + subject, dat))
diag(sig) <- 1
set.seed(17); dat$value <- chol(sig) %*% rnorm(15, 0, 1)
# function for resampling
resamp.mean <- function(dat,
indices,
cluster = c('subject', 'trial'),
replace = TRUE){
cls <- sample(unique(dat[[cluster[1]]]), replace=replace)
sub <- lapply(cls, function(b) subset(dat, dat[[cluster[1]]]==b))
sub <- do.call(rbind, sub)
mean(sub$value)
}
dat.boot <- boot(dat, resamp.mean, 4) # produces and estimated statistic
boot.ci(data.boot) # produces errors
如何在boot 输出上使用boot.ci?
【问题讨论】:
标签: r statistics hierarchical-data confidence-interval statistics-bootstrap