SplineFitter¶
- class lifelines.fitters.spline_fitter.SplineFitter(knot_locations: ndarray, *args, **kwargs)¶
Model the cumulative hazard using \(N\) cubic splines. This offers great flexibility and smoothness of the cumulative hazard.
\[H(t) = \exp{\left( \phi_0 + \phi_1\log{t} + \sum_{j=2}^N \phi_j v_j(\log{t})\right)}\]where \(v_j\) are our cubic basis functions at predetermined knots. See references for exact definition.
- Parameters:
knot_locations (list, np.array) – The locations of the cubic breakpoints. Must be length two or more. Typically, the first knot is the minimum observed death, the last knot is the maximum observed death, and the knots in between are the centiles of observed data (ex: if one additional knot, choose the 50th percentile, the median. If two additional knots, choose the 33rd and 66th percentiles).
References
Royston, P., & Parmar, M. K. B. (2002). Flexible parametric proportional-hazards and proportional-odds models for censored survival data, with application to prognostic modelling and estimation of treatment effects. Statistics in Medicine, 21(15), 2175–2197. doi:10.1002/sim.1203
Examples
from lifelines import SplineFitter from lifelines.datasets import load_waltons waltons = load_waltons() T, E = waltons['T'], waltons['E'] knots = np.percentile(T.loc[E.astype(bool)], [0, 50, 100]) sf = SplineFitter(knots) sf.fit(T, E) sf.plot() print(sf.knots)
- cumulative_hazard_¶
The estimated cumulative hazard (with custom timeline if provided)
- Type:
DataFrame
- hazard_¶
The estimated hazard (with custom timeline if provided)
- Type:
DataFrame
- survival_function_¶
The estimated survival function (with custom timeline if provided)
- Type:
DataFrame
- cumulative_density_¶
The estimated cumulative density function (with custom timeline if provided)
- Type:
DataFrame
- density_¶
The estimated density function (PDF) (with custom timeline if provided)
- Type:
DataFrame
- variance_matrix_¶
The variance matrix of the coefficients
- Type:
DataFrame
- median_survival_time_¶
The median time to event
- Type:
float
- lambda_¶
The fitted parameter in the model
- Type:
float
- rho_¶
The fitted parameter in the model
- Type:
float
- durations¶
The durations provided
- Type:
array
- event_observed¶
The event_observed variable provided
- Type:
array
- timeline¶
The time line to use for plotting and indexing
- Type:
array
- entry¶
The entry array provided, or None
- Type:
array or None
- knot_locations¶
The locations of the breakpoints.
- Type:
array
- n_knots¶
Count of breakpoints
- Type:
int