MC808 - 1 year ago 132
R Question

# How do I add confidence intervals to odds ratios in stargazer table?

I am trying to create a table of a multivariable logistic regression model using

`stargazer`
. I would like to include odds ratios and their confidence intervals instead of the model coefficients.

I figured out how to replace the coefficients with the odds ratios, thanks to this link but doing the same with the CI creates problems. If I give
`stargazer`
an argument like
`se = *a list of the standard errors or exp(standard errors)*`
it calculates the CI using the OR +/- 1.96 times that list, which is incorrect.

Here's some sample code, first part from UCLA DAE:

``````library(stargazer)
mydata\$rank <- factor(mydata\$rank)
mylogit <- glm(admit ~ gre + gpa + rank, data = mydata, family = "binomial")
summary(mylogit)

# Table with coefficients
stargazer(mylogit, ci = T, single.row = T, type = "text")

# Table with Odds Ratios, but the CI is not right
OR.vector <- exp(mylogit\$coef)
stargazer(mylogit, coef = list(OR.vector), ci = T, single.row = T, type = "text")

# Correct CIs
CI.vector <- exp(confint(mylogit))
cbind(OR = OR.vector, CI.vector)
``````

You can use the `ci.custom` argument to feed `stargazer` a list with custom confidence intervals (first column is the lower bound, second column is the upper bound). In your example, all you have to do is call:

``````stargazer(mylogit, coef = list(OR.vector), ci = T,
ci.custom = list(CI.vector), single.row = T, type = "text")
``````

Alternatively, you can define your own function to exponentiate values and simply apply this function to your coefficients and/or confidence intervals (using arguments `apply.coef` and `apply.ci`):

``````exponentiate <- function(x) exp(x)

stargazer(mylogit, ci=T, apply.coef=exponentiate, apply.ci=exponentiate,
single.row = T, type="text")
``````
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download