Reputation: 11
I have a dataset that have samples with / without treatment and their ages at death and gender. All the samples are dead. I want to test if the treatment affects the survival.
The dataset df looks like below
FID gender age_at_death treatment event
1 101 female 46 Y 1
2 102 female 65 Y 1
3 103 male 73 Y 1
4 104 male 74 N 1
5 105 female 56 N 1
6 106 male 57 N 1
Below is my code to test if the treatment affects survival:
library(survminer)
surv_obj <- Surv(time=df$age_at_death, event=df$event)
fit <- survfit(surv_obj ~treatment, data=df)
ggsurvplot(fit, data = df, pval = TRUE, title = "test" )
But gender is quite an important co variant (females usually live longer than males), therefore I want to adjust for gender. But the below code give me 4 survival curves. What I want is two curves (treated vs non-treat) adjusted for gender.
fit1 <- survfit(surv_obj ~treatment + gender, data=df)
ggsurvplot(fit, data = df, pval = TRUE, title = "test" )
fit2 <- coxph( Surv(time=df$age_at_death, event=df$event) ~ treatment, data = df )
ggadjustedcurves(fit2, data = df)
This only give one curve.
fit3 <- coxph( Surv(time=df$age_at_death, event=df$event) ~ treatment +strata(gender), data = df )
ggadjustedcurves(fit3, data = df)
This gives twos curve, male vs female.
The figure I want is similar to this example:
"after adjustment for age, sex, race, diseases suspected to influence B27 testing and mortality". They adjusted for quite a few covariants and have an adjusted survival plot for B27+ and B27- (mine is treated vs non-treated).
Any help will be appreciated!!!
Upvotes: 1
Views: 739
Reputation: 355
I would suggest taking a look at the adjustedCurves
package: https://github.com/RobinDenz1/adjustedCurves
It offers a variety of ways to adjust survival curves for confounders. The literature references given in the documentation of that package can also be used to get a good understanding of what exactly confounder-adjustment means in this context and how it is performed.
Upvotes: 0