【问题标题】:Permutation with random sampling (with replacement) in linear regression in RR中线性回归中随机抽样(带替换)的排列
【发布时间】:2015-12-17 12:49:07
【问题描述】:

我想置换一个线性回归(为了不因放回随机抽样而失去动力)。

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

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

我的回归是这样的:

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

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

我没有足够的经验来编写自己想要的功能。是否有一个 R 包可以做到这一点?或者,更好的是,你能推荐一个好的(方便的)吗?

【问题讨论】:

    标签: r permutation linear-regression random-sample


    【解决方案1】:

    您可以编写自己的代码。

    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))
    })
    

    【讨论】:

    • 谢谢Ven Yao,我正在寻找这样的东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多