cox-regressionhuxtable

Exponentiate regression results in huxtable


I'm putting together some tables with results from a series of Cox Proportional Hazards Models. I'd like to exponentiate the coefficients so the tables display the Hazard Ratios rather than the raw beta values. Does anyone know of a way to do this with huxtable? It's my preferred package for building regression tables. I've done some googling and can't find a solution.


Solution

  • You can use the tidy_args argument to huxreg:

    library(huxtable)
    library(survival)
    
    test1 <- list(time=c(4,3,1,1,2,2,3), 
                  status=c(1,1,1,0,1,1,0), 
                  x=c(0,2,1,1,1,0,0), 
                  sex=c(0,0,0,0,1,1,1)) 
    mod <- coxph(Surv(time, status) ~ x + strata(sex), test1) 
    
    huxreg(mod)
                               ─────────────────────────────────────────────────
                                                                  (1)           
                                                       ─────────────────────────
                                 x                                      0.802   
                                                                       (0.822)  
                                                       ─────────────────────────
                                 N                                      5.000   
                                 R2                                     0.144   
                                 logLik                                -3.328   
                                 AIC                                    8.655   
                               ─────────────────────────────────────────────────
                                 *** p < 0.001; ** p < 0.01; * p < 0.05.        
    
    Column names: names, model1
    
    huxreg(mod, tidy_args = list(exponentiate = TRUE))
                               ─────────────────────────────────────────────────
                                                                  (1)           
                                                       ─────────────────────────
                                 x                                      2.231   
                                                                       (0.822)  
                                                       ─────────────────────────
                                 N                                      5.000   
                                 R2                                     0.144   
                                 logLik                                -3.328   
                                 AIC                                    8.655   
                               ─────────────────────────────────────────────────
                                 *** p < 0.001; ** p < 0.01; * p < 0.05.        
    
    Column names: names, model1
    

    tidy(mod, exponentiate = TRUE) appears to exponentiate the coefficients but not the standard errors, which is presumably a bug in broom and worth reporting? Confidence intervals appear correct, though, so you can do:

    huxreg(mod, tidy_args = list(exponentiate = TRUE), 
           error_format = "[{conf.low}-{conf.high}]", ci_level = 0.95)
                               ─────────────────────────────────────────────────
                                                                  (1)           
                                                       ─────────────────────────
                                 x                                      2.231   
                                                                [0.445-11.180]  
                                                       ─────────────────────────
                                 N                                      5.000   
                                 R2                                     0.144   
                                 logLik                                -3.328   
                                 AIC                                    8.655   
                               ─────────────────────────────────────────────────
                                 *** p < 0.001; ** p < 0.01; * p < 0.05.        
    
    Column names: names, model1