I have a dataset and need to compare survival between Treatment A and Treatment B using survminer.
I want treatment A to be my reference, but R automatically assigns the reference as treatment B and gives me the HR the wrong way (for treatment B but I want it for treatment A)
Here is my example data:
library(survival)
library(survminer)
library(gt_summary)
id time event treatment
<chr> <dbl> <dbl> <chr>
1 NA 59.2 0 B
2 NA 14.0 1 B
3 NA 10.6 0 B
4 NA 2.79 1 B
5 NA 21.4 0 B
6 NA 1.84 0 A
7 NA 41.9 0 A
8 NA 5.59 0 A
9 NA 26.8 1 A
10 NA 6.81 0 A
df$treatment <- factor(df$treatment, levels=c("A", "B"))
os_chemo_io <- survfit(formula = Surv(time = time, type = 'right', event = event)~treatment, data = df)
coxph(Surv(time, event) ~ treatment, data=df) %>%
gtsummary::tbl_regression(exp=TRUE)