I'm using texreg
to generate output tables of regressions. I'd like to include statistics such as AIC, BIC and HQIC as Goodness of Fit statistics.
Replicatible example below
library(texreg)
library(tidyverse)
mtcars
model1 <- lm(mpg ~ disp, data = mtcars)
model2 <- lm(mpg ~ disp + hp, data = mtcars)
screenreg(list(model1, model2))
Give me this:
=================================
Model 1 Model 2
---------------------------------
(Intercept) 29.60 *** 30.74 ***
(1.23) (1.33)
disp -0.04 *** -0.03 ***
(0.00) (0.01)
hp -0.02
(0.01)
---------------------------------
R^2 0.72 0.75
Adj. R^2 0.71 0.73
Num. obs. 32 32
RMSE 3.25 3.13
=================================
*** p < 0.001, ** p < 0.01, * p < 0.05
Which is great, but in addition to R^2, RMSE, etc, I'd also like AIC, BIC, and if possible HQIC.
Edit:
In answer to a comment below, it's true that the answer doesn't need to come from texreg
, but I am looking for an answer that produces the sort of formatted html tables that look ready for submission to academic journals, eg stargazer
, texreg
, sjPlot
.
AIC and BIC are based on the maximized log likelihood. The lm
function uses ordinary least squares and not maximum likelihood estimation. Hence there is no likelihood and no AIC or BIC. However, to get AIC and BIC, you can estimate the model using the glm
function and a Gaussian link function, in which case you get AIC and BIC by default:
library("texreg")
model1 <- glm(mpg ~ disp, data = mtcars, family = "gaussian")
model2 <- glm(mpg ~ disp + hp, data = mtcars, family = "gaussian")
screenreg(list(model1, model2))
Result:
======================================
Model 1 Model 2
--------------------------------------
(Intercept) 29.60 *** 30.74 ***
(1.23) (1.33)
disp -0.04 *** -0.03 ***
(0.00) (0.01)
hp -0.02
(0.01)
--------------------------------------
AIC 170.21 168.62
BIC 174.61 174.48
Log Likelihood -82.10 -80.31
Deviance 317.16 283.49
Num. obs. 32 32
======================================
*** p < 0.001; ** p < 0.01; * p < 0.05
You can get rid of the log likelihood, deviance etc. in the GOF block by using screenreg
arguments include.loglik = FALSE
, include.deviance = FALSE
etc.