When you call a fitting functions, you can normally use ~.
as a shortcut to mean "include all other available variables on the right-hand side". See this question for some explanation, Meaning of ~. (tilde dot) argument?. But this only works when a data
argument is given to the function, otherwise the function won't know where it should find the other variables. It won't start searching your environment for anything that it thinks looks useful, which is a good thing.
To avoid this error, you should explicitly list the variables you want used. So, this will not work
library(mice)
imps <- mice(airquality, m = 5, predictorMatrix = quickpred(airquality)
mods <- with(imps, glm(Ozone ~ .))
#> Error in terms.formula(formula, data = data): '.' in formula and no 'data' argument
But changing to this will work
mods <- with(imps, glm(Ozone ~ Solar.R + Wind + Temp + Month + Day))
We can also use a trick where we set the data argument as data = data.frame(mget(ls()))
, to pull all the data out of the imputation into a dataframe and pass it to the fitting function. That will also work, so we could use
mods <- with(imps, glm(Ozone ~ ., data = data.frame(mget(ls()))))
I prefer to list the variables I want to use in the model. I think that makes it easier to read the code and follow what's going on.