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

前端 未结 2 2024
你的背包
你的背包 2020-12-09 13:43

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

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 13:58

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

提交回复
热议问题