如何在R中使用bootstrap提取线性模型预测的标准偏差

如何在R中使用bootstrap提取线性模型预测的标准偏差,r,R,我有一个训练数据集Y=1,2,3,4,5和X=1,2,2,3,4。我想估计X=3时预测的标准偏差。我如何在R中做到这一点。下面是我已经完成的代码,但我不确定我的过程 y <- c(1,2,3,4,5) #input predictor x <- c(1,2,2,3,4) #input response data.set <- data.frame(x,y) #create data frame for x, y boot.fn <- function(data, inde

我有一个训练数据集Y=1,2,3,4,5和X=1,2,2,3,4。我想估计X=3时预测的标准偏差。我如何在R中做到这一点。下面是我已经完成的代码,但我不确定我的过程

y <- c(1,2,3,4,5) #input predictor
x <- c(1,2,2,3,4) #input response
data.set <- data.frame(x,y) #create data frame for x, y
boot.fn <- function(data, index)
{
  linreg <- lm(y~x, data = data, subset=index)
  prediction <- predict.lm(linreg, data.frame(x=c(3)))
  return(prediction)
}
boot(data.set, boot.fn, R=1200)

上述程序是正确的。当应用bootstrap时,估计的标准误差是估计的标准偏差