question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exponential AFT Fitter

See original GitHub issue

I used the WeibullAFTFitter to produce an ExpAFTFitter.

The code I’ve changed:

    def __init__(self, alpha=0.05, penalizer=0.0, l1_ratio=0.0, fit_intercept=True, model_ancillary=False):
        self._ancillary_parameter_name = "rho_"
        self._primary_parameter_name = "lambda_"
        super(ExpAFTFitter, self).__init__(alpha, penalizer, l1_ratio, fit_intercept, model_ancillary)

    def _cumulative_hazard(self, params, T, Xs):
        lambda_params = params["lambda_"]
        log_lambda_ = Xs["lambda_"] @ lambda_params

        return safe_exp(np.log(np.clip(T, 1e-25, np.inf)) + log_lambda_)

    def _log_hazard(self, params, T, Xs):
        lambda_params = params["lambda_"]
        log_lambda_ = Xs["lambda_"] @ lambda_params

        return log_lambda_

This produces numerically correct estimates, with wrong signs though.

However, it also produces some warnings and when printing the summary it spits out an error too. Obviously because of the rho. I tried to exclude rho, but then it started to whine about some _ancillary_parameter_name.

So, my suggestion is to include an ExpAFTFitter(). And why wouldn’t there be a single AFT function which would take the distribution as an argument?

For instance:

from lifelines import AFTFitter
aft = AFTFitter()
aft.fit(rossi_dataset, duration_col='week', event_col='arrest', distribution='Weibull')

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
CamDavidsonPiloncommented, Aug 27, 2019

To do the Exponential AFT model, try something like: https://lifelines.readthedocs.io/en/latest/jupyter_notebooks/Custom Regression Models.html

That is the preferred way to extend AFT models.

The latter model, AFTFitter might be included in a future release (it’s something I’ve thought about), but it bucks the trend of models being equal to classes.

0reactions
sursucommented, Aug 27, 2019

Yes, coefficients are identical in all 3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WeibullAFTFitter — lifelines 0.27.4 documentation
Bases: lifelines.fitters.ParametericAFTRegressionFitter , lifelines.fitters.mixins.ProportionalHazardMixin. This class implements a Weibull AFT model.
Read more >
Accelerated Failure Time Models
Meaning of AFT models ... discuss estimation and model fitting, and go through an ... For a random time-to-event T, an accelerated failure...
Read more >
Accelerated failure time model
In the statistical area of survival analysis, an accelerated failure time model (AFT model) is a parametric model that provides an alternative to...
Read more >
Chapter 16 Survival Analysis
For Weibull and Exponential regression, instead of fitting a PH model, R and SAS fit an accelerated failure time model log(Yi) = α+βT....
Read more >
Parametric survival models
3 Proportional hazards or AFT model? ... eha and the function survreg in the package survival that perform the task of fitting AFT...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found