CamDavidsonPilon / lifelines

Survival analysis in Python
lifelines.readthedocs.org
MIT License
2.32k stars 551 forks source link

survival_table_from_events intervals outside of maximum causes error #1587

Closed swit22 closed 5 months ago

swit22 commented 6 months ago

When using collapse = True and intervals in lifelines.utils.survival_table_from_events, a 'Cannot convert non-finite values (NA or inf) to integer' ValueError is thrown when any of the intervals exceed the maximum time of the observations. This makes it difficult to use uniform intervals for multiple populations. I'm also seeing this error happen occasionally even when the intervals don't exceed the bounds of the observations. I'm aiming to use the survival_table_from_events to get a table with one row per year up to a set year, where values are zero beyond the maximum year of the population. Using lifelines version 0.27.7 from lifelines.datasets import load_waltons
from lifelines.utils import survival_table_from_events
import numpy as np waltons = load_waltons()
survival_table_from_events(waltons['T'], waltons['E'], collapse = True, intervals = np.arange(10,100).tolist())