r - R 中的 boot.ci() 函数出错

标签 r statistics-bootstrap

我正在尝试计算自举置信区间。 这是我的代码。

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/

相关文章:

r - 使用 R 并行加速 Bootstrap

r - 在 R 中为启动功能添加进度条

r - 加速时间序列模拟(用于引导)

r - 如何生成一个堆叠的 geom_area(fill) 并在不同的列中包含数据?

r - ggplot2 每周箱线图

r - 如何获取自举 p 值和自举 t 值以及函数 boot() 如何工作?

R:boot()输出的解释

r - R可以通过ssh连接从文件读取吗?

r - 在 ggradar 图中保留原始值

r - 在 R 中使用 set.seed() 和 foreach()