0

So I am trying to display odds ratio in my texreg table:

library(texreg)

df <- mtcars

logit <- glm(
  formula = am ~ cyl,
  data = df,
  family = binomial(link = "logit")
)

odds_ratio <- exp(coef(logit))

screenreg(logit, odds_ratio)

This, unfortunately, produces the following error:

Error in screenreg(logit, odds_ratio) : 
  The 'file' argument must be a character string.

How to include odds ratio?

Isn't it correct that the regular model (as I have called logit above) displays log-odds/logarithm of the odds?

SnupSnurre
  • 363
  • 2
  • 12

1 Answers1

2

To replace log-odds by odds-ratios, you can do this:

library("texreg")
logit <- glm(formula = am ~ cyl,
             data = mtcars,
             family = binomial(link = "logit"))
screenreg(logit, override.coef = exp(coef(logit)))

The override.coef argument just replaces the coefficients by a vector you provide. There are similar arguments for standard errors, p-values etc., in case you need them.

The result:

=========================
                Model 1  
-------------------------
(Intercept)      43.71 * 
                 (1.55)  
cyl               0.50 **
                 (0.25)  
-------------------------
AIC              37.95   
BIC              40.88   
Log Likelihood  -16.98   
Deviance         33.95   
Num. obs.        32      
=========================
*** p < 0.001; ** p < 0.01; * p < 0.05

Note that the standard errors were not converted in the example above. It would not really make sense to convert them in the first place because they would need to be asymmetric. So you might as well drop them from the table. You can do this by saving the results into an intermediate texreg object, manipulating this object, and then handing it over to the screenreg function, as follows:

tr <- extract(logit)
tr@coef <- exp(tr@coef)
tr@se <- numeric()
screenreg(tr)

Result:

=========================
                Model 1  
-------------------------
(Intercept)      43.71 * 
cyl               0.50 **
-------------------------
AIC              37.95   
BIC              40.88   
Log Likelihood  -16.98   
Deviance         33.95   
Num. obs.        32      
=========================
*** p < 0.001; ** p < 0.01; * p < 0.05
Philip Leifeld
  • 2,253
  • 15
  • 24