【问题标题】:Confidence Interval from hierarchical bootstrap来自分层引导的置信区间
【发布时间】: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


    【解决方案1】:

    您使用的引导重采样太少。当你调用boot.ci时,需要影响测量,如果没有提供,它们是从empinf获得的,观察太少可能会失败。请参阅here 以获取类似的解释。

    试试

    dat.boot <- boot(dat, resamp.mean, 1000) 
    boot.ci(dat.boot, type = "bca") 
    

    给出:

    > boot.ci(dat.boot, type = "bca") 
    
    BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
    Based on 1000 bootstrap replicates
    
    CALL : 
    boot.ci(boot.out = dat.boot, type = "bca")
    
    Intervals : 
    Level       BCa          
    95%   (-0.2894,  1.2979 )  
    Calculations and Intervals on Original Scale
    Some BCa intervals may be unstable
    

    您也可以自己提供L(影响力度量)。

    # proof of concept, use appropriate value for L!
    > dat.boot <- boot(dat, resamp.mean, 4)
    > boot.ci(dat.boot, type = "bca", L = 0.2)
    BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
    Based on 4 bootstrap replicates
    
    CALL : 
    boot.ci(boot.out = dat.boot, type = "bca", L = 0.2)
    
    Intervals : 
    Level       BCa          
    95%   ( 0.1322,  1.2979 )  
    Calculations and Intervals on Original Scale
    Warning : BCa Intervals used Extreme Quantiles
    Some BCa intervals may be unstable
    

    【讨论】:

    • @coffeeinjunky 谢谢!当问题如此平淡时,我花了这么多时间评估代码,我不觉得很可笑!
    • 很高兴我能帮上忙。
    猜你喜欢
    • 1970-01-01
    • 2018-07-29
    • 1970-01-01
    • 2023-04-09
    • 2016-11-28
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多