1

How can you remove gof rows from a texreg table? In my specific case, I'd like to remove the R2, Adj. R2, and F statistic rows.

I'm using texreg version 1.37.5 and R version 4.1.1. The default table rows I get from texreg in addition to headings and coefficients are R2, Adj. R2, Num. obs., and RMSE.

The answer here (R texreg: How can I select the gof statistics to be displayed?) is implemented in the code below but does not work. Possibly the package changed in the last few years since this response was posted.

A look at the texreg documentation here, under the omit.coef section, indicates that you can remove gof rows using extract but the link is broken.

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 = FALSE, 
       include.adjrs = FALSE)
Matifou
  • 7,968
  • 3
  • 47
  • 52
Dr. Beeblebrox
  • 838
  • 2
  • 13
  • 30

1 Answers1

2

This answer is based on texreg version 1.37.5.

Observe that the objects are of class lm_robust:

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

You can display the help page for the corresponding extract method as follows:

?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,
##   ...
##   )
##
## [...]

In your example, you can get rid of all GOF rows as follows:

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.

Change from screenreg to texreg to get LaTeX output. Leave out the last two arguments to get rid of only R-squared and adjusted R-squared. The F-statistic is not reported by default. (Perhaps you used an old version of texreg?)

To remove statistics without using those arguments, you can also save texreg objects into intermediate objects and manipulate them before you hand them over to the respective table layout function, like in the following example:

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.

This requires a bit more effort but gives you full control and is applicable also if you want to change only some of the models.

Philip Leifeld
  • 2,253
  • 15
  • 24
  • From sessionInfo(): I'm using texreg version 1.37.5. R version 4.1.1 (2021-08-10). Platform: x86_64-apple-darwin17.0 (64-bit). Running under: macOS Big Sur 11.3.1. The code at the bottom of your answer using extract(mod1) works, thank you! Oddly, the code above using include.rsquared=F etc. did not work, but after restarting Rstudio it does. I'll play around a bit more and see if I can recreate the previous odd behavior. Possibly it was an unexpected package interaction? – Dr. Beeblebrox Sep 01 '21 at 19:55
  • 1
    I would advise against abbreviating `TRUE` with `T` and `FALSE` with `F` because it is easy to overwrite `T` and `F` with other values. Could this be the reason? Just guessing. – Philip Leifeld Sep 01 '21 at 21:23
  • I tried `?extract.lm_robust` but I get `No documentation for ‘extract.lm_robust’`? Thanks! – Matifou Jan 19 '23 at 10:10
  • I think the `extract` method for `lm_robust` objects is defined in the `estimatr` package. You need to load this package to have access to the help page. The `estimatr` package enhances the `texreg` package by providing an `extract` method for their `lm_robust` class. – Philip Leifeld Jan 19 '23 at 15:18