[R] Imputation Simulation using MICE
kungfukid
sacacataphract at yahoo.com.hk
Wed Sep 8 00:54:54 CEST 2010
Hi all,
I wish to use the mice package but before that, I tried a simulation to test
it:
#Generate the complete data matrix X with 2 variables, 10000 observations
Xcomplete=mvrnorm(10000,mu=c(0,0),Sigma=matrix(c(1,0.5,0.5,1),ncol=2))
Error=rnorm(10000,0,1)
#Create Y as X+Error
Y=Xcomplete%*%c(1,1)+Error
#Complete Data Regression
summary(lm(Y~Xcomplete))
#Construct a vector of non-missingness for X2
missingprob=0.5
R=cbind(rep(1,10000),rbinom(10000,1,1-missingprob))
#Creation of observed data matrix
#elementwise multiply with R, then remove all 0s
Xobs=Xcomplete*R
Xobs[Xobs==0]=NA
#Missing Data Regression
summary(lm(Y~Xobs))
#Use the mice package to generate imputations
XImpute=mice(m=2,Xobs,maxit=50,defaultMethod=c("norm","logreg","polyreg"))
pool(lm.mids(Y~V1+V2,XImpute))
However I got something far off. If I export and do the MI in Stata I got
the correct coefficients and std. errors. Was that I did something wrong in
the imputation stage? Thanks.
--
View this message in context: http://r.789695.n4.nabble.com/Imputation-Simulation-using-MICE-tp2530547p2530547.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list