When using stargazer to create a LaTeX table on a logistic regression object the standard behaviour is to output logit-values of each model. Is it possible to get exp(logit) instead? That is, can i get the Odds-ratios instead?
In the stargazer documentation the following mentions the "Coef"-argument, but I dont understand if this can enable the exp(logits).
Coef: a list of numerical vectors that will replace the default coefficient values for each model. Element names will be used to match coefficients to individual covariates, and should therefore match covariate names. A NULL vector indicates that, for a given model, the default set of coefficients should be used. By contrast, an NA vector means that all of the model’s coefficients should be left blank.
The coefficient returned by a logistic regression in r is a logit, or the log of the odds. To convert logits to odds ratio, you can exponentiate it, as you've done above. To convert logits to probabilities, you can use the function exp(logit)/(1+exp(logit)) .
Since the ln (odds ratio) = log odds, elogodds = odds ratio. So to turn our -2.2513 above into an odds ratio, we calculate e-2.2513, which happens to be about 0.1053:1. So the probability we have a thief is 0.1053/1.1053 = 0.095, so 9.5 %.
For example, in logistic regression the odds ratio represents the constant effect of a predictor X, on the likelihood that one outcome will occur. The key phrase here is constant effect. In regression models, we often want a measure of the unique effect of each X on Y.
From probability to odds/odds ratio The odds of an event of interest occurring is defined by odds=p(1−p) where p is the probability of the event occurring. So if p=0.1, the odds are equal to 0.1/0.9=0.111 (recurring).
As per symbiotic comment in 2014, more recent versions of ''stargazer'' have the options ''apply.*'' for ''coef'' ''se'' ''t'' ''p'' and ''ci'' allowing the direct transformation of these statistics.
apply.coef a function that will be applied to the coefficients.
apply.se a function that will be applied to the standard errors.
apply.t a function that will be applied to the test statistics.
apply.p a function that will be applied to the p-values.
apply.ci a function that will be applied to the lower and upper bounds of the confidence intervals.
Meaning you can directly use...
stargazer(model,
apply.coef = exp,
apply.se = exp)
EDIT : I have noticed however that simply exponentiating the CIs does not give what you would expect.
EDIT : You can obtain the correct CIs using the method described here.
stargazer
allows you to substitute a lot of things, dependent variable labels, covariate labels and so forth. To substitute those you need to supply a vector of variable labels, this is done to have publishable row names, instead of variable names from R
by default.
So in order to have odds ratios, you need to supply a vector of odds ratios to stargazer
. How do you obtain that vector? Very easily, actually. Let's say that your model is called model
, then your code is:
coef.vector <- exp(model$coef)
stargazer(model,coef=list(coef.vector))
If you have multiple models in your table, then the list should be expanded, e.g. coef=list(coef.vector1,coef.vector2,...)
, where all vectors in the list would be derived from similar exponentiation as above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With