yap*_*yap 5 r confidence-interval statistics-bootstrap
library(boot)
set.seed(1)
x=sample(0:1000,1000)
y=function(u,i) sum(x[i])
o=boot(x,y,1000)
theta1=NULL
theta1=cbind(theta1,o$t)
b=theta1[order(theta1)]
bp1=c(b[25], b[975])
ci=boot.ci(o,type="perc")
Run Code Online (Sandbox Code Playgroud)
我使用两种方法来构建引导百分位数置信区间,但我得到了两个不同的答案。
bp1=c(b[25], b[975]) get (480474,517834)
Run Code Online (Sandbox Code Playgroud)
同时ci=boot.ci(o,type="perc")得到 (480476, 517837 )
boot.ci 如何构建百分位区间?
通过调用该函数本身boot.ci,脚本就会出现。然后您可以看到百分位数 CI 是使用该函数计算的perc.ci(第 70 行左右)。在Github上,您可以获取打包脚本。寻找该perc.ci功能,您会发现:
perc.ci <- function(t, conf = 0.95, hinv = function(t) t)
#
# Bootstrap Percentile Confidence Interval Method
#
{
alpha <- (1+c(-conf,conf))/2
qq <- norm.inter(t,alpha)
cbind(conf,matrix(qq[,1L],ncol=2L),matrix(hinv(qq[,2]),ncol=2L))
}
Run Code Online (Sandbox Code Playgroud)
然后,这导致了一个norm.inter函数,该函数似乎是创建用于提取百分位数的向量的函数。在同一个 Github 脚本中寻找此函数请告诉我们:
在正常分位数尺度上进行插值。对于非整数阶统计量,此函数使用正常分位数尺度在周围阶统计量之间进行插值。参见 Davison 和 Hinkley (1997) 的方程 5.8
因此,它似乎使用正态分布的插值来解释为什么它与您完全经验的解决方案不同。