- Join over
**1.5M+ people** - Join over
**100K+ communities** - Free
**without limits** - Create
**your own community**

For 1., hm, so strange. I am surprised that even reducing it to a single covariate still makes it fail. Is there a constant column in the dataframe?

If you have an individual, who has the 'death' event, but then becomes alive again, and then has a 'death' event again. How do you treat this? should you use a time based model, and record the death event something like this [t0 - t1, death] [t2 - t3, death], or do you not record the death event but still you a time based model, recording a gap in between the 'observations' [t0 - t1, t2-t3, death]

OR could you use a standard(non-temportal) model and treat them as separate individuals? What would the mathematical ramifications be to use a standard model like this?

@veggiet_gitlab this is called recurrent event analysis, and is a harder problem than survival analysis (obviously). You can still use some survival analysis tools though, but with some caution. One approach is to use coxph model with the "cluster" argument: https://lifelines.readthedocs.io/en/latest/Examples.html#correlations-between-subjects-in-a-cox-model

I'd like to introduce some interaction terms between ordinal variables into the lognormal AFT model, but after adding the interaction column, the algorithm now fails to converge. Is there a way to introduce interactions for categorical/ordinal variables without creating convergence issues?

@blissfulchar_twitter it sounds like the convergence issues might be due to sparse data. You could check the counts for each category to verify. If interaction terms are important, you could consider collapsing some of the ordinal categories together. For example, if you have 5 categories, you could make it 3 instead

@pzivich Thanks Paul! Looking into your sparsity suggestion I realized the DF with the interaction terms was not merging correctly with the main DF (it was dropping about 80% of the data). I fixed this issue and the model fits correctly now. Oops. Thanks for pointing me in the right direction :)

Hi @CamDavidsonPilon Question about custom fitters. I was looking at this documentation https://lifelines.readthedocs.io/en/latest/jupyter_notebooks/Piecewise%20Exponential%20Models%20and%20Creating%20Custom%20Models.html . Before I put any effort into experimenting, I was wondering if it would be possible to make one of the parameters an arbitrary list. Say for example, I wanted the date associated with each element of the

`times`

parameter. If this were possible, I think it might allow me to add seasonality to a competing risk model that captures the cumulative hazard of the outcome-of-interest. So I guess my question is two-fold. a) Is that possible with lifelines, b) Does that make sense for modeling competing risk.
Here is a crude sketch of what I'd like to do.

```
class SeasonalHazardFitter(ParametericUnivariateFitter):
"""
The idea of this class would be to fit custom seasonality to an
exponential-like hazard model.
"""
_fitted_parameter_names = ['a_q1_', 'a_q2_', 'a_q3_', 'a_q4_' 'dates']
def _cumulative_hazard(self, params, times):
# Pull out fiscal quarters and dates corresponding to times.
# Each element of the dates array corresponds an element of the
# times array.
a_q1_, a_q2_, a_q3_, a_q4_, dates = params
# Call a function that associates fiscal quarter with date
quarters = get_fiscal_quarters(dates)
# Get the hazard for each time
q_lookup = {1: a_q1_, 2: a_q2_, 3: a_q3_, 4:a_q4}
hazards = np.array([q_lookup[quarter] for quarter in quarters])
# Return the cumulative hazard
# You'd have to be more careful to actually do the
# integration properly, but you get the idea.
return np.cumsum(hazards)
```

@CamDavidsonPilon You are correct.

Is that right?

`dates`

are not an unknown. They are known constants. It makes sense that everything that goes into params should be unknown. Not sure what I was thinking there. Putting it in a global/class/instance variable makes sense. I just want to be sure I understand how `_cumulative_hazard()`

is called.`params`

: get tweaked by the optimization`times`

: the times passed into the fitter as "durations"`return`

: The cumulative hazard encountered over the duration represented by each timeIs that right?

The process I am trying to model consists of two competing kinds of events. The hazard for each event is a function of

`date`

. So the cumulative hazard for each time would be the integral of the hazard from the "start_date" to the "end_date". (where these can be derived from an element of `time`

and its corresponding date.) What I really care about is the cumulative incidence function (CIF) for each kind of event. If the idea of getting `dates`

into the `_cumulative_hazard`

function works, then I was hoping to use this technique to model the CIF for one of the competing event types.
Is this making sense?

Your explanation of `_cumulative_hazard`

is correct. But you can also see it as simply the cumulative hazard you wish to implement (i.e., not necessary to think about "durations" or "unknowns")

I was thinking about your seasonal model, and actually tried to code something up, but there is a problem I think. The `_cumulative_hazard`

is invoked for both the censored and uncensored data, so your code needs to handle that (and you won't know which until you see the shapes of the input data)

I'll think more about it. Try to write down the hazard mathematically - I think the problem is that it is clock-time dependent.

I love this interface you have for arbitrary models. If there was a way to hack that, it could be pretty useful.

Clock-dependent hazards I think are actually pretty common

Agree, but I feel like the common strategy is to use a regression model *or* fit N univariate models (i.e. partition the data)

I think a seasonal model is a great idea, so I want this to work.

:wave: new lifelines release: 0.22.0. Some important API changes to take a look at, but some really powerful new regression models: https://github.com/CamDavidsonPilon/lifelines/releases/tag/v0.22.0

lifelines has focused less on purely predictive models, and more on inference

Hi everyone, I'm trying to fit a model onto a recurrent process. I.E: Patient returns to a doctor. Is there a way to do so using lifelines ? So far the closest that I've got was this repo: https://github.com/dunan/MultiVariatePointProcess

Unfortunately

@CamDavidsonPilon Let me know if you have any suggestions for question below:

Hi, I am using CoxPHFitter with IPS weights and

`robust=True`

flag. However, the fit is taking really long time to finish. I have about million instances and 6 features in my dataset. Let me know if slower runtime is expected in weighted version and what can be done to speed it up.

:wave: minor version of lifelines released: https://github.com/CamDavidsonPilon/lifelines/releases/tag/v0.22.1

Hi all. I've somewhat new to using lifelines, and in using the CoxPHFitter, when I run `check_assumptions`

, I end up with an error that reads as follows: `/RuntimeWarning: overflow encountered in exp scores = weights * np.exp(np.dot(X, self.params_))`

Any suggestions on dealing with this issue? I'm starting down the road of normalization, but I'm not sure if that's 100% correct.

Hi! I am currently trying to create mixed cure models using the lifelines fitter. I saw that there is an example code in the GitHub under experiments. I was going to use this as a starting point and then adjust accordingly but I am getting an error when I run that code saying: "AttributeError: 'CureModel' object has no attribute '_primary_parameter_name'

I don't have a full understanding of the input arguments for _cumulative_hazard so I am not sure what is causing this error. Thank you!

I don't have a full understanding of the input arguments for _cumulative_hazard so I am not sure what is causing this error. Thank you!

If not, try upgrading. Otherwise, if you are still getting the error, can you post the entire stack trace?

in reference to the subclass my computer doesn't recognize ParametricRegressionFitter as an option but it does recognize ParametericRegressionFitter - perhaps also because of the version?