问题描述
我正在尝试使用R的boot
包中的boot.ci
从参数引导程序计算经过偏差和偏斜校正的引导程序置信区间.通过阅读手册页和实验,我得出结论,我必须自己计算折刀估计值并将其输入boot.ci
,但这在任何地方都没有明确说明.我没有找到其他文档,尽管公平地说,我没有看过基于Davison和Hinkley编写代码的原始书...
I am attempting to use boot.ci
from R's boot
package to calculate bias- and skew-corrected bootstrap confidence intervals from a parametric bootstrap. From my reading of the man pages and experimentation, I've concluded that I have to compute the jackknife estimates myself and feed them into boot.ci
, but this isn't stated explicitly anywhere. I haven't been able to find other documentation, although to be fair I haven't looked at the original Davison and Hinkley book on which the code is based ...
如果我天真地先运行b1 <- boot(...,sim="parametric")
,然后再运行boot.ci(b1)
,则会收到错误influence values cannot be found from a parametric bootstrap
.当且仅当我指定type="all"
或type="bca"
时,才会发生此错误. boot.ci(b1,type="bca")
给出相同的错误. empinf(b1)
也是如此.使工作正常的唯一方法是显式计算折刀估计值(将empinf()
与data
参数一起使用)并将其输入到boot.ci
中.
If I naively run b1 <- boot(...,sim="parametric")
and then boot.ci(b1)
, I get the error influence values cannot be found from a parametric bootstrap
. This error occurs if and only if I specify type="all"
or type="bca"
; boot.ci(b1,type="bca")
gives the same error. So does empinf(b1)
. The only way I can get things to work is to explicitly compute jackknife estimates (using empinf()
with the data
argument) and feed these into boot.ci
.
构造数据:
set.seed(101)
d <- data.frame(x=1:20,y=runif(20))
m1 <- lm(y~x,data=d)
引导程序:
b1 <- boot(d$y,
statistic=function(yb,...) {
coef(update(m1,data=transform(d,y=yb)))
},
R=1000,
ran.gen=function(d,m) {
unlist(simulate(m))
},
mle=m1,
sim="parametric")
到目前为止还不错.
boot.ci(b1)
boot.ci(b1,type="bca")
empinf(b1)
全部给出上述错误.
这有效:
L <- empinf(data=d$y,type="jack",
stype="i",
statistic=function(y,f) {
coef(update(m1,data=d[f,]))
})
boot.ci(b1,type="bca",L=L)
有人知道我是否应该这样做吗?
Does anyone know if this is the way I'm supposed to be doing it?
更新:boot
软件包的原始作者回复了一封电子邮件:
update: The original author of the boot
package responded to an e-mail:
您当然可以做您正在做的事情,但是我不确定 混合参数重采样的理论特性 非参数区间估计.
You can certainly do what you're doing but I am not sure of the theoretical properties of mixing parametric resampling with non-parametric interval estimation.
推荐答案
查看boot.ci页面后,我决定使用按照Davison和Hinkley第6章中的示例构造的启动对象,并查看是否它产生了您观察到的错误.我确实收到警告,但没有错误.
After looking at the boot.ci page I decided to use a boot-object constructed along the lines of an example in Ch 6 of Davison and Hinkley and see whether it generated the errors you observed. I do get a warning but no errors.:
require(boot)
lmcoef <- function(data, i){
d <- data[i, ]
d.reg <- lm(y~x, d)
c(coef(d.reg)) }
lmboot <- boot(d, lmcoef, R=999)
m1
boot.ci(lmboot, index=2) # I am presuming that the interest is in the x-coefficient
#----------------------------------
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates
CALL :
boot.ci(boot.out = lmboot, index = 2)
Intervals :
Level Normal Basic
95% (-0.0210, 0.0261 ) (-0.0236, 0.0245 )
Level Percentile BCa
95% (-0.0171, 0.0309 ) (-0.0189, 0.0278 )
Calculations and Intervals on Original Scale
Warning message:
In boot.ci(lmboot, index = 2) :
bootstrap variances needed for studentized intervals
这篇关于引导程序包中的参数引导程序可调整引导程序置信区间(BCa)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!