- class surpyval.univariate.parametric.mixture_model.MixtureModel(dist, m=2)
Bases:
DistributionA class for creating a Mixture Model fitter.
This class implements a Mixture Model, which is a probabilistic model that combines multiple probability distributions to model complex data. Models can be fit with either the Expectation Maximisation (EM) algorithm or Maximum Likelihood Estimation (MLE). The EM algorithm is the default and is based on the paper found here.
- Parameters
dist (surpyval distribution) – The distribution to be used in the mixture model. Must be a surpyval distribution.
m (int, optional) – The number of sub-distributions to be used in the mixture model. Defaults to 2.
- cs(x, X)
The conditional survival function of the fitted model.
- Parameters
x (array like) – The values at which the conditional survival function will be evaluated.
X (array like) – The values at which the item is known to have survived to.
- Returns
The conditional survival function evaluated at x given X.
- Return type
array like
- df(x)
The probability density function of the fitted model.
- Parameters
x (array like) – The values at which the probability density function will be evaluated.
- Returns
The probability density function evaluated at x.
- Return type
array like
- ff(x)
The cumulative density function of the fitted model.
- Parameters
x (array like) – The values at which the cumulative density function will be evaluated.
- Returns
The cumulative density function evaluated at x.
- Return type
array like
- fit(x=None, c=None, n=None, t=None, tl=None, tr=None, xl=None, xr=None)
- Parameters
x (array like, optional) – Array of observations of the random variables. If x is
None, xl and xr must be provided.c (array like, optional) – Array of censoring flag. -1 is left censored, 0 is observed, 1 is right censored, and 2 is intervally censored. If not provided will assume all values are observed.
n (array like, optional) – Array of counts for each x. If data is provided as counts, then this can be provided. If
Nonewill assume each observation is 1.t (2D-array like, optional) – 2D array like of the left and right values at which the respective observation was truncated. If not provided it assumes that no truncation occurs.
tl (array like or scalar, optional) – Values of left truncation for observations. If it is a scalar value assumes each observation is left truncated at the value. If an array, it is the respective ‘late entry’ of the observation
tr (array like or scalar, optional) – Values of right truncation for observations. If it is a scalar value assumes each observation is right truncated at the value. If an array, it is the respective right truncation value for each observation
xl (array like, optional) – Array like of the left array for 2-dimensional input of x. This is useful for data that is all intervally censored. Must be used with the
xrinput.xr (array like, optional) – Array like of the right array for 2-dimensional input of x. This is useful for data that is all intervally censored. Must be used with the
xlinput.
Examples
>>> import surpyval as surv >>> x = [1, 2, 3, 4, 5, 6, 6, 7, 8, 10, 13, 15, 16, 17 ,17, 18, 19] >>> # Create a Weibull Mixture Model fitter with 2 sub-distributions >>> wmm = surv.MixtureModel(dist=surv.Weibull, m=2) >>> wmm.fit(x) >>> wmm Parametric Mixture SurPyval Model ================================= Distribution : Weibull Sub-Distributions : 2 Fitted by : EM Weights : 0.6094710980384728, 0.39052890196152723 Parameters : alpha: [ 5.8855232 17.23187124] beta: [ 2.04051304 11.01565277]
- plot(heuristic='Nelson-Aalen', ax=None)
A method to do a probability plot
- Parameters
heuristic ({'Blom', 'Median', 'ECDF', 'Modal', 'Midpoint', 'Mean', 'Weibull', 'Benard', 'Beard', 'Hazen', 'Gringorten', 'None', 'Tukey', 'DPW', 'Fleming-Harrington', 'Kaplan-Meier', 'Nelson-Aalen', 'Filliben', 'Larsen', 'Turnbull'}, optional) – The method that the plotting point on the probability plot will be calculated.
ax (matplotlib.axes.Axes, optional) – The axis onto which the plot will be created. Optional, if not provided a new axes will be created.
- Returns
a matplotlib axes containing the plot
- Return type
matplotlib.axes.Axes
- sf(x)
The survival function of the fitted model.
- Parameters
x (array like) – The values at which the survival function will be evaluated.
- Returns
The survival function evaluated at x.
- Return type
array like