You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I have been working on this for almost 2 weeks now and I couldn't find the answer.. so I decided to ask here.
This question is about specifying a imputation model (Multi level MI) with two explanatory variable, one at the individual level (variable name C) and one at the group level (variable name W), including a random slope and interaction effects. Response variable name is R.
The Model that I am interested is following (in lmer syntax).
lmer(R~MC+C_MC+W+MC:C_MC+W:C_MC+(C_MC | id) )
where MC is group mean of C,
C_MC is deviation from group mean MC (Also C_MC has random slope)
and I also want to specify my imputation model to be exactly same as the model that I am interested in.
Note that there are only 4 variable (with missing in R and C and fully observed W and id which indicates the group number) in the dataset I simulated. (missing depends on W)
Below is how I specified imputation model, and it produces warning message that I cannot fix.
visit=c("R","MR","R_MR", "W.R_MR","C","MC","C_MC","MC.C_MC","W.C_MC")
imp1 <- mice(d, pred = pred, meth = meth, visit = visit, m = 10, allow.na = TRUE)
Predication matrix looks below.
However, when I run the code, it generates warning messages that number of items to replace is not a multiple of replacement length.
Can anyone please tell me what is wrong with my imputation model and if possible, how to fix it?
P.S
Surprisingly, when I added interaction effect between W:MC ( W= level 2 variable, MC = group mean of C) into imputation model like below prediction matrix, it worked without an error.
I don't understand why it worked and have very strong desire to understand the reason. Please help.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello. I have been working on this for almost 2 weeks now and I couldn't find the answer.. so I decided to ask here.
This question is about specifying a imputation model (Multi level MI) with two explanatory variable, one at the individual level (variable name C) and one at the group level (variable name W), including a random slope and interaction effects. Response variable name is R.
The Model that I am interested is following (in lmer syntax).
lmer(R~MC+C_MC+W+MC:C_MC+W:C_MC+(C_MC | id) )
where MC is group mean of C,
C_MC is deviation from group mean MC (Also C_MC has random slope)
and I also want to specify my imputation model to be exactly same as the model that I am interested in.
Note that there are only 4 variable (with missing in R and C and fully observed W and id which indicates the group number) in the dataset I simulated. (missing depends on W)
Below is how I specified imputation model, and it produces warning message that I cannot fix.
d=data.frame(method1, MR=NA, R_MR=NA, MR.R_MR=NA, W.R_MR=NA, MC=NA, C_MC=NA, MC.C_MC=NA, W.C_MC=NA)
meth=make.method(d)
meth[c("R","C")]="2l.norm"
meth[c("W","id")]="2l.pmm"
meth[c("MR","MC")]="2l.groupmean"
meth["R_MR"]="~I(R-MR)"
meth["C_MC"]="~I(C-MC)"
meth["MR.R_MR"]="~I(MR * R_MR)"
meth["MC.C_MC"]="~I(MC * C_MC)"
meth["W.R_MR"]="~I(W * R_MR)"
meth["W.C_MC"]="~I(W * C_MC)"
pred=make.predictorMatrix(d)
pred[,]=0
pred[,"id"]=-2
pred["R",]=c(-2,0,0,1,0,0,0,0,1,2,1,1)
pred["C",]=c(-2,0,0,1,1,2,1,1,0,0,0,0)
pred["MR", c("id", "R")]=c(-2,1)
pred["MC", c("id", "C")]=c(-2,1)
visit=c("R","MR","R_MR", "W.R_MR","C","MC","C_MC","MC.C_MC","W.C_MC")
imp1 <- mice(d, pred = pred, meth = meth, visit = visit, m = 10, allow.na = TRUE)
Predication matrix looks below.
However, when I run the code, it generates warning messages that number of items to replace is not a multiple of replacement length.
Can anyone please tell me what is wrong with my imputation model and if possible, how to fix it?
P.S
Surprisingly, when I added interaction effect between W:MC ( W= level 2 variable, MC = group mean of C) into imputation model like below prediction matrix, it worked without an error.
I don't understand why it worked and have very strong desire to understand the reason. Please help.
Beta Was this translation helpful? Give feedback.
All reactions