[R] help using ecm.mix
Andreas Wittmann
andreas_wittmann at gmx.de
Sun Mar 7 11:03:07 CET 2010
Dear R-users,
i have the following exmple for which i want to use ecm.mix from the
mix-package.
with da.mix after using em.mix i get the error "improper
posterior--empty cells", which is not uncommen because of 17 * 5 * 3 =
255 cells.
so the next attempt is to use the ecm.mix for the restricted model, but
i get errors also.
what can i do to get the imputations with the mix package working? maybe
it could be reasonable to merge some levels before imputation?
best regards
Andreas
y <- matrix(0, nrow=100, ncol=4, byrow=TRUE)
y[,1] <- sample(17,100,replace=TRUE)
y[,2] <- sample(5,100,replace=TRUE)
y[,3] <- sample(3,100,replace=TRUE)
y[,4] <- rnorm(100)
y[,1] <- ifelse(rbinom(100,1,0.4)==1, NA, y[,1])
y[,2] <- ifelse(rbinom(100,1,0.7)==1, NA, y[,2])
y[,3] <- ifelse(rbinom(100,1,0.05)==1, NA, y[,3])
## first attempt, imputation under unrestricted model
s <- prelim.mix(y,3)
thetahat <- em.mix(s)
rngseed(1234567) # set random number generator seed
newtheta <- da.mix(s,thetahat,steps=100) # data augmentation
##ximp <- imp.mix(s, newtheta, y)
## da.mix gives "improper posterior--empty cells" error
## second attempt, imputation under restricted model
s <- prelim.mix(y,3)
margins1 <- c(1,2,3)
margins2 <- c(1,2,0,2,3,0,1,3)
design <- diag(rep(1,255)) # identity matrix D=no of cells
thetahat <- ecm.mix(s,margins1,design) # find ML estimate
thetahat <- ecm.mix(s,margins2,design) # find ML estimate
#rngseed(1234567) # random generator seed
#newtheta <- dabipf.mix(s,margins,design,thetahat,steps=200)
#ximp <- imp.mix(s,newtheta,stlouis) # impute under newtheta
More information about the R-help
mailing list