我使用texreg生成回归的输出表。我想将AIC、BIC和HQIC等统计数据作为拟合优度统计数据。
下面是可复制的示例
library(texreg)
library(tidyverse)
mtcars
model1 <- lm(mpg ~ disp, data = mtcars)
model2 <- lm(mpg ~ disp + hp, data = mtcars)
screenreg(list(model1, model2))给我这个:
=================================
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这很好,但除了R^2,RMSE等,我还想要AIC,BIC,如果可能的话,还有HQIC。
编辑:
在回答下面的一条评论时,答案确实不需要来自texreg,但我正在寻找一个答案,它可以产生一种格式化的html表格,看起来可以提交给学术期刊,例如stargazer,texreg,sjPlot。
发布于 2020-04-24 01:54:37
AIC和BIC基于最大化的对数似然。lm函数使用普通的最小二乘,而不是最大似然估计。因此,没有可能性,也没有AIC或BIC。但是,为了得到AIC和BIC,您可以使用glm函数和高斯链接函数来估计模型,在这种情况下,默认情况下会得到AIC和BIC:
library("texreg")
model1 <- glm(mpg ~ disp, data = mtcars, family = "gaussian")
model2 <- glm(mpg ~ disp + hp, data = mtcars, family = "gaussian")
screenreg(list(model1, model2))结果:
======================================
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您可以通过使用screenreg参数include.loglik = FALSE、include.deviance = FALSE等来消除GOF块中的对数似然、偏差等。
https://stackoverflow.com/questions/57865558
复制相似问题