- class surpyval.univariate.parametric.parametric.Parametric(dist: Any, method: str, data: Any, offset: bool, lfp: bool, zi: bool)
Bases:
ParametricDistributionResult of
.fit()or.from_params()method for every parametric surpyval distribution.Instances of this class are very useful when a user needs the other functions of a distribution for plotting, optimizations, monte carlo analysis and numeric integration.
- Hf(x: ArrayLike) ndarray[tuple[Any, ...], dtype[_ScalarT]]
The cumulative hazard function for a distribution using the parameters found in the
.paramsattribute.- Parameters
x (array like or scalar) – The values of the random variables at which the cumulative hazard function will be calculated
- Returns
Hf – The scalar value of the cumulative hazard function of the distribution if a scalar was passed. If an array like object was passed then a numpy array is returned with the value of the cumulative hazard function at each corresponding value in the input array.
- Return type
scalar or numpy array
Examples
>>> from surpyval import Weibull >>> model = Weibull.from_params([10, 3]) >>> model.Hf(2) 0.008000000000000002 >>> model.Hf([1, 2, 3, 4, 5]) array([0.001, 0.008, 0.027, 0.064, 0.125])
- aic() float
The Aikake Information Criterion (AIC) for the model, if it was fit with the
fit()method. Not available if fit with thefrom_params()method.- Returns
aic – The AIC of the model
- Return type
float
Examples
>>> from surpyval import Weibull >>> import numpy as np >>> np.random.seed(1) >>> x = Weibull.random(100, 10, 3) >>> model = Weibull.fit(x) >>> model.aic() 529.0537128477147
- aic_c() float
The Corrected Aikake Information Criterion (AIC) for the model, if it was fit with the
fit()method. Not available if fit with thefrom_params()method.- Returns
aic_c – The Corrected AIC of the model
- Return type
float
Examples
>>> from surpyval import Weibull >>> import numpy as np >>> np.random.seed(1) >>> x = Weibull.random(100, 10, 3) >>> model = Weibull.fit(x) >>> model.aic() 529.1774241879209
- bic() float
The Bayesian Information Criterion (BIC) for the model, if it was fit with the
fit()method. Not available if fit with thefrom_params()method.- Returns
bic – The BIC of the model
- Return type
float
Examples
>>> from surpyval import Weibull >>> import numpy as np >>> np.random.seed(1) >>> x = Weibull.random(100, 10, 3) >>> model = Weibull.fit(x) >>> model.bic() 534.2640532196908
References
Bayesian Information Criterion for Censored Survival Models.
- cb(t: ArrayLike, on: str = 'sf', alpha_ci: float = 0.05, bound: str = 'two-sided') ndarray[tuple[Any, ...], dtype[_ScalarT]]
Confidence bounds of the
onfunction at thealpa_cilevel of significance. Can be the upper, lower, or two-sided confidence by changing value ofbound.- Parameters
x (array like or scalar) – The values of the random variables at which the confidence bounds will be calculated
on (('sf', 'ff', 'Hf', 'hf', 'df'), optional) – The function on which the confidence bound will be calculated.
bound (('two-sided', 'upper', 'lower'), str, optional) – Compute either the two-sided, upper or lower confidence bound(s). Defaults to two-sided.
alpha_ci (scalar, optional) – The level of significance at which the bound will be computed.
- Returns
cb – The value(s) of the upper, lower, or both confidence bound(s) of the selected function at x
- Return type
scalar or numpy array
- cs(x: ArrayLike, X: ArrayLike) ndarray[tuple[Any, ...], dtype[_ScalarT]]
The conditional survival of the model; that is, the probability that an item that has survived to
Xsurvives a furtherx:\[R(x, X) = \frac{R(x + X)}{R(X)}\]- Parameters
x (array like or scalar) – The further durations at which conditional survival is to be calculated.
X (array like or scalar) – The value(s) at which it is known the item has survived
- Returns
cs – The conditional survival probability.
- Return type
array
Examples
>>> from surpyval import Weibull >>> model = Weibull.from_params([10, 3]) >>> model.cs(11, 10) 0.00025840046151723767
- df(x: ArrayLike) ndarray[tuple[Any, ...], dtype[_ScalarT]]
The density function for a distribution using the parameters found in the
.paramsattribute.- Parameters
x (array like or scalar) – The values of the random variables at which the density function will be calculated.
- Returns
df – The scalar value of the density function of the distribution if a scalar was passed. If an array like object was passed then a numpy array is returned with the value of the density function at each corresponding value in the input array.
- Return type
scalar or numpy array
Examples
>>> from surpyval import Weibull >>> model = Weibull.from_params([10, 3]) >>> model.df(2) 0.01190438297804473 >>> model.df([1, 2, 3, 4, 5]) array([0.002997 , 0.01190438, 0.02628075, 0.04502424, 0.06618727])
- entropy() float
The entropy of the distribution using the parameters found in the
.paramsattribute.- Returns
entropy – Returns entropy of the distribution
- Return type
float
Examples
>>> from surpyval import Normal >>> model = Normal.from_params([10, 3]) >>> model.entropy() 2.5175508218727822
- ff(x: ArrayLike) ndarray[tuple[Any, ...], dtype[_ScalarT]]
The cumulative distribution function, or failure function, for a distribution using the parameters found in the
.paramsattribute.- Parameters
x (array like or scalar) – The values of the random variables at which the failure function (CDF) will be calculated.
- Returns
ff – The scalar value of the CDF of the distribution if a scalar was passed. If an array like object was passed then a numpy array is returned with the value of the CDF at each corresponding value in the input array.
- Return type
scalar or numpy array
Examples
>>> from surpyval import Weibull >>> model = Weibull.from_params([10, 3]) >>> model.ff(2) 0.007968085162939342 >>> model.ff([1, 2, 3, 4, 5]) array([0.0009995 , 0.00796809, 0.02663876, 0.061995 , 0.1175031 ])
- get_plot_data(heuristic: str = 'Nelson-Aalen', alpha_ci: float = 0.05) dict
A method to gather plot data
- 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. Default is “Nelson-Aalen”.
alpha_ci (float, optional) – The level of significance at which the confidence bounds, if able, will be calculated. Defaults to 0.05.
- Returns
data – Returns dictionary containing the data needed to do a plot.
- Return type
dict
Examples
>>> from surpyval import Weibull >>> x = Weibull.random(100, 10, 3) >>> model = Weibull.fit(x) >>> data = model.get_plot_data()
- hf(x: ArrayLike) ndarray[tuple[Any, ...], dtype[_ScalarT]]
The instantaneous hazard function for a distribution using the parameters found in the
.paramsattribute.- Parameters
x (array like or scalar) – The values of the random variables at which the instantaneous hazard function will be calculated.
- Returns
hf – The scalar value of the instantaneous hazard function of the distribution if a scalar was passed. If an array like object was passed then a numpy array is returned with the value of the instantaneous hazard function at each corresponding value in the input array.
- Return type
scalar or numpy array
Examples
>>> from surpyval import Weibull >>> model = Weibull.from_params([10, 3]) >>> model.hf(2) 0.012000000000000002 >>> model.hf([1, 2, 3, 4, 5]) array([0.003, 0.012, 0.027, 0.048, 0.075])
- mean() float
The mean of the distribution using the parameters found in the
.paramsattribute.- Returns
mean – Returns the mean of the distribution.
- Return type
float
Examples
>>> from surpyval import Weibull >>> model = Weibull.from_params([10, 3]) >>> model.mean() 8.929795115692489
- moment(n: int) float
The n-th moment of the distribution using the parameters found in the
.paramsattribute.- Parameters
n (integer) – The degree of the moment to be computed
- Returns
moment[n] – Returns the n-th moment of the distribution
- Return type
float
Examples
>>> from surpyval import Normal >>> model = Normal.from_params([10, 3]) >>> model.moment(1) 10.0 >>> model.moment(5) 202150.0
- neg_ll() float
The negative log-likelihood for the model, if it was fit with the
fit()method. Not available if fit with thefrom_params()method.- Returns
neg_ll – The negative log-likelihood of the model
- Return type
float
Examples
>>> from surpyval import Weibull >>> import numpy as np >>> np.random.seed(1) >>> x = Weibull.random(100, 10, 3) >>> model = Weibull.fit(x) >>> model.neg_ll() 262.52685642385734
- param_cb(name: str, alpha_ci: float = 0.05, bound: str = 'two-sided') ndarray[tuple[Any, ...], dtype[_ScalarT]]
Method to calculate the confidence bound on a parameter.
- plot(heuristic: str = 'Nelson-Aalen', plot_bounds: bool = True, alpha_ci: float = 0.05, ax: Axes | None = None) list
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.
plot_bounds (Boolean, optional) – A Boolean value to indicate whether you want the probability bounds to be calculated.
alpha_ci (float, optional) – The level of significance at which the confidence bounds, if able, will be calculated. Defaults to 0.05.
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
plot – list of a matplotlib plot object
- Return type
list
Examples
>>> from surpyval import Weibull >>> x = Weibull.random(100, 10, 3) >>> model = Weibull.fit(x) >>> model.plot()
- qf(p: ArrayLike) ndarray[tuple[Any, ...], dtype[_ScalarT]]
The quantile function for a distribution using the parameters found in the
.paramsattribute.- Parameters
p (array like or scalar) – The values, which must be between 0 and 1, at which the the quantile will be calculated
- Returns
qf – The scalar value of the quantile of the distribution if a scalar was passed. If an array like object was passed then a numpy array is returned with the value of the quantile at each corresponding value in the input array.
- Return type
scalar or numpy array
Examples
>>> from surpyval import Weibull >>> model = Weibull.from_params([10, 3]) >>> model.qf(0.2) 6.06542793124108 >>> model.qf([.1, .2, .3, .4, .5]) array([4.72308719, 6.06542793, 7.09181722, 7.99387877, 8.84997045])
- random(size: int | tuple[int, ...], a: float | None = None, b: float | None = None) ndarray[tuple[Any, ...], dtype[_ScalarT]]
A method to draw random samples from the distributions using the parameters found in the
.paramsattribute.- Parameters
size (int) – The number of random samples to be drawn from the distribution.
a (float or None) – The left truncated value if sampling from a truncated distribution
b (float or None) – The right truncated value if sampling from a truncated distribution
- Returns
random – Returns a numpy array of size
sizewith random values drawn from the distribution.- Return type
numpy array
Examples
>>> from surpyval import Weibull >>> model = Weibull.from_params([10, 3]) >>> np.random.seed(1) >>> model.random(1) array([8.14127103]) >>> model.random(10) array([10.84103403, 0.48542084, 7.11387062, 5.41420125, 4.59286657, 5.90703589, 7.5124326 , 7.96575225, 9.18134126, 8.16000438])
- sf(x: ArrayLike) ndarray[tuple[Any, ...], dtype[_ScalarT]]
Survival (or Reliability) function for a distribution using the parameters found in the
.paramsattribute.- Parameters
x (array like or scalar) – The values of the random variables at which the survival function will be calculated.
- Returns
sf – The scalar value of the survival function of the distribution if a scalar was passed. If an array like object was passed then a numpy array is returned with the value of the survival function at each corresponding value in the input array.
- Return type
scalar or numpy array
Examples
>>> from surpyval import Weibull >>> model = Weibull.from_params([10, 3]) >>> model.sf(2) 0.9920319148370607 >>> model.sf([1, 2, 3, 4, 5]) array([0.9990005 , 0.99203191, 0.97336124, 0.938005 , 0.8824969 ])
- var() float
The variance of the distribution using the parameters found in the
.paramsattribute.- Returns
var – Returns the variance of the distribution.
- Return type
float
Examples
>>> from surpyval import Weibull >>> model = Weibull.from_params([10, 3]) >>> model.var() 11.229...