【问题标题】:Use `texreg` to display AIC, BIC gof stats使用 `texreg` 显示 AIC、BIC gof stats
【发布时间】:2019-09-10 07:00:07
【问题描述】:

我正在使用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 表格,例如stargazertexregsjPlot

【问题讨论】:

  • 必须是texreg吗?如果没有,您可以尝试 broom 封装并使用函数 tidy 用于系数,glance 用于 R2、AIC 和 BIC 等...

标签: r stargazer sjplot texreg


【解决方案1】:

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 = FALSEinclude.deviance = FALSE 等来消除 GOF 块中的对数可能性、偏差等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 1970-01-01
    • 2015-11-24
    • 2018-02-09
    • 2016-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多