我正在尝试计算自举置信区间。 这是我的代码。
library(boot)
nboot <- 10000 # Number of simulations
alpha <- .01 # alpha level
n <- 1000 # sample size
bootThetaQuantile <- function(x,i) {
quantile(x[i], probs=.5)
}
raw <- rnorm(n,0, 1) # raw data
( theta.boot.median <- boot(raw, bootThetaQuantile, R=nboot) )
boot.ci(theta.boot.median, conf=(1-alpha)) #this causes no error
boot.ci(theta.boot.median, conf=(1-alpha), type = "percent") #this causes an error
错误消息显示为“ci.out[[4L]] 中的错误:下标越界”。我对此感到非常困惑,因为我不确定为什么在前一行没有错误的情况下调用 boot.ci 会导致错误。
最佳答案
那是因为你必须使用 type = 'perc'
。
boot.ci(theta.boot.median, conf=(1-alpha), type = "perc")
关于r - R 中的 boot.ci() 函数出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50800808/