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)
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.