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.

Generalizing Parametric Regression models

See original GitHub issue

Design goals:

  1. Easy to add custom regression models, similar to how one can create custom univariate models.

  2. Arbitrary number of parameters to fit to. Example: an exponential AFT model has a single parameter, whereas Weibull AFT model has two, and a custom one could have N.

  3. Fixing parameters. I should be able to fix n < N parameters to set parameters.

  4. custom penalizers (this enables point 5 below) for users to allow some interesting parameter/information sharing.

  5. Stretch goal: make PiecewiseExponentialRegressionFitter less of a snowflake.

Point 2. and 3. allow the Exponential AFT fitter to be a special case of the the Weibull AFT fitter.

Prior workarounds or issues

See also #720 and this answer

Some thoughts:

  • I think I need to expel the idea of “primary” and “ancillary” for the general case, and make Known models reimplement those
  • PiecewiseExponentialRegressionFitter is currently a snowflake. One of the reasons was because it has an arbitrary number of parameters and a customer penalizer function. I might be able to fold that into this class.

Custom AFT API


class ShiftedWeibull(ParametericRegressionFitter):

    _fitted_parameter_names = ['lambda_', 'rho_', 'delta_']
    # no point in _bounds: assume they range over all floats, the user can change to positive only 
    # using the cumulative hazard and exp()

    def _cumulative_hazard(self, params, T, Xs):
        lambda_ = np.exp(np.dot(Xs["lambda_"], params["lambda_"])) # > 0
        rho_    = np.exp(np.dot(Xs["rho"],     params["rho_"]))    # > 0
        delta_  =        np.dot(Xs["delta_"],  params["delta_"])

        return ((T - delta_) / lambda_) ** rho_


    def _add_penalty(self, neg_ll, params):
        """ 
        only penalize the delta parameter, for whatever reason
        """
        penalty = params['delta_'] ** 2
        return neg_ll + self.penalizer * penalty



swf = ShiftedWeibull(penalizer=1.0)

covariates = {
  'lambda_': [variable names], # need a shortcut for all columns?
  'rho_':    [variable names], 
  'delta_':  [variable names] # (or fixed constant),
}

swf.fit_right_censoring(df, "T", "E", regressors=covariates) # TODO: name 

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
CamDavidsonPiloncommented, Apr 9, 2021

@helloannietran yes, you’re correct, that makes more sense for a parameter called “cure” - the interpretation is all relative though!

0reactions
helloannietrancommented, Apr 9, 2021

In the cumulative hazard func for CureModel, should it return -np.log(c + (1 - c) * sf) instead of -np.log((1 - c) + c * sf) if c is the cure rate? I’m new to survival analysis and currently experimenting with lifelines. Let me know if I should post this somewhere else…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parametric versus Semi/nonparametric Regression Models
Linear models, generalized linear models, and nonlinear models are examples of parametric regression models because we know the function ...
Read more >
Multiple and Generalized Nonparametric Regression in R
Multiple and generalized nonparametric regression models are powerful extensions of generalized linear models that can be used to estimate ...
Read more >
12.4 - Generalized Linear Models | STAT 462
(In fact, a more "generalized" framework for regression models is called general regression models, which includes any parametric regression model.) ...
Read more >
Testing Parametric Regression Specifications with ...
The typical parametric regression model is something like. Y = f (X;θ)+ ε ... model will actually generalize better than the non-parametric model2....
Read more >
Introduction to Nonparametric Regression Models - Coursera
The generalized linear models that we've just studied, the Poisson and the Binomial are also examples of parametric models because we ...
Read more >

github_iconTop Related Medium Post

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