在 R 中使用 mice 包进行多重插补的残差图
Residual plots for multiple imputation using mice package in R
使用 mice
包,我们如何检查合并分析的残差?
library(mice)
imp <- mice(nhanes, seed = 23109)
fit <- with(imp, lm(chl ~ age + bmi))
pool(fit)
summary(pool(fit))
fit
包含每个估算数据集的分析和 pool(fit)
汇总结果。是否有命令来检查标准 lm
对象的残差,例如 plot(pool(fit))
?
我 运行 遇到了同样的问题,我用一个非常详尽的解决方案解决了它。我为每个单独的估算数据集保存了残差和拟合值。如果您只有有限数量的数据集,这可以正常工作,但如果您有更多数据集,它将变得更加复杂(我有 75 个,所以我的脚本变得非常长)。
我将基于一个包含 5 个估算数据集的示例来解释我的解决方案:
# Computing and saving the mean residual per individual over 5 imputed datasets
RS1 <-residuals(model1$ana[[1]])+residuals(model1$ana[[2]])+residuals(model1$ana[[3]])+residuals(model1$ana[[4]])+residuals(model1$ana[[5]])
RSmodel1 <- RS1 / 5
# Computing and saving the mean predicted value per individual over 5 imputed datasets
PS1 <-predict(model1$ana[[1]])+predict(model1$ana[[2]])+predict(model1$ana[[3]])+predict(model1$ana[[4]])+predict(model1$ana[[5]])
PSmodel1 <- PS1 / 5
# Creating the residual plot
plot(RSmodel1, PSmodel1)
希望对您有所帮助!
我很清楚我的解决方案很不方便,但它会完成工作:)
只是为了改进 Floor Middel 所做的:
RS1=NULL
PS1=NULL
for(i in 1:5){
RS1=rbind(RS1,residuals(model1$analyses[[i]]))
RS=colMeans(RS1)
PS1=rbind(PS1,predict(model1$analyses[[i]]))
PS=colMeans(PS1)}
plot(RS,PS)
使用 mice
包,我们如何检查合并分析的残差?
library(mice)
imp <- mice(nhanes, seed = 23109)
fit <- with(imp, lm(chl ~ age + bmi))
pool(fit)
summary(pool(fit))
fit
包含每个估算数据集的分析和 pool(fit)
汇总结果。是否有命令来检查标准 lm
对象的残差,例如 plot(pool(fit))
?
我 运行 遇到了同样的问题,我用一个非常详尽的解决方案解决了它。我为每个单独的估算数据集保存了残差和拟合值。如果您只有有限数量的数据集,这可以正常工作,但如果您有更多数据集,它将变得更加复杂(我有 75 个,所以我的脚本变得非常长)。 我将基于一个包含 5 个估算数据集的示例来解释我的解决方案:
# Computing and saving the mean residual per individual over 5 imputed datasets
RS1 <-residuals(model1$ana[[1]])+residuals(model1$ana[[2]])+residuals(model1$ana[[3]])+residuals(model1$ana[[4]])+residuals(model1$ana[[5]])
RSmodel1 <- RS1 / 5
# Computing and saving the mean predicted value per individual over 5 imputed datasets
PS1 <-predict(model1$ana[[1]])+predict(model1$ana[[2]])+predict(model1$ana[[3]])+predict(model1$ana[[4]])+predict(model1$ana[[5]])
PSmodel1 <- PS1 / 5
# Creating the residual plot
plot(RSmodel1, PSmodel1)
希望对您有所帮助! 我很清楚我的解决方案很不方便,但它会完成工作:)
只是为了改进 Floor Middel 所做的:
RS1=NULL
PS1=NULL
for(i in 1:5){
RS1=rbind(RS1,residuals(model1$analyses[[i]]))
RS=colMeans(RS1)
PS1=rbind(PS1,predict(model1$analyses[[i]]))
PS=colMeans(PS1)}
plot(RS,PS)