sample_params
survival.sample_params(fitted_model, n, seed=None)Draw parameter sets from a fit’s asymptotic covariance.
Draws n parameter vectors from the asymptotic normal approximation to the maximum-likelihood estimate, Normal(params_, variance_matrix_), the same approximation the fitting package itself uses for confidence intervals. Parameters that must be positive (lambda_ and rho_ of WeibullFitter, lambda_ of ExponentialFitter, sigma_ of LogNormalFitter, alpha_ and beta_ of LogLogisticFitter, and each lambda_ of PiecewiseExponentialFitter) are sampled on the log scale and exponentiated, so every draw is positive. The covariance on the log scale follows from the delta method, Var(log p) = Var(p) / p**2, applied to the whole matrix. Unconstrained parameters, such as the location mu_ of LogNormalFitter, stay on the natural scale, and a fitter that is not listed here is sampled entirely on the natural scale.
The draws land on the canonical iteration index, so the fitted survival curve’s uncertainty flows into heormodel.run.run_psa alongside every other parameter, keyed by the fitted model’s own parameter names (for lifelines.WeibullFitter, lambda_ for the scale and rho_ for the shape).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| fitted_model | FittedSurvivalModel | A fitted parametric survival model exposing params_ and variance_matrix_. |
required |
| n | int |
Number of iterations (rows) to draw. | required |
| seed | int | np.random.Generator | None |
Integer seed or numpy generator for reproducibility. |
None |
Returns
| Name | Type | Description |
|---|---|---|
| pd.DataFrame | DataFrame with n rows, a RangeIndex named "iteration", and one |
|
| pd.DataFrame | column per fitted parameter. |
Example
from lifelines import WeibullFitter # doctest: +SKIP fit = WeibullFitter().fit(durations, event_observed) # doctest: +SKIP draws = sample_params(fit, n=1000, seed=1) # doctest: +SKIP draws.index.name # doctest: +SKIP ‘iteration’