1

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を使用できますか?

答えて

0

ブートストラップのリサンプルが少なすぎます。 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 
+1

@coffeeinjunkyありがとう!問題が非常に懐古的だったときにコードを評価するのに多大な時間を費やしたことをばかげて感じません! –

+0

うれしい私は助けることができます。 – coffeinjunky

関連する問題