tl; dr:从空值下生成的数据集开始,我对样本进行了替换并重新采样,并对每个重新采样的数据集进行了假设检验。这些假设检验在超过5%的时间内拒绝了原假设。
在下面的非常简单的模拟中,我使用生成数据集,并为每个数据集拟合一个简单的OLS模型。然后,对于每个数据集,我通过替换替换原始数据集的行来生成1000个新数据集(该算法在Davison&Hinkley的经典文章中专门描述为适合线性回归的算法)。对于每一个,我都使用相同的OLS模型。最终,引导样本中大约16%的假设检验拒绝了null,而我们应该得到5%(就像在原始数据集中所做的那样)。
我怀疑这与重复观察导致虚假关联有关,因此为了进行比较,我尝试了以下代码中的两种其他方法(注释掉)。在方法2中,我修复,然后用原始数据集上OLS模型中的重采样残差替换在方法3中,我绘制了一个随机子样本而不进行替换。这两种选择均起作用,即它们的假设检验拒绝了5%的无效时间。ÿ
我的问题:罪魁祸首是反复观察吗?如果是这样,考虑到这是引导程序的标准方法,那么我们到底在哪里违反标准引导程序理论?
更新#1:更多模拟
我尝试了一个更简单的方案,即的仅拦截回归模型。发生相同的问题。
# note: simulation takes 5-10 min on my laptop; can reduce boot.reps
# and n.sims.run if wanted
# set the number of cores: can change this to match your machine
library(doParallel)
registerDoParallel(cores=8)
boot.reps = 1000
n.sims.run = 1000
for ( j in 1:n.sims.run ) {
# make initial dataset from which to bootstrap
# generate under null
d = data.frame( X1 = rnorm( n = 1000 ), Y1 = rnorm( n = 1000 ) )
# fit OLS to original data
mod.orig = lm( Y1 ~ X1, data = d )
bhat = coef( mod.orig )[["X1"]]
se = coef(summary(mod.orig))["X1",2]
rej = coef(summary(mod.orig))["X1",4] < 0.05
# run all bootstrap iterates
parallel.time = system.time( {
r = foreach( icount( boot.reps ), .combine=rbind ) %dopar% {
# Algorithm 6.2: Resample entire cases - FAILS
# residuals of this model are repeated, so not normal?
ids = sample( 1:nrow(d), replace=TRUE )
b = d[ ids, ]
# # Method 2: Resample just the residuals themselves - WORKS
# b = data.frame( X1 = d$X1, Y1 = sample(mod.orig$residuals, replace = TRUE) )
# # Method 3: Subsampling without replacement - WORKS
# ids = sample( 1:nrow(d), size = 500, replace=FALSE )
# b = d[ ids, ]
# save stats from bootstrap sample
mod = lm( Y1 ~ X1, data = b )
data.frame( bhat = coef( mod )[["X1"]],
se = coef(summary(mod))["X1",2],
rej = coef(summary(mod))["X1",4] < 0.05 )
}
} )[3]
###### Results for This Simulation Rep #####
r = data.frame(r)
names(r) = c( "bhat.bt", "se.bt", "rej.bt" )
# return results of each bootstrap iterate
new.rows = data.frame( bt.iterate = 1:boot.reps,
bhat.bt = r$bhat.bt,
se.bt = r$se.bt,
rej.bt = r$rej.bt )
# along with results from original sample
new.rows$bhat = bhat
new.rows$se = se
new.rows$rej = rej
# add row to output file
if ( j == 1 ) res = new.rows
else res = rbind( res, new.rows )
# res should have boot.reps rows per "j" in the for-loop
# simulation rep counter
d$sim.rep = j
} # end loop over j simulation reps
##### Analyze results #####
# dataset with only one row per simulation
s = res[ res$bt.iterate == 1, ]
# prob of rejecting within each resample
# should be 0.05
mean(res$rej.bt); mean(s$rej)
更新2:答案
在评论和答案中提出了几种可能性,我进行了更多的模拟以进行经验测试。事实证明,JWalker是正确的,问题在于我们需要以原始数据的估计值为中心来计算引导统计信息,以便在下获得正确的采样分布。但是,我还认为,尽管在这种情况下解决JWalker问题时,实际上确实得到了名义上的误报,但胡布尔关于违反参数测试假设的评论也是正确的。
ids
ids <- unique(ids)