Hello

I would like to pass a model formula as an argument to the with.mids function from the mice package. The with.mids functon fits models to multiply imputed data sets.

Here's a simple example

library(mice)

#Create multiple imputations on the nhanes data contained in the mice package.
imp <- mice(nahnes)

#Fitting a linear model with each imputed data set the regular way works fine
with(imp, lm(bmi~hyp+chl))

#Creating a formula object and than passing it as argument does not work:
form.obj <- formula(bmi~hyp+chl)
with(imp, lm(form.obj))

#The following doesn't work either
expr <-"lm(bmi~hyp+chl)"
with(imp, expr)

Looking at the definition of with.mids reveals that the second argument is first substituted and than evaluated within each data.frame of the multiply imputed data sets. Is there a way to pass "lm(bmi~hyp+chl)" without having to change the definition of the with.mids function?

Thanks in advance,
Erich

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to