harrelfe / rms

Regression Modeling Strategies
https://hbiostat.org/R/rms
Other
172 stars 48 forks source link

How to include time-vary covariates using tt=function from coxph in rcs code? #135

Open PaulaStuermer opened 11 months ago

PaulaStuermer commented 11 months ago

I´d like to use RCS to test for non-linearity after testing for linearity using coxph. I have a variable that does not meet the proportional hazard assumption ("t4_examination_age_F1"). In the coxph statment I can include a time transform function to account for this. The code is as follows:

cox_dash_std_3 <- coxph(Surv(time = all$survival_time, event = all$mortality_status) ~ dash_res_kon_std + sex_F1 + t4_examination_age_F1 + t277_BMI_F1 + whr + PA_Mets + smoke + education + Gkcal_F1 + tt(t4_examination_age_F1), data = all,
                              tt=function(t4_examination_age_F1, survival_time, ...) t4_examination_age_F1 * log(survival_time))

Now I´d like to use rcsplot. But how do I include the time transform function in this code?

rcsplot(data=all,
        outcome = "mortality_status",
        time = "survival_time",
        exposure = "dash_res_kon_std",
        covariates = c("t4_examination_age_F1", "sex_F1", "t277_BMI_F1", "whr", "PA_Mets", "smoke_2", "smoke_3", "education_2", "education_3", "Gkcal_F1"),
        knots = c(0.05, 0.35, 0.65, 0.95),
        ref.value = 5.22)

I tried using the same trick as in coxph, but this does not work:

rcsplot(data=all,
        outcome = "mortality_status",
        time = "survival_time",
        exposure = "dash_res_kon_std",
        covariates = c("t4_examination_age_F1", "sex_F1", "t277_BMI_F1", "whr", "PA_Mets", "smoke_2", "smoke_3", "education_2", "education_3", "Gkcal_F1", "tt(t4_examination_age_F1)"),
        tt=function(t4_examination_age_F1, survival_time, ...) t4_examination_age_F1 * log(survival_time),
        knots = c(0.05, 0.35, 0.65, 0.95),
        ref.value = 5.22)

I get this error: tt(t4_examination_age_F1) are (is) not included in the data frame.

I would be very grateful for any kind of help of how to account for the proportional hazard assumption violation of my variable in rcsplot. Thank you!