0

I am getting an error running the line summary(glm.object)

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ‘"summary.glm"’ to a data.frame

For example, the following code gives the error.

norms <- rnorm(100)
data <- data.frame("var1" = norms,
                   "var2" = 2*norms + 0.3*rnorm(100),
                   "var3" = rbinom(n=100,size=1,prob=0.4))
eta <- 3 + data$var1 + 0.4*data$var2 - 1.8*data$var3
data$outcome <- rbinom(n=100,size=1,prob=exp(eta)/(1+exp(eta)))
glm1 <- glm(outcome ~ var1 + var2 + var2*var1, family = binomial, weights = 3-var3, data = data)
summary(glm1)

I've never had this in the past and can't see what the issue is - I've tried running this with various different glms. If I run the line glm1 it outputs the glm results normally as it should - the glm seems to have run correctly. I've tried detaching all loaded packages to see if that helps but it did not.

I later found summary.glm(glm1) works. However I thought it was possible to pass glm objects into summary, and have seen others suggest it online. Why doesn't summary(glm1) work?

Dan Phillips
  • 132
  • 7
  • I don't get any errors with the code snippet you've provided. `summary(glm1)` provides expected output. Are you running this in R console or Rstudio? Have you tried from a fresh session (ctrl/cmd + shift + F10)? – Phil Aug 27 '21 at 15:38
  • Thanks - I tried that and also didn't get any errors. That's strange, I don't know what was causing them before. – Dan Phillips Aug 31 '21 at 08:14

0 Answers0