I am trying to combine the dependent variable columns for multiple cox hazard models in R/Stargazer. I know the interpretation is not appropriate, but this is merely for publication purposes. An example with mtcars.
library(stargazer)
data(mtcars)
outcomes <- c("vs", "am")
predictors <- c("gear", "carb")
futime <- mtcars$qsec
formulas <- expand.grid("Surv(futime,",outcomes,")"," ~ ",predictors," + ","hp", stringsAsFactors = FALSE)
formula.list <- as.character(interaction(formulas,sep=""))
coef.summary <- lapply(seq_along(formula.list),
function(x) coxph(as.formula(formula.list[x]),data=mtcars))
This creates 4 cox models in this example (2 dep outcomes x 2 indep predictors), but my models are larger of about 10 outcomes x 5 predictors. The output of formula.list:
> formula.list
"Surv(futime,vs) ~ gear + hp"
"Surv(futime,am) ~ gear + hp"
"Surv(futime,vs) ~ carb + hp"
"Surv(futime,am) ~ carb + hp"
The output I get in Stargazer
stargazer(coef.summary, omit=c("hp"),ci=TRUE,
digits = 2, omit.stat="all",
column.labels = c("vs", "am","vs","am"),
type="text")
===========================================================
Dependent variable:
-----------------------------------------------------
formula.list[x]
vs am vs am
(1) (2) (3) (4)
-----------------------------------------------------------
gear 1.47* 3.34***
(-0.02, 2.96) (1.36, 5.32)
carb 0.40 0.67**
(-0.27, 1.07) (0.14, 1.20)
===========================================================
===========================================================
Note: *p<0.1; **p<0.05; ***p<0.01
But the output I want is a condensed version by each dependent variable.
===========================================================
Dependent variable:
-----------------------------------------------------
formula.list[x]
vs am
(1) (2)
-----------------------------------------------------------
gear 1.47* 3.34***
(-0.02, 2.96) (1.36, 5.32)
carb 0.40 0.67**
(-0.27, 1.07) (0.14, 1.20)
===========================================================
===========================================================
Note: *p<0.1; **p<0.05; ***p<0.01
Again, I understand this is intentionally separated as these are entirely different models, but want this for summary/presentation purposes. I'm hoping this can be done without post-processing in html/Latex, but natively in the R/stargazer.