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

Improve error message when user passes survfit.coxphms model #222

Open
steliosbl opened this issue Sep 17, 2024 · 1 comment
Open

Improve error message when user passes survfit.coxphms model #222

steliosbl opened this issue Sep 17, 2024 · 1 comment

Comments

@steliosbl
Copy link

Hello,
I am attempting to plot "probability in state" curves from a multi-state object created with survfit2() from a Cox proportional hazards model. Unfortunately, when calling ggcuminc, I encounter the following error:

Error in data.frame(time = x$time, n.risk = c(x$n.risk), n.event = c(x$n.event),  : 
 arguments imply differing number of rows: 286, 858, 3432, 0

This error occurs when following the standard steps for fitting a multi-state Cox model per the survival package's multi-state vignette. I have written a minimal, reproducible example of the error below following the vignette's steps with a stock dataset.

library(survival)
library(ggsurvfit)

data(cancer, package="survival")

# First, we prepare the multi-state dataset.
# This code is copied directly from the survival package's multi-state vignette, section 2.2
ptemp <- with(mgus2, ifelse(ptime==futime & pstat==1, ptime-.1, ptime))
data3 <- tmerge(mgus2, mgus2,  id=id, death=event(futime, death),
                pcm = event(ptemp, pstat))
data3 <- tmerge(data3, data3, id, enum=cumtdc(tstart))
temp <- with(data3, ifelse(death==1, 2, pcm))
data3$event <- factor(temp, 0:2, labels=c("censor", "pcm", "death"))

# Finally, we fit the Cox PH model and run survfit2
msfit <- coxph(Surv(tstart, tstop, event) ~ sex + age, data=data3, id=id)
ndata <- expand.grid(sex=c("F", "M"), age=c(60, 80))
mssurv <- survfit2(msfit, newdata=ndata, p0=c(1,0,0))

# Run ggcuminc
ggcuminc(mssurv, outcome=c("censor", "pcm", "death"))

> Error in data.frame(time = x$time, n.risk = c(x$n.risk), n.event = c(x$n.event),  : 
  arguments imply differing number of rows: 286, 858, 3432, 0

Does ggcuminc support survfit.coxphms objects, i.e. survfit objects generated from a multi-state Cox model? Or am I making a mistake when using it?

Thank you for your assistance.

@steliosbl steliosbl changed the title ggcuminc() failing for multi-state Cox models Bug Report: ggcuminc() failing for multi-state Cox models Sep 17, 2024
@ddsjoberg
Copy link
Collaborator

Dear @steliosbl , thanks for the post.

The package doesn't support visualizations from the regression models. But we can certainly improve the error message in this setting.

@ddsjoberg ddsjoberg changed the title Bug Report: ggcuminc() failing for multi-state Cox models Improve error message when user passes survfit.coxphms model Sep 17, 2024
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