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

summary.survfit(*, data.frame = TRUE) causes error with multi-state data #305

Open
steliosbl opened this issue Feb 28, 2025 · 0 comments
Open

Comments

@steliosbl
Copy link

steliosbl commented Feb 28, 2025

Hello,
I am encountering an error when trying to run summary.survfit() on a survfit.coxphms object with data.frame = TRUE. The error is always of the form:

 > Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: .......

This error is thrown upon the execution of this line:

ndata <- data.frame(ndata)

MVE on mgus2:

# Prepare the mgus2 dataset.
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"))

# Fit Cox PH model 
msfit <- coxph(
    Surv(etime, event) ~ age + sex,
    data = mgus2, id = id
)

# The following ndata causes an error
ndata <- mgus2[1:2, c("age", "sex")]
sf <- survfit(msfit, ndata)
summary(sf, data.frame = TRUE)
# > Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
#  arguments imply differing number of rows: 1284, 1926

Investigating further, the error occurs whenever the number of rows in ndata is not a multiple of 3.
The example below tries ndata lengths from 1-30 and returns the ones that did not cause the error.

working_nrow <- unlist(lapply(1:30, function(i) {
    tryCatch({
            ndata <- mgus2[1:i, c("age", "sex")]
            sf <- survfit(msfit, ndata)
            summary(sf, data.frame = TRUE)
            return(i)
        }, error = function(e) NULL 
    )
}))
working_nrow
>  1  3  6  9 12 15 18 21 24 27 30 

Thank you for your help.

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

1 participant