首页 > 解决方案 > 从 texreg 回归表中删除 GOF 行

问题描述

如何从 texreg 表中删除 gof 行?在我的具体情况下,我想删除 R 2,Adj。R 2和 F 统计数据行。

我正在使用 texreg 版本 1.37.5 和 R 版本 4.1.1。除了标题和系数之外,我从 texreg 获得的默认表格行是 R 2,Adj。R 2,编号。obs. 和 RMSE。

这里的答案(R texreg: How can I select the gof statistics to be display?)在下面的代码中实现但不起作用。自发布此回复以来,该包裹可能在过去几年中发生了变化。

查看此处的 texreg 文档,在该omit.coef部分下,表明您可以使用删除 gof 行,extract但链接已损坏。

SSCCE:

library(estimatr)
library(texreg)

set.seed(42)
x1 <- rnorm(1000)
x2 <- rnorm(1000)
y <- 0.5*x1 + x2 + rnorm(1000)

mod1 <- lm_robust(y ~ x1)
mod2 <- lm_robust(y ~ x1 + x2)

texreg(list(mod1, mod2), 
       include.rsquared = F, 
       include.adjrs = F)

标签: rtexreg

解决方案


此答案基于texreg版本 1.37.5。

观察对象属于类lm_robust

> class(mod1)
## [1] "lm_robust"

您可以显示相应extract方法的帮助页面,如下所示:

?extract.lm_robust

## [..]
##
## extract.lm_robust(
##   model,
##   include.ci = TRUE,
##   include.rsquared = TRUE,
##   include.adjrs = TRUE,
##   include.nobs = TRUE,
##   include.fstatistic = FALSE,
##   include.rmse = TRUE,
##   include.nclusts = TRUE,
##   ...
##   )
##
## [...]

在您的示例中,您可以删除所有 GOF 行,如下所示:

screenreg(list(mod1, mod2),
  include.rsquared = FALSE,
  include.adjrs = FALSE,
  include.nobs = FALSE,
  include.rmse = FALSE)

## =========================================
##              Model 1        Model 2      
## -----------------------------------------
## (Intercept)   -0.01          -0.00       
##              [-0.10; 0.08]  [-0.07; 0.06]
## x1             0.49 *         0.48 *     
##              [ 0.40; 0.58]  [ 0.41; 0.54]
## x2                            0.98 *     
##                             [ 0.92; 1.05]
## =========================================
## * Null hypothesis value outside the confidence interval.

从 更改screenregtexreg以获得 LaTeX 输出。省略最后两个参数以仅删除 R 平方和调整后的 R 平方。默认情况下不报告 F 统计量。(也许您使用的是旧版本的texreg?)

要在不使用这些参数的情况下删除统计信息,您还可以将texreg对象保存到中间对象中并在将它们交给相应的表布局函数之前对其进行操作,如下例所示:

tr1 <- extract(mod1)
tr1@gof.names <- tr1@gof.names[-(1:2)]
tr1@gof.decimal <- tr1@gof.decimal[-(1:2)]
tr1@gof <- tr1@gof[-(1:2)]
screenreg(list(tr1, mod2))

## =========================================
##              Model 1        Model 2      
## -----------------------------------------
## (Intercept)   -0.01          -0.00      
##              [-0.10; 0.08]  [-0.07; 0.06]
## x1             0.49 *         0.48 *    
##              [ 0.40; 0.58]  [ 0.41; 0.54]
## x2                            0.98 *    
##                             [ 0.92; 1.05]
## -----------------------------------------
## Num. obs.    1000           1000         
## RMSE            1.41           1.03      
## R^2                            0.53      
## Adj. R^2                       0.53      
## =========================================
## * Null hypothesis value outside the confidence interval.

这需要更多的努力,但可以让您完全控制,并且如果您只想更改某些模型也适用。


推荐阅读