Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 带自举的标准误差和零偏差_R_Regression_Resampling_Statistics Bootstrap - Fatal编程技术网

R 带自举的标准误差和零偏差

R 带自举的标准误差和零偏差,r,regression,resampling,statistics-bootstrap,R,Regression,Resampling,Statistics Bootstrap,我想对我的数据集bodyfat_进行修剪,并使用引导来检索平均值和标准误差。然而,我似乎一直在使用相同的数据,因此得到零标准误差和偏差。我怎样才能解决这个问题 bsfunc <- function(data) { set.seed(1) x <- model.matrix(reduced_BIC_fit)[, -1] y <- data$density bootdata <- sample(1:nrow(x), nrow(x)/2)

我想对我的数据集bodyfat_进行修剪,并使用引导来检索平均值和标准误差。然而,我似乎一直在使用相同的数据,因此得到零标准误差和偏差。我怎样才能解决这个问题

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

如果种子在函数中,示例函数将有点重复

bsfunc<-function(){set.seed(1); sample(1:10,1)}
bsfunc()
[1] 3
bsfunc()
[1] 3
bsfunc()
[1] 3
PS
你的bsfunc也被误解了。如前所述,训练即引导框架您的函数在第一行中设置了.seed1。如果你把它拿出来会发生什么?非常感谢,这会带来清晰!所以,把种子放在外面,使用bsfunc进行统计和拟合,我仍然一遍又一遍地得到相同的结果。set.seed1 bsfunc我也有同样的问题。。。你有没有解决过这个问题?
bsfunc<-function(){set.seed(1); sample(1:10,1)}
bsfunc()
[1] 3
bsfunc()
[1] 3
bsfunc()
[1] 3