When I test a model for multilevel imputation with mice, I get an error message that I do not understand. This is my code:
CoreMulti <- subset(Short, select = c(CHILDID,
s_id_K,
X12SESL,homelangK, T2ENNAT,
X_RACETH_R, X_CHSEX_R, X1KAGE_R, X1PLTOT, X1EBRSTOT, X1NRWABL,
X1MTHETK5, X1RTHETK5, X1DCCSTOT,
T4RLVINF, T4INTSTY, T4REGVWL, T4IRGVWL, T4RD1IND, T4RD1FLN, T4CMPSES, T4CONPRN, T4WRTSKIL,
T4PLCVL, T4WHNUM, T4COINS, T4GRPHAC, T4ESTQNT, T4MEASU, T4STRAT, T4FRACTN,
T4OBSERV, T4EXPLAN, T4CLSSF, T4SCIPRT, T4CMSCIN, T4PHYSCN, T4LIFSCN, T4ERSPSN,
X6RTHETK5, X6MTHETK5, X6STHETK5
))
pred2 <- make.predictorMatrix(CoreMulti)
#Cluster Variable for multilevel imputation
pred2[,"s_id_K"] <- -2
#Variables not imputed,
pred2["CHILDID",] <- 0
pred2["s_id_K",] <- 0
#Variables not predicting
pred2[,"CHILDID"] <- 0
pred2[,"s_id_K"] <- 0
pred2
#Change Method
meth2 <- make.method(CoreMulti)
meth2[] <- "2l.pmm"
meth2
#Level 1 Factors: 2l.binary
meth2["homelangK"] <-"2l.binary"
meth2["T2ENNAT"] <-"2l.binary"
meth2["X_CHSEX_R"] <-"2l.binary"
meth2["CHILDID"] <- ""
meth2["s_id_K"] <- ""
imp4 <- mice(CoreMulti, m=1, method=meth2, predictorMatrix=pred2, maxit=1, seed=123)
This is the error message:
Error in str2lang(x) : :1:448: unexpected ')' 1: T+T4RLVINF+T4INTSTY+T4REGVWL+T4IRGVWL+T4RD1IND+T4RD1FLN+T4CMPSES+T4CONPRN+T4WRTSKIL+T4PLCVL+T4WHNUM+T4COINS+T4GRPHAC+T4ESTQNT+T4MEASU+T4STRAT+T4FRACTN+T4OBSERV+T4EXPLAN+T4CLSSF+T4SCIPRT+T4CMSC
I do not know why this error occurs. When I run a single-level imputation everything was fine. Is there something problematic with the names of my variables?