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.

Generic ParametricUnivariate mixture cure model

See original GitHub issue

Would it be of interest to have a ParametricUnivariateFitter that adds a ‘cure’ component to a specified non-cure model? This could operate in a manner similar to the flexsurvreg R package - wrapping the functions of some baseline fitter. I suggest it because I’ve found such a thing useful in my own work, when selecting which underlying model to use.

Here is a quickly put together example of what I mean. If there is interest, I’d be willing to get into a better shape, with guidance.

class  MixtureCureModel(ParametricUnivariateFitter):
        def __init__(self, base_fitter, *args, **kwargs):
            self._base_fitter = base_fitter
            self._fitted_parameter_names = ["theta__"] + base_fitter._fitted_parameter_names
            self._bounds = [(0.0, 1.0)] + base_fitter._bounds
            super().__init__(*args, **kwargs)

        def _cumulative_hazard(self, params, times):
            theta__, lambda_, k_ = params
            sf = self._base_fitter._survival_function(params[1:], times)
            return -np.log(theta__ + (1 - theta__)*sf)


        def _create_initial_point(self, Ts, E, *args):
            self._base_fitter._censoring_type = self._censoring_type
            base_point = self._base_fitter._create_initial_point(Ts, E, *args)
            return np.array([.5] + list(base_point))

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bluemoocommented, Jan 23, 2020

Here are all the versions I’ve considered, with the assumption that long term you’ll want to parallel the capabilities of flexsurvcure, where they make sense. I think you’ve been trying to avoid having any mapping between string parameters and fitters, so there won’t be anything like dist=‘weibull’.

1. Class builder function: This would parallel the way that the sklearn_adapter function works. It takes a non-cure class and a few parameters, and returns a new class that the user then can instantiate.

def cure_model(base_fitter_klass: ParametricUnivariateFitter, link=expit, mixture=True) -> Type['MixtureCureFitter']:
        ...
        return new_klass

MixtureCureLogLogistic = cure_model(LogLogisticFitter, link=lambda x: exp(-exp(x)), mixture=True)
fitter = CureLogLogistic()

2. A Cure Model class with passed instance: A pair of MixtureCureModelFitter and NonMixtureCureModelFitter classes that take instances of a ParametricUnivariateFitter and are implemented in terms of that fitter. Changing things like the cure parameter link function can just be done via subclassing. This has the advantage of totally decoupling how the cure model portion and the base fitter are instantiated. I think it’s probably the easiest to implement approach, but that’s just a guess. It’s what I’ve actually used for my own work.

class  MixtureCureModelFitter(ParametricUnivariateFitter):
        def __init__(self, base_fitter, *args, **kwargs):
                self._base_fitter = base_fitter
                ...
                super().__init__(*args, **kwargs)

fitter = MixtureCureModelFitter(LogLogisticFitter())

3. A Cure Model Fitter class with passed class and arguments: A pair of MixtureCureModelFitter and NonMixtureCureModelFitter classes that have a parameter which takes a type that is a subclass of ParametricUnivariateFitter and any needed arguments. Then it instantiates the class itself as needed. I think this is probably a more awkward interface than the previous approach, but there is a lot of state stored in the fitters, and it would allow the Fitter to ‘reset’ the base_fitter if that becomes necessary.

class  MixtureCureModelFitter(ParametricUnivariateFitter):
        def __init__(self, base_fitter, *args, **kwargs):
                self._base_fitter = base_fitter
                ...
                super().__init__(*args, **kwargs)

fitter = MixtureCureModel(LogLogisticFitter())

4. Split apart fitters and equations: This is a more aggressive solution that involves a big refactoring of…everything. The portion of a class which represents the survival model equations could be separated from the actual mechanics of fitting the data. Then the equation for the non-cure portion could be wrapped in what I would expect is a straightforward way. I think this is closer to how the R packages do it, but I’m not sure that makes it correct.

0reactions
bluemoocommented, Feb 9, 2020

Actually, that by itself doesn’t work well. The allowed parameter bounds and default value should probably depend on the specific link function to use (or some kind of future smart default would need to have an inverse function). Maybe the way sklearn scorer specification works would be a reasonable model: allow either a string to use something predefined, or allow an object with a specific interface. Maybe something as simple as a namedtuple that gives the desired function, its inverse, and default bounds.

For reference, here’s the code for R/flexsurvcure (link functions are dealt with about halfway down): https://rdrr.io/cran/flexsurvcure/src/R/flexsurvcure.R

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parametric Cure Models
In a mixture cure model, these 'cured' and 'uncured' subjects are modeled separately, with the cured individuals subject to no excess risk and ......
Read more >
A General Approach for Cure Models in Survival Analysis
In this paper we propose a novel approach to estimate a mixture cure model when the data are subject to random right censoring....
Read more >
Efficient estimation for semiparametric cure models with ...
Ma [17], [18] studied a semiparametric mixture cure model based on the Cox model for current status data and mixed case interval-censored data,...
Read more >
Approximate Bayesian inference for mixture cure models - arXiv
This modeling strategy based on introducing covariate information through one of the parameters of the target distribution also applies to the ...
Read more >
npcure: An R Package for Nonparametric Inference in Mixture ...
The geecure package (Niu and Peng, 2018) features the marginal parametric and semiparametric PH mixture cure models for analyzing clustered survival data with...
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