0

I am trying to run an analysis using a dataset imputed through the mice package. However, when using the with() function to run a linear regression on the imputed data, I get an error stating that the variables I am trying to analyze do not exit. Here is an example:

imputed_dataset <- mice(original_data, formulas = list_of_formulas, m = 5, maxit = 10)
model <- with(imputed_dataset, lm(my_outcome ~ some_imputed_predictor + other_predictor_that_was_not_imputed))

I can get the with() function to return a model if I only include predictors that have been imputed by Mice. I am not able to get the function to work if a variable that was not imputed is included in the formula. What should I do to be able to run my regression model, with some imputed predictors and some non-imputed predictors?

Htom
  • 21
  • 2

1 Answers1

1

The answer to this problem can be found in this thread. The formula needs to be wrapped like this

model <- with(imputed_dataset, formula(format(lm(my_outcome ~ my_regressors))))

Running mice with a formula as a variable: instant evaluation instead of later evaluation?

Htom
  • 21
  • 2