You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
steliosbl
changed the title
ggcuminc() failing for multi-state Cox models
Bug Report: ggcuminc() failing for multi-state Cox models
Sep 17, 2024
The package doesn't support visualizations from the regression models. But we can certainly improve the error message in this setting.
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
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 callingggcuminc
, I encounter the following error: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.
Does
ggcuminc
supportsurvfit.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.
The text was updated successfully, but these errors were encountered: