【问题标题】:Residual plots for multiple imputation using mice package in R使用 R 中的 mouse 包进行多重插补的残差图
【发布时间】:2015-11-22 19:53:06
【问题描述】:
使用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))?
【问题讨论】:
标签:
r
statistics
missing-data
r-mice
【解决方案1】:
我遇到了同样的问题,我用一个非常详尽的解决方案解决了它。我为每个单独的估算数据集保存了残差和拟合值。如果您只有有限数量的数据集,这可以正常工作,但如果您有更多数据集(我有 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)
希望对您有所帮助!
我很清楚我的解决方案很不方便,但它会完成这项工作:)
【解决方案2】:
只是为了改进 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)