简体   繁体   English

R:Bootstrap 百分位置信区间

[英]R: Bootstrap percentile confidence interval

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")

I am using two method to construct bootstrap percentile confidence interval but I got two different answer.我正在使用两种方法来构建 bootstrap 百分位置信区间,但我得到了两个不同的答案。

bp1=c(b[25], b[975]) get (480474,517834)

while ci=boot.ci(o,type="perc") get (480476, 517837 )ci=boot.ci(o,type="perc")得到 (480476, 517837)

How does the boot.ci construct the percentile interval? boot.ci 如何构造百分位区间?

By calling the function by itself boot.ci , the script appears.通过自行调用函数boot.ci ,脚本出现。 You can then see that the percentile CI is calculated using the function perc.ci (around line 70).然后您可以看到百分比 CI 是使用函数perc.ci计算的(第 70 行附近)。 On Github , you can get the package script.Github 上,您可以获得包脚本。 Looking for the perc.ci function, your find this:寻找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))
}

Which then leads to the norm.inter function which seems to be the one creating the vector for extracting the percentiles.然后导致了norm.inter函数,它似乎是创建用于提取百分位数的向量的函数。 Looking for this function in the same Github script tel us:在同一个 Github 脚本中查找此函数,请联系我们:

Interpolation on the normal quantile scale.在正常分位数尺度上进行插值。 For a non-integer order statistic this function interpolates between the surrounding order statistics using the normal quantile scale.对于非整数顺序统计,此函数使用正常分位数在周围顺序统计之间进行插值。 See equation 5.8 of Davison and Hinkley (1997)见戴维森和欣克利 (1997) 的方程 5.8

So it seems it's using interpolation from a normal distribution explaining why it's different from your totally empirical solution.所以它似乎是使用正态分布的插值来解释为什么它与你完全经验的解决方案不同。

The standard interval using basic boostrap I always use is:使用我一直使用的基本 boostrap 的标准间隔是:

est <- est.from.bootstrap
basic.bs <- c(2*est-quantile(bootstrap.vector, prob=0.975), 2*est -
quantile(bootstrap.vector, prob=0.025)

You can also just use the normal bootstrap interval given by:您也可以只使用以下给出的正常引导间隔:

est <- est.from.bootstrap
bs.interval <-c(est + sd(bootstrap.vector)*qnorm(0.025), est +
sd(bootstrap.vector)*qnorm(0.975)

However you can also use just the normal percentile method:但是,您也可以仅使用正常的百分位数方法:

est <- est.from.bootstrap
perc <- c(quantile(bootstrap.vector, prob=0.025), quantile(bootstrap.vector, 
prob=0.075)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM