【问题标题】:Adjusted R squared using 'mice'使用“老鼠”调整 R 平方
【发布时间】:2023-03-31 16:17:01
【问题描述】:

我正在使用来自 lme4 的 mice 包和 lmer 进行分析。但是,pool.r.squared() 不会在此输出上工作。我正在寻找有关如何将调整后的 R 平方的计算包含在以下工作流程中的建议。

require(lme4, mice)
imp <- mice(nhanes)
imp2 <- mice::complete(imp, "all") # This step is necessary in my analyses to include other variables/covariates following the multiple imputation
fit <- lapply(imp2, lme4::lmer, 
              formula = bmi ~ (1|age) + hyp + chl,
              REML = T)
est <- pool(fit)
summary(est)

【问题讨论】:

    标签: r lme4 r-mice


    【解决方案1】:

    这里有两个不同的问题。

    首先,关于多级/混合模型回归的 R 平方实际上是什么,有几种观点。这就是pool.r.squared 对您不起作用的原因,因为它不接受来自lm() 以外的任何结果。我没有答案告诉你如何为你的模型计算 R-squared-ish,因为它是一个统计问题——不是编程问题——我不会详细说明。但是,快速搜索表明,对于某些类型的多级 R 方,有 R 可用的函数,例如mitml::multilevelR2.

    其次,为了跨插补样本汇集统计数据,它应该是正态分布的。因此,您必须将 R-squared 转换为 Fisher's Z,并在池化后对其进行反向转换。见https://stefvanbuuren.name/fimd/sec-pooling.html

    在下文中,我假设您有一种方法(或多种选择)来计算(调整后的)R 平方。假设您使用mitl::multilevelR2 并选择 LaHuis 等人的方法。 (2014),您可以通过以下步骤在您的插补中计算和汇集它:

    # what you did before:
    imp <- mice::mice(nhanes)
    imp2 <- mice::complete(imp, "all")
    fit_l <- lapply(imp2, lme4::lmer, 
                  formula = bmi ~ (1|age) + hyp + chl,
                  REML = T)
    
    # get your R-squareds in a vector (replace `mitl::multilevelR2` with your preferred function for this)
    Rsq <- lapply(fit_l, mitml::multilevelR2, print="MVP")
    Rsq <- as.double(Rsq)
    
    # convert the R-squareds into Fisher's Z-scores
    Zrsq <- 1/2*log( (1+sqrt(Rsq)) / (1-sqrt(Rsq)) )
    
    # get the variance of Fisher's Z (same for all imputation samples)
    Var_z <- 1 / (nrow(imp2$`1`)-3)
    Var_z <- rep(Var_z, imp$m)
    
    # pool the Zs
    Z_pool <- pool.scalar(Zrsq, Var_z, n=imp$n)$qbar
    
    # back-transform pooled Z to Rsquared
    Rsq_pool <- ( (exp(2*Z_pool) - 1) / (exp(2*Z_pool) + 1) )^2
    
    Rsq_pool #done
    
    

    【讨论】:

    • 非常感谢您的深刻见解和帮助!
    猜你喜欢
    • 2021-04-26
    • 1970-01-01
    • 2022-01-16
    • 2016-08-28
    • 2021-02-15
    • 2018-08-29
    • 2021-12-22
    • 2019-04-06
    • 2016-04-14
    相关资源
    最近更新 更多