I have a glm model for which I use coeftest
from the lmtest
package to estimate robust standard errors. When I use stargazer to produce regression tables I get the correct results but without the number of observations and other relevant statistics like the null deviance and the model deviance.
Here's an example:
library(lmtest)
library(stargazer)
m1 <- glm(am ~ mpg + cyl + disp, mtcars, family = binomial)
# Simple binomial regression
# For whatever reason, let's say I want to use coeftest to estimate something
m <- coeftest(m1)
stargazer(m, type = "text", single.row = T) # This is fine, but I want to also include the number of observations
# the null deviance and the model deviance.
I'm specifically interested in the number of observations, the null deviance and the residual deviance.
I thought that If I replaced the old coefficient matrix with the new one, I'd get the correct estimates with the correct statistics and stargazer would recognize the model and print it correctly. For that, I've tried substituting the coefficients, SE's, z statistic and p values from the coeftest
model in the m1
model but some of these statistics are computed with summary.glm
and are not included in the m1
output. I could easily substitute these coefficients in the summary
output but stargazer doesn't recognize summary type class. I've tried adding attributes to the m
object with the specific statistics but they don't show up in the output and stargazer doesn't recognize it.
Note: I know stargazer can compute robust SE's but I'm also doing other computations, so the example needs to include the coeftest
output.
Any help is appreciated.
add.lines
option? Then you could use the coeftest object and add the other stats from the lm object:stargazer(m,type="text", single.row = T,add.lines = list(c("Observations",length(m1$data[,1])),c("Null Deviance" ,round(m1$null.deviance,3))))
– Cadency