lifelines icon indicating copy to clipboard operation
lifelines copied to clipboard

Error in using CoxTimeVaryingFitter due to NaN in base-df

Open Asieh-A-Mofrad opened this issue 2 years ago • 0 comments

Discussed in https://github.com/CamDavidsonPilon/lifelines/discussions/1435

Originally posted by Asieh-A-Mofrad July 8, 2022 Hi,

I'm new to survival analysis and the lifelines library. I'm using Cox’s time varying proportional hazard model and trying to use the CoxTimeVaryingFitter. My data has several time-varying covariates and is in the event-based type (i.e. NaN represents if an event is not happening).

When I create the dataset based on the lifelines guideline using lifelines.utils.covariates_from_event_matrix(), The final dataset has NaN in the first period of each event. It is in line with the example in the guideline:

   start   E1  var1  stop  id  event
0    0.0  NaN   0.1   1.0   1  False
1    1.0  1.0   0.1  10.0   1   True
2    0.0  NaN   0.5  12.0   2   True

But when I use this dataset as the input to the fit, I got the error: NaNs were detected in the dataset. Try using pd.isnull to find the problematic values.

PS. If I remove the rows with NaNs, the fitter works, but in this case, I miss some data, similar to the data for id=2 in the example, and none of the time periods starts at time 0.

Thanks in advance, Asieh

Asieh-A-Mofrad avatar Jul 09 '22 10:07 Asieh-A-Mofrad