简体   繁体   English

调整后的 R 使用“老鼠”平方

[英]Adjusted R squared using 'mice'

I am using the mice package and lmer from lme4 for my analyses.我正在使用来自 lme4 的小鼠 package 和 lmer 进行分析。 However, pool.r.squared() won't work on this output.但是, pool.r.squared()不适用于此 output。 I am looking for suggestions on how to include the computation of the adjusted R squared in the following workflow.我正在寻找有关如何在以下工作流程中包含调整后的 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)

You have two separate problems here.你在这里有两个不同的问题。

First, there are several opinions about what an R-squared for multilevel/mixed-model regressions actually is.首先,关于多级/混合模型回归的 R 平方实际上是什么,有几种观点。 This is the reason why pool.r.squared does not work for you, as it does not accept results from anything other than lm() .这就是pool.r.squared对您不起作用的原因,因为它不接受lm()以外的任何结果。 I do not have an answer for you how to calculate something R-squared-ish for your model and since it is a statistics question – not a programming one – I am not going into detail.我没有答案告诉你如何为你的 model 计算 R 平方,因为这是一个统计问题——不是编程问题——我不会详细说明。 However, a quick search indicates that for some kinds of multilevel R-squares, there are functions available for R, eg mitml::multilevelR2 .但是,快速搜索表明,对于某些类型的多级 R 平方,有可用于 R 的函数,例如mitml::multilevelR2

Second, in order to pool a statistic across imputation samples, it should be normally distributed.其次,为了在插补样本中汇集统计数据,它应该是正态分布的。 Therefore, you have to transform R-squared into Fisher's Z and back-transform it after pooling.因此,您必须将 R-squared 转换为 Fisher's Z,并在池化后对其进行反向转换。 See https://stefvanbuuren.name/fimd/sec-pooling.htmlhttps://stefvanbuuren.name/fimd/sec-pooling.html

In the following I assume that you have a way (or several options) to calculate your (adjusted) R-squared.在下文中,我假设您有一种方法(或多种选择)来计算(调整后的)R 平方。 Assuming that you use mitl::multilevelR2 and choose the method by LaHuis et al.假设您使用mitl::multilevelR2并选择 LaHuis 等人的方法。 (2014), you can compute and pool it across your imputations with the following steps: (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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM