Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

survfit.coxph doesn't support Surv2-type data #264

Open
steliosbl opened this issue Jun 25, 2024 · 1 comment
Open

survfit.coxph doesn't support Surv2-type data #264

steliosbl opened this issue Jun 25, 2024 · 1 comment

Comments

@steliosbl
Copy link

steliosbl commented Jun 25, 2024

Hello,
I'm running into an error when trying to obtain survival curves from a CoxPH fitted using timeline-type data with a Surv2 formula.

Error in aeqSurv(Y) : argument is not a Surv object

Here is a barebones example, using the mgus data and the exact code from the vignette.

# Preparing the dataframe in timeline format
ctime <- with(mgus2, ifelse(pstat==1, ptime, futime))
cstat <- with(mgus2, ifelse(pstat==1, 1, 2*death))
cstat <- factor(cstat, 0:2, c("censor", "PCM", "death"))
tdata <- data.frame(id=mgus2$id, days=ctime, cstat=cstat)
mdata2 <- data.frame(mgus2[,1:7], days=0)
mdata2 <- merge(mdata2, tdata, all=TRUE)

# Fitting the cox model
cph <-  coxph(Surv2(days, cstat) ~ age + sex, id=id, mdata2)

# Attempting to obtain survival curves for two new records
ndata <- expand.grid(sex=c("F", "M"), age=c(60, 80))
survfit(cph, newdata=ndata) 
> Error in aeqSurv(Y) : argument is not a Surv object

I have traced the error inside survfit.coxph to the variable mf not taking the value it's supposed to take (survfit.coxph.R:83):

mf <- stats::model.frame(object)

When called with a coxph object that uses a Surv-type formula, mf is as expected. When the formula is a Surv2, however, it appears to return an empty frame, which then dominoes into the error I'm experiencing.

Am I making a mistake when calling survfit.coxph? Or does it currently not support Surv2?

Thank you

@therneau
Copy link
Owner

I have a few other things to do before I tackle this. Surv2 was an experimental idea which never worked out, at least in the sense of being useful to my own work, so I have not paid much attention to it. But I'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants