Search code examples
datatablestatisticsregressiongtsummarycox-regression

stratified cox model with gtSUMMARY


I am trying to create multiple univariate cox regression analyses using GTsummary. However, I need to add a stratification variable into the model and not sure how to go about this. Could any of you kindly help?

I would need to stratify my current working code by a variable "job_site"

#CURRENT CODE: 
uvlm_table <- tbl_uvregression(
  tbl1 %>%
    select(right_censor, n_result, age, exp_case, job_cat, n_facilities)
  type = list(
    age ~ "continuous"
  ),
  method = coxph,
  y = Surv(right_censor, n_result),
  exponentiate = TRUE,
  pvalue_fun = ~style_pvalue(.x, digits=3)
)

uvlm_table    

I tried to write the formula out manually but it did not work.


Solution

  • If you are looking to stratify by job site you can modify the formula input to incorporate this. I added job site as a strata below.

    library(survival)
    library(gtsummary)
    
    uvlm_table <- tbl_uvregression(
      tbl1 %>%
        select(right_censor, n_result, age, exp_case, job_cat, n_facilities, job_site),
      type = list(
        age ~ "continuous"
      ),
      method = coxph,
      y = Surv(right_censor, n_result),
      formula = "{y} ~ {x} + strata(job_site)",
      exponentiate = TRUE,
      pvalue_fun = ~style_pvalue(.x, digits=3)
    )
    

    Here is a reproducible example with the trial dataset from gtsummary.

    uvlm_table <- tbl_uvregression(
      trial %>%
        select(ttdeath, death, age,marker, grade),
      type = list(
        age ~ "continuous"
      ),
      method = coxph,
      y = Surv(ttdeath, death),
      formula = "{y} ~ {x} + strata(grade)",
      exponentiate = TRUE,
      pvalue_fun = ~style_pvalue(.x, digits=3)
    )