MICE中的地带图 [英] Stripplot in MICE
问题描述
我在R中使用软件包MICE进行多次插补.我只用数值变量完成了几种插补,插补方法是预测均值匹配,当我使用命令stripplot(插补数据集的名称)时,我可以看到所有变量的观测值和插补值.
I´m using the package MICE in R to do multiple imputations. I´ve done several imputations with only numerical variables, the imputation method is predictive mean matching, and when I use the command stripplot(name of imputed dataset) I get to see the observed and imputed values of all the variables.
当我尝试对分类变量和数值变量进行归因时,就会出现问题.然后,插补方法是将PMM用于数字变量,将逻辑回归用于分类变量. stripplot-command仅显示数字变量.我尝试使用以下命令指定edu是具有2个值的类别变量:
The problem occurs when I try to do imputation on a combination of categorical and numerical variables. The imputation method then is PMM for the numerical variables, and logistical regression for the categorical ones. The stripplot-command only shows me the numerical variables. I tried to specify with these commands were edu is a categorical variable with 2 values:
stripplot(imp, imp$edu)
stripplot(imp, names(imp$edu))
我得到了这个错误:
stripplot.mids(imp,imp $ edu)错误:无法填充扩展公式.
Error in stripplot.mids(imp, imp$edu) : Cannot pad extended formula.
有人知道我该如何为数字变量和分类变量绘制观测值和推算值?
Does anyone know how I can plot the values of the observed and the imputed values for both the numerical and the categorical variables?
推荐答案
您可以尝试做的一件事是将估算出的dataset
作为data.frame进行检索,并仅使用常规的绘图功能即可.首先检索包含缺少值的原始数据集的数据集(imp是mouses.mids对象,即正在运行的鼠标的结果)
One thing you can try is to retrieve the imputed dataset
as a data.frame and just use normal plotting functions. First retrieve the datasets including the original dataset with missing values (imp is the mice.mids object i.e. result of running mice)
impL <- complete(imp,"long",include = T)
接下来添加一个虚拟值,指示要估算哪些数据集
Next add a dummy indicating which datasets are imputed
impL$Imputed <- factor(impL$.imp >0,labels = c("Observed","Imputed"))
然后,您可以仅对每个变量使用绘图功能.这样的好处是您可以创建更好的图.例如,使用ggplot
(软件包ggplot2)在分类变量上创建条形图:
Then you can just use plotting functions for each variable. This has the benefit that you can create nicer plots. For example using ggplot
(package ggplot2) to create a barplot on a categorical variable:
ggplot(impL[which(!is.na(impL$var1)),],aes(x = var1)) +
geom_bar(aes(y = ..prop.., group = Imputed)) + facet_wrap(Imputed ~ .,ncol=1,nrow=2)
包含!is.na
是为了避免绘制NA条. var1
是要绘制的变量.对于连续变量,您可以创建一个密度图.
The !is.na
is included to avoid the plotting of an NA bar. var1
is the variable you want to plot. For a continuous variable you might create a density plot.
ggplot(impL, aes(x = var2, colour = Imputed)) + geom_density()
要查看所有唯一的插补,可以在aes括号内添加group = .imp
.希望这会有所帮助
To look at all the unique imputations you can add group = .imp
within the aes brackets. Hope this helps
这篇关于MICE中的地带图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!