0

I'm encountering a problem similar to Survival not recognizing right censored data but the suggested fix isn't working. I've confirmed that the censoring variable is numeric and I'm not encountering any problems when using coxph function. I only get the error when trying to visualize the p-value from Kaplan-Meier survfit function. Dataset is a standardized entry date, with weekly intervals to accompany a time-varying covariate used later in my cox models, dataset shown here https://drive.google.com/file/d/14nj8L-HatqqjbLZSzNLw1T-U9wFDlsCi/view?usp=sharing

library(readr)
library(survival)
library(survminer)
NOBO_surv_com <- read.csv("WSIdf.csv")



#Create censoring variable (right censoring)

NOBO_surv_com$censored[NOBO_surv_com$Death == 1] <- 1
NOBO_surv_com$censored[NOBO_surv_com$Death == 0 | NOBO_surv_com$Death == 2] <- 0
NOBO_surv_com$censored <- as.numeric(NOBO_surv_com$censored)

#Specify K-M Analysis model with categorical covariate (Year and Sex)
km_fit_Yr <- survfit(Surv(tstart, tstop, censored) ~ Yr,
                  data=NOBO_surv_com,
                  type="kaplan-meier")
print(km_fit_Yr)
surv_pvalue(km_fit_Yr, data = NOBO_surv_com)

1 Answers1

0

The error is not coming from any functions in pkg:survival but rather from surv_pvalue which is part of pkg:survminer.

Furthermore the type argument has been deprecated for surv.fit, although the call to surv.fit succeeded and changing the arguments to what is now recommended did not change anything. I don't think a median value can make sense with time-varying data.

But why do you have it arranged as time varying data, anyway? You don't have any covariates that are associated with the start-stop times, do you? There are only two values for the single covariate. For this step in the analysis you should concatenate the time intervals.

Your situation has been reported in the proper location as of 2017. In the succeeding 5 years it remains an open and apparently unresolved "issue". See the GitHub issues page: https://github.com/kassambara/survminer/issues/311

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • I have it arranged for time varying covariates for when I run my cox models because I have a time varying continuous variable that I use in them (It is a winter severity index). I'm trying to run KM this way so that I can show the differences in baseline KM survival estimates between Sexes of Individuals and between the 2 years of the study and show that the non-significant p-values justify leaving these variables out of the cox models. – Blake Baum Feb 28 '23 at 15:13
  • So a p-value for that model is not what is needed. You need to do a model comparison using the standard tools available in pkg:survival. That will give you a p-value for the difference in fit between the base model that you just built and the seasonal model you anticipate. Using p-value to decide which variable should be in models is poor practice. – IRTFM Feb 28 '23 at 18:39