Search code examples
routputformulaglmsummary

R summary output not printing formula, but only its variable


I my R code, I have the folllowing:

input.formula = 'some_valid_formula'

glm.model <- glm(inp.formula,data=data, family='quasipoisson')

summary <- capture.output(summary(glm.model)) 

print(summary) 

The problem is that the summary prints:

Call: [INFO] - model coefficients: glm(formula = input.formula, family = \"quasipoisson\") ...

Note that the formula is printed as the formula variable name and not the formula itself. What am I missing here?


Solution

  • One option is to use do.call to construct and execute the glm call. This will return the evaluated glm call with the formula displayed. For example:

    data <- data.frame(group = gl(3,3), type = gl(3,1,9), counts = rpois(9, 2))
    input.formula = "counts ~ group + type"
    glm.model <- do.call("glm", list(input.formula, 'quasipoisson', data))
    summary(glm.model)