我使用来自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)发布于 2020-07-03 21:55:56
这里有两个独立的问题。
首先,关于多水平/混合模型回归的R平方实际上是什么,有几种意见。这就是为什么pool.r.squared不能为您工作的原因,因为它不接受来自lm()以外的任何结果。我没有为你的模型如何计算R平方的答案,因为这是一个统计问题-而不是编程问题-我不会详细介绍。然而,快速搜索表明,对于某些类型的多水平R方块,有可用于R的函数,例如mitml::multilevelR2。
其次,为了在估算样本之间汇集统计数据,它应该是正态分布的。因此,您必须将R平方转换为Fisher的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 #donehttps://stackoverflow.com/questions/62702164
复制相似问题