Skip to content
Prev 389837 / 398503 Next

bootstrap confidence intervals

Hi, 

Many thanks for your responses.



Le samedi 6 novembre 2021, 08:39:22 UTC+1, Rui Barradas <ruipbarradas at sapo.pt> a ?crit : 





Hello,


?s 01:36 de 06/11/21, David Winsemius escreveu:
This cheating comes from wilcox.test, which is called by HodgesLehman to 
do the calculations. Below is a function calling wilcox.test directly, 
and the bootstrapped intervals are always equal, no matter what way they 
are computed.



A <- c(488, 437, 500, 449, 364)
dat <- data.frame(A)

med <- function(d,i) {
? temp <- d[i, ]
? HodgesLehmann(temp)
}
med2 <- function(d, i, conf.level = 0.95){
? temp <- d[i, ]
? wilcox.test(temp,
? ? ? ? ? ? ? conf.int = TRUE,
? ? ? ? ? ? ? conf.level = Coalesce(conf.level, 0.8),
? ? ? ? ? ? ? exact = FALSE)$estimate
}

set.seed(2021)
boot.out <- boot(data = dat, statistic = med, R = 100)
set.seed(2021)
boot.out2 <- boot(data = dat, statistic = med2, R = 100, conf.level = 0.95)

HodgesLehmann(boot.out$t)
#[1] 452.75
HodgesLehmann(boot.out2$t)
#[1] 452.75

HodgesLehmann(boot.out$t, conf.level = 0.95)
#? ? est? lwr.ci? upr.ci
#452.7500 447.2500 458.7499
HodgesLehmann(boot.out2$t, conf.level = 0.95)
#? ? est? lwr.ci? upr.ci
#452.7500 447.2500 458.7499

quantile(boot.out$t, c(0.025, 0.975))
# 2.5% 97.5%
#400.5 494.0
quantile(boot.out2$t, c(0.025, 0.975))
# 2.5% 97.5%
#400.5 494.0

boot.ci(boot.out, type = "all")? ? # CI's are
boot.ci(boot.out2, type = "all")? # the same



But the bootstrap statistic vectors t are different:



identical(boot.out$t, boot.out2$t)
#[1] FALSE
all.equal(boot.out$t, boot.out2$t)
#[1] "Mean relative difference: 8.93281e-08"




I haven't time to check what is going on in wilcox.test, its source is a 
bit involved, with many if/else statements, maybe I'll come back to this 
but no promises made.


Hope this helps,

Rui Barradas


______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.