derrynknife / SurPyval

A Python package for survival analysis. The most flexible survival analysis package available. SurPyval can work with arbitrary combinations of observed, censored, and truncated data. SurPyval can also fit distributions with 'offsets' with ease, for example the three parameter Weibull distribution.
https://surpyval.readthedocs.io/en/latest/index.html
MIT License
48 stars 5 forks source link

Left-censored data error #30

Closed lisandrojim closed 1 year ago

lisandrojim commented 2 years ago

Hello,

I am trying to make analysis using left-censored data using the non-parametric estimators Kaplan-Meier but I get the following error:

import numpy as np
import surpyval as surv
x = np.array([20,20,50,50,70])
c = np.array([-1,-1,-1,-1,-1])
km_surpyval = surv.KaplanMeier.fit(x=x,c=c)
km_surpyval.plot()

The error:

ValueError: xrd format can't be used with left (c=-1) or interval (c=2) censoring

What are the alternatives?

derrynknife commented 2 years ago

This is an issue, but it should raise a ValueError. This is because you shouldn't use only left censored data for estimation. You need at least one failure, or one right censored point with all the left censored data to get a reasonable result.

If you have more than just left censored data, you can use the Turnbull estimator:

turnbull_model = surv.Turnbull.fit(x=x, c=c)
derrynknife commented 1 year ago

You need at least two different failure types for a fit to work. So you'd need some observed (c=0) or right censored (c=1) with this data.

Otherwise the fitting method will just say that the failure occurred at -inf...