引导标准错误和偏置为零

问题描述 投票:0回答:1

我想获取我的数据集bodyfat_trimmed并使用bootstrapping来检索均值和标准错误。但是,我似乎一直在使用相同的数据,因此得到零标准误差和偏差。我怎么解决这个问题?

bsfunc <- function(data) {
    set.seed(1)
    x <- model.matrix(reduced_BIC_fit)[, -1]
    y <- data$density
    bootdata <- sample(1:nrow(x), nrow(x)/2)
    x.train <- x[bootdata, ]
    y.train <- y[bootdata]
    bootframe <- data.frame(bodyfat_trimmed[train, ])
    fit <- lm(density ~ age + abdomen + wrist, data = bootframe)
    stats <- coef(summary(fit))[, "Estimate"]
    return(stats)}
strap <- boot(data = bodyfat_trimmed, sim = "parametric", statistic =    bsfunc, R=1000)
strap

输出:

PARAMETRIC BOOTSTRAP


Call:
boot(data = bodyfat_trimmed, statistic = bsfunc, R = 1000, sim =  "parametric")


Bootstrap Statistics :
         original  bias    std. error
t1*  1.1360858253       0           0
t2* -0.0000889957       0           0
t3* -0.0018446625       0           0
t4*  0.0050609837       0           0
r regression resampling statistics-bootstrap
1个回答
1
投票

如果种子在函数内,则样本函数将有些重复。

bsfunc<-function(){set.seed(1); sample(1:10,1)}
bsfunc()
[1] 3
bsfunc()
[1] 3
bsfunc()
[1] 3

PS你的bsfunc也是错误的。如上所述,train(即bootframe <- data.frame(bodyfat_trimmed[train, ]))并非来自此功能。通常boot的重点是进行自举重新采样。而bsfunc应该是一个直接的统计数据。

© www.soinside.com 2019 - 2024. All rights reserved.