Some sample code from JSS paper 2011 can't be run #365
-
I read the paper 'mice: Multivariate Imputation by Chained Equations in R' and try to run the sample code. # 1st -----------------------------------------------------------------------
nhanes2.ext <- cbind(nhanes2, bmi.chl = NA)
ini <- mice(nhanes2.ext, max = 0, print = FALSE)
meth <- ini$meth
meth["bmi.chl"] <- "~I((bmi-25)*(chl-200))"
pred <- ini$pred
pred[c("bmi", "chl"), "bmi.chl"] <- 0
imp <- mice(nhanes2.ext, meth = meth, pred = pred, seed = 51600)
head(ini$pad$data, 3) **# -------> It return Null for me, not like the paper** # 2nd ----------------------------------------------------------------------
ini <- mice(cbind(boys, mat = NA), max = 0, print = FALSE)
meth <- ini$meth
meth["mat"] <- "~I(as.integer(gen) + as.integer(phb) + as.integer(cut(tv,breaks=c(0,3,6,10,15,20,25))))"
meth["bmi"] <- "~I(wgt/(hgt/100)^2)"
pred <- ini$pred
pred[c("bmi", "gen", "phb", "tv"), "mat"] <- 0
pred[c("hgt", "wgt", "hc", "reg"), "mat"] <- 1
pred[c("hgt", "wgt", "hc", "reg"), c("gen", "phb", "tv")] <- 0
pred[c("wgt", "hgt", "hc", "reg"), "bmi"] <- 0
pred[c("gen", "phb", "tv"), c("hgt", "wgt", "hc")] <- 0
pred
post <- ini$post
**post["gen"] <- "imp[[j]][p$data$age[!r[,j]]<5,i] <- levels(boys$gen)[1]"
post["phb"] <- "imp[[j]][p$data$age[!r[,j]]<5,i] <- levels(boys$phb)[1]"
post["tv"] <- "imp[[j]][p$data$age[!r[,j]]<5,i] <- 1"**
imp <- mice(cbind(boys, mat = NA), pred = pred, meth = meth, post = post, maxit = 10, print = FALSE)
# It return error:
# Error in `[<-.data.frame`(`*tmp*`, p$data$age[!r[, j]] < 5, i, value = "G1") :
# No object found'p' In addition, I want to know what dose |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 1 reply
-
Thanks for your interest. The code you're citing comes from our JSS 2011 paper, which describes The Variable There is plenty of example code for Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
Thank you for you reply! It's helpful for me!
I know the means of 'constant' and 'collinear', but what the means of the log of V50? |
Beta Was this translation helpful? Give feedback.
-
Collinearity introduces feedback loops, and may cause pathological convergence, so Record 11 means: |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer! It's helpful for me! |
Beta Was this translation helpful? Give feedback.
-
Hi, Thank you so much for developing and maintaining this package! A quick question about alternatives to the Relatedly, are interaction terms for which one of the variables is determined to be collinear automatically removed from the imputation model when the main effect is removed? Thanks! |
Beta Was this translation helpful? Give feedback.
-
The Collinear variables are removed after the formula for the target variable/block is expanded. |
Beta Was this translation helpful? Give feedback.
-
Very helpful--thank you! |
Beta Was this translation helpful? Give feedback.
-
Hi, I would like to run impute missing values in my dataframe using the mice function and taking into account an interaction between two categorical (unordered) variables in my dataframe : "sympt"and "dipl" My initial plan was to adapt the following code in the 2011 presentation of the mice package in R (van Buuren, S., & Groothuis-Oudshoorn, K. (2011). mice: Multivariate Imputation by Chained Equations in R. Journal of Statistical Software, 45(3), 1–67) to :
However, with the removal of the pad component of the mids objects in mice 3.0 I did not find any alternatives to include a categorical interaction term in the mice function. Thank you very much in advance for your help |
Beta Was this translation helpful? Give feedback.
-
Use the |
Beta Was this translation helpful? Give feedback.
-
Classification and Regression Trees are ideal vehicles to preserve interactions between variables. So an alternative strategy is to set See Doove, L.L., van Buuren, S., Dusseldorp, E. (2014) Recursive Partitioning for Missing Data Imputation in the Presence of Interaction Effects. Computational Statistics and Data Analysis, 72, 92--104. |
Beta Was this translation helpful? Give feedback.
Thanks for your interest.
The code you're citing comes from our JSS 2011 paper, which describes
mice 2.09
. Both errors have the same cause: They rely on the internalpad
component to be present in themids
-object, and I admit that this is a hacky way to specify the model.The
pad
component was superfluous and complicated development, and was removed inmice 3.0
. The price is that the few code blocks that asses thepad
component directly (like the above code) won't run anymore inmice 3.0
and beyond.Variable
p
was the internal representation of thepad
component, and is not used anymore.r
is the internal representation of the response indicator.There is plenty of example code for
mice 3.0