Solution is to use
with(data=imp2, exp=glm((hyp==2)~bmi+chl, family=binomial , subset=(age==1) ))
(I think) the problem in your question is the use of ...
within the glm.mids
function. They are used in the function argument to allow “Additional parameters passed to glm”. However, when ...
are passed to the glm
call in the glm.mids
function they are not processed this way. In ?glm
the ...
are “For glm: arguments to be used to form the default control argument if it is not supplied directly.”. So the additional arguments will not work.
To see this, simplify the function
f1 <- function (formula, family = binomial, data, ...)
{
glm(formula, family = family, data = data, ...)
}
f1(formula=((hyp==2)~bmi+chl), data=nhanes, subset=(age==2))
#Error in eval(expr, envir, enclos) :
# ..1 used in an incorrect context, no ... to look in
So the subset argument is not passed to the glm
function call
Using the answer from R : Pass argument to glm inside an R function we can slightly alter the function
f2 <- function (formula, family = binomial, data, ...)
{
eval(substitute(glm(formula, family = family, data = data, ...)))
}
# This now runs
f2(formula=((hyp==2)~bmi+chl), data=nhanes, subset=(age==2))
# check
glm((hyp==2)~bmi+chl, data=nhanes, family="binomial", subset=(age==2))
The use of substitute
will substitute the arguments from the function environment (This needs more details - please feel free to update)