I would like to make a table in gtsummary with the variables listed in this order from top to bottom:
covars <- c("age", "stage", "grade", "marker", "response")
I ran this code but the table lists the variables in a different order (age, marker, stage, grade, response).
tbl_uvregression(
trial,
method=coxph,
y=Surv(ttdeath, death),
exponentiate = TRUE,
include = all_of(covars),
hide_n = TRUE,
add_estimate_to_reference_rows = TRUE) %>%
as_kable()
Characteristic | HR | 95% CI | p-value |
---|---|---|---|
Age | 1.01 | 0.99, 1.02 | 0.332 |
Marker Level (ng/mL) | 0.91 | 0.72, 1.15 | 0.435 |
T Stage | |||
T1 | 1.00 | Reference | |
T2 | 1.18 | 0.68, 2.04 | 0.560 |
T3 | 1.23 | 0.69, 2.20 | 0.476 |
T4 | 2.48 | 1.49, 4.14 | 4.7e-04 |
Grade | |||
I | 1.00 | Reference | |
II | 1.28 | 0.80, 2.05 | 0.305 |
III | 1.69 | 1.07, 2.66 | 0.024 |
Tumor Response | 0.50 | 0.31, 0.78 | 0.003 |
It seems that include
doesn't honor the variable ordering. You may have to select the data frame first before calling tbl_uvregression
:
covars <- c("age", "stage", "grade", "marker", "response")
select(trial, all_of(covars), ttdeath, death) %>%
tbl_uvregression(
method=coxph,
y=Surv(ttdeath, death),
exponentiate = TRUE,
# include = all_of(covars),
hide_n = TRUE,
add_estimate_to_reference_rows = TRUE)