0

I use ggsurvplot to generate survival plots and encountered problems when my Surv fit function includes multiple censored data.

This is the data link: testdata

my fit function and my ggsurvplot function:

library(survival)
library(survminer)
cnsr_values <- c(1,2)
fit <- surv_fit(Surv(AVAL, !CNSR %in% cnsr_values) ~ TRTKEY, data = testdata)

myplot <- ggsurvplot(fit,data = testdata,conf.int = FALSE)

When the cnsr_values only have one numeric number, for example 1, then it works; when the cnsr_values have two numeric number, for example cnsr_values = c(1, 2), then it returns error: Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 1169, 2;

But if I put c(1,2) in the fit function as

fit <- surv_fit(Surv(AVAL, !CNSR %in% c(1,2) ~ TRTKEY, data = testdata) 

then it also works.

I have compared the two fit functions, cannot find any differences, and the data sets in the ggsurvplot are also the same.

However, there must be some where makes it return the error.

I also tried to use testdata[1:1168,]in the ggsurvplot, it works.

Can anyone please help?

  • 1
    Can you make your post [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and provide your data using `dput()`? – jrcalabrese Feb 15 '23 at 22:15
  • I tested that only use the whole data could reproduce the error message, then I shared the data through the link. – Elin Zhang Feb 16 '23 at 18:10

0 Answers0