therneau / survival

Survival package for R
394 stars 106 forks source link

piecewise hazard model with multi-state outcome #282

Closed ecpolley closed 1 week ago

ecpolley commented 1 month ago

When attempting to estimate a piecewise hazard (time-varying coefficients) model with a multi-state outcome, an error message states "multi-state coxph does not support strata*covariate interactions" (example below). Is there a work-around or is this not implemented yet? Thanks! Eric

library(survival)
mgus2$etime <- with(mgus2, ifelse(pstat==0, futime, ptime))
event <- with(mgus2, ifelse(pstat==0, 2*death, 1))
mgus2$event <- factor(event, 0:2, labels=c("censor", "pcm", "death"))
mfit2 <- survfit(Surv(etime, event) ~ sex, data=mgus2)
mgus3 <- survSplit(Surv(etime, event) ~ sex, data= mgus2, cut=c(100, 200), episode= "tgroup", id="id")

fit <- coxph(Surv(tstart, etime, event) ~ sex*strata(tgroup), data = mgus3, id = id)
therneau commented 1 month ago

This was put in the code many months ago. The logic was “I haven’t written the test case for this yet. It should work, but I can’t be sure, so put in a temporary error message until I get to it in a couple of weeks….” I’ll try and look into this today. It completely slipped my mind.

Addenda: I just tried it (simply removed the error message) and your example works fine. For a data set where time restarts at 0 in the second strata, however, I need to make further changes as the code will complain about “overlapping time intervals for a subject” when it really should not do so.

Terry

From: Eric Polley @.> Date: Wednesday, September 25, 2024 at 9:59 AM To: therneau/survival @.> Cc: Subscribed @.***> Subject: [EXTERNAL] [therneau/survival] piecewise hazard model with multi-state outcome (Issue #282)

When attempting to estimate a piecewise hazard (time-varying coefficients) model with a multi-state outcome, an error message states "multi-state coxph does not support strata*covariate interactions" (example below). Is there a work-around or is this not implemented yet? Thanks! Eric

library(survival)

mgus2$etime <- with(mgus2, ifelse(pstat==0, futime, ptime))

event <- with(mgus2, ifelse(pstat==0, 2*death, 1))

mgus2$event <- factor(event, 0:2, labels=c("censor", "pcm", "death"))

mfit2 <- survfit(Surv(etime, event) ~ sex, data=mgus2)

mgus3 <- survSplit(Surv(etime, event) ~ sex, data= mgus2, cut=c(100, 200), episode= "tgroup", id="id")

fit <- coxph(Surv(tstart, etime, event) ~ sex*strata(tgroup), data = mgus3, id = id)

— Reply to this email directly, view it on GitHubhttps://github.com/therneau/survival/issues/282, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACJ3PGIW2BVEOHIG7B6BDL3ZYLFS5AVCNFSM6AAAAABO2X4ZX2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGU2DQMRUGIYDINI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

therneau commented 1 month ago

The github version has been updated to address this.

From: Eric Polley @.> Date: Wednesday, September 25, 2024 at 9:59 AM To: therneau/survival @.> Cc: Subscribed @.***> Subject: [EXTERNAL] [therneau/survival] piecewise hazard model with multi-state outcome (Issue #282)

When attempting to estimate a piecewise hazard (time-varying coefficients) model with a multi-state outcome, an error message states "multi-state coxph does not support strata*covariate interactions" (example below). Is there a work-around or is this not implemented yet? Thanks! Eric

library(survival)

mgus2$etime <- with(mgus2, ifelse(pstat==0, futime, ptime))

event <- with(mgus2, ifelse(pstat==0, 2*death, 1))

mgus2$event <- factor(event, 0:2, labels=c("censor", "pcm", "death"))

mfit2 <- survfit(Surv(etime, event) ~ sex, data=mgus2)

mgus3 <- survSplit(Surv(etime, event) ~ sex, data= mgus2, cut=c(100, 200), episode= "tgroup", id="id")

fit <- coxph(Surv(tstart, etime, event) ~ sex*strata(tgroup), data = mgus3, id = id)

— Reply to this email directly, view it on GitHubhttps://github.com/therneau/survival/issues/282, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACJ3PGIW2BVEOHIG7B6BDL3ZYLFS5AVCNFSM6AAAAABO2X4ZX2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGU2DQMRUGIYDINI. You are receiving this because you are subscribed to this thread.Message ID: @.***>