SurvivalCurve
survival.SurvivalCurve(
cumulative_hazard,
inverse_cumulative_hazard,
label='curve',
)A survival curve as its cumulative hazard function, plus how to sample from it.
The families below (exponential, weibull, gompertz), the curve algebra in heormodel.survival.algebra, and heormodel.survival.lifelines_adapter.from_lifelines are the ways to build one; nothing about the analysis code constructs a SurvivalCurve directly.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| cumulative_hazard | Callable[[_FloatArray], _FloatArray] |
The curve’s cumulative hazard H(t), mapping an array of non-negative times to H at each one. survival is exp(-H(t)). |
required |
| inverse_cumulative_hazard | Callable[[_FloatArray], _FloatArray] |
The inverse of cumulative_hazard, mapping a target hazard value to the time at which the curve reaches it. sample_time uses it for inverse-transform sampling. |
required |
| label | str |
A short description of the curve for repr and for reading back a model built from several curves, for example "weibull(shape=1.2, scale=6)". |
'curve' |
Example
from heormodel.survival import weibull curve = weibull(shape=1.2, scale=6.0) round(float(curve.survival(6.0)), 5) 0.36788
Methods
| Name | Description |
|---|---|
| sample_time | Sample event times by inverse-transform sampling. |
| survival | Survival probability S(t) = exp(-cumulative_hazard(t)). |
sample_time
survival.SurvivalCurve.sample_time(rng, size)Sample event times by inverse-transform sampling.
The cumulative hazard evaluated at a curve’s own event time follows a standard exponential distribution, so drawing an exponential variate and inverting the cumulative hazard samples an event time directly, without inverting the survival function on the probability scale.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| rng | np.random.Generator | A numpy random generator, typically the one an engine’s model function receives. |
required |
| size | int |
Number of event times to draw. | required |
Returns
| Name | Type | Description |
|---|---|---|
_FloatArray |
Array of size sampled event times. |
Example
import numpy as np from heormodel.survival import exponential curve = exponential(rate=0.2) rng = np.random.default_rng(0) times = curve.sample_time(rng, 5) times.shape (5,)
survival
survival.SurvivalCurve.survival(time)Survival probability S(t) = exp(-cumulative_hazard(t)).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| time | _FloatArray | float |
Time (years), scalar or array. | required |
Returns
| Name | Type | Description |
|---|---|---|
_FloatArray |
Survival probability at each time. |
Example
from heormodel.survival import exponential curve = exponential(rate=0.2) round(float(curve.survival(5.0)), 5) 0.36788