I'd like to extract the model call for a list of models. The list includes both glm and glmm.
It seems like this works for glm objects, but not for glmerMod objects
gm1 <- glm(cbind(incidence, size - incidence) ~ period,
data = cbpp, family = binomial)
gm1$call
>glm(formula = cbind(incidence, size - incidence) ~ period, family = binomial,
data = cbpp)
gm2 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
data = cbpp, family = binomial)
gm2$call
>Error in gm2$call : $ operator not defined for this S4 class
I can see when I click on the glmerMod objects in the rstudio environment pane that the object does appear to have a call value associated with it.
Is there a way I could extract this information from both types of models using the same function? This would be my preference becasue I'm hoping to set it up as an lapply function to apply to a list of models.
models <- list(gm1, gm2)
calls <- lapply(models, function(x) x$call)
You don't need summary()
at all.
getCall(lmm)
and getCall(lm)
both work. (If you dig into this you'll see that the default method for getCall
is just getElement(., "call")
; getElement
is a utility function that looks for an element as either a list element ($...
) or an S4 slot (@...
).)