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 int
Thank you to Marek for the assistance with this question. Here's the code that worked for me in this example:
library(stargazer)
mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
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")
OR.vector <- exp(mylogit$coef)
CI.vector <- exp(confint(mylogit))
p.values <- summary(mylogit)$coefficients[, 4]
# Table with ORs and CIs
stargazer(mylogit, coef = list(OR.vector), ci = T,
ci.custom = list(CI.vector), p = list(p.values),
single.row = T, type = "text")
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")