Reputation: 1023
I have been using the following function to output logistic regression tables with stargazer as odds ratio with the right significance stars and standard errors:
stargazer2 <- function(model, odd.ratio = F, ...) {
if(!("list" %in% class(model))) model <- list(model)
if (odd.ratio) {
coefOR2 <- lapply(model, function(x) exp(coef(x)))
seOR2 <- lapply(model, function(x) exp(coef(x)) * summary(x)$coef[, 2])
p2 <- lapply(model, function(x) summary(x)$coefficients[, 4])
stargazer(model, coef = coefOR2, se = seOR2, p = p2, ...)
} else {
stargazer(model, ...)
}
}
However, this no longer works when I'm using a hazards model analysis, and the significance stars move around in the output. Reproducible example below:
library(survival)
library(stargazer)
data("diabetic")
juvenile <- 1*(diabetic$age < 20)
fit <-coxph(Surv(time, status) ~ trt + juvenile, cluster= id,
data= diabetic)
stargazer2(fit, odd.ratio = T, type = "text")
stargazer2(fit, odd.ratio = F, type = "text")
Upvotes: 0
Views: 141
Reputation: 263301
The citation for that code brings up a blocked webpage. I don't think this line is correct:
seOR2 <- lapply(model, function(x) exp(coef(x)) * summary(x)$coef[, 2])
The reported effect measures are different. The "odd.ratio = T" version is reporting the exponentiated coefficient estimate while the "odd.ratio = F" version is displaying the unexponentiated version. Quite frankly the code you have copied is highly suspect for the line that calculates the seOR2 as well as the fact that it uses the sloppy and dangerous shortcut of T and F for logical values. The p-values for the ordinary stargazer call are correct while the new improved version is not. You might want to contact the author of that code to advise them to check their statistical logic.
Upvotes: 0
Reputation: 263301
The citation for that code brings up a blocked webpage. I don't think this line is correct:
seOR2 <- lapply(model, function(x) exp(coef(x)) * summary(x)$coef[, 2])
The reported effect measures are different. The "odd.ratio = T" version is reporting the exponentiated coefficient estimate while the "odd.ratio = F" version is displaying the unexponentiated version. Quite frankly the code you have copied is highly suspect for the line that calculates the seOR2 as well as the fact that it uses the sloppy and dangerous shortcut of T and F for logical values. The p-values for the ordinary stargazer call is correct while the new improved version is not.
Upvotes: 0