R中线性回归中随机抽样(带替换)的排列

Permutation with random sampling (with replacement) in linear regression in R

我想排列线性回归(为了不失去随机抽样和替换的能力)。

我知道如何随机抽样我的数据集:

 sampled_random <- df[sample(nrow(df), replace = TRUE),]

我的回归是这样的:

reg <- lm(DV ~ Iv1 + IV2  + IV3,  data = df)

是否有一个很好的内置函数可以用我监督的不同 sample_random 重复此回归 x 次?作为结果,我想要平均 p 值和你用 summary(reg)

得到的其他平均值

我没有足够的经验来编写自己的函数来满足我的所有需求。有没有这样做的R包?或者,更好的是,你能推荐一个好的(方便的)吗?

您可以编写自己的代码。

res <- lapply(1:100, function(i){
    sampled_random <- df[sample(nrow(df), replace = TRUE),]
    reg <- lm(DV ~ Iv1 + IV2  + IV3,  data = sampled_random)
    return(c(summary(reg)$residuals, summary(reg)$r.squared))
})