Survival parametricsurvival fit - CyrilB1531/lodestar GitHub Wiki
Development build. This page describes
main, not a released package. The latest published Lodestar.Survival is 0.2.0 — read its documentation.
Home › Survival › Survival estimators
Fits a parametric model to right-censored durations: lifelines' fit.
public static ParametricSummary Fit(ReadOnlySpan<double> durations, ReadOnlySpan<bool> eventObserved, ParametricModel model, ParametricOptions options = null)public static ParametricSummary Fit(ReadOnlySpan<double> durations, ReadOnlySpan<bool> eventObserved, ReadOnlySpan<double> weights, ReadOnlySpan<double> entries, ParametricModel model, ParametricOptions options = null)The second overload takes lifelines' weights and entry.
Parameters — model is the ParametricModel to fit. durations holds one
positive, finite duration per subject, and eventObserved is true where it ends in the event.
weights holds one positive, finite weight per subject, or is empty for ones. entries holds each
subject's entry time, non-negative and at most its duration, or is empty when everyone is observed
from zero. options sets the interval level, the iteration budget and the piecewise model's
breakpoints; null takes the defaults.
Returns — a ParametricSummary: the parameters with their standard errors,
z statistics, p-values and intervals, the log-likelihood and AIC, and the fitted curves.
Exceptions — ArgumentException when the spans differ in length or are empty, a duration is not
positive and finite, a weight or entry span is neither empty nor one valid value per subject, or the
piecewise model is given no breakpoint. ArgumentOutOfRangeException when model names no model.
InvalidOperationException when the fit does not converge, its parameters are not identified, or
every observation is a probability and the likelihood reaches one only in the limit of a point mass, so it has no maximum.
Example — a weight of two is the same subject counted twice.
using Lodestar.Survival;
double[] months = [5, 8, 12, 3, 15, 9, 20, 6, 11, 14];
bool[] died = [true, true, false, true, true, true, false, true, true, false];
double[] weights = [1, 2, 1, 1, 1, 2, 1, 1, 1, 1];
ParametricSummary weighted = ParametricSurvival.Fit(months, died, weights, [], ParametricModel.Weibull);
ParametricSummary repeated = ParametricSurvival.Fit([5, 8, 12, 3, 15, 9, 20, 6, 11, 14, 8, 9],
[true, true, false, true, true, true, false, true, true, false, true, true],
ParametricModel.Weibull);
double byWeight = Math.Round(weighted.Parameters[0], 6); // => 12.661582
double byCopy = Math.Round(repeated.Parameters[0], 6); // => 12.661582Remarks — Newton's method on exact derivatives, from lifelines' own starting point, each step halved until it raises the likelihood and keeps every parameter inside its bounds. The derivatives are carried forward through the likelihood, not estimated by differences, so the observed information the standard errors come from is the exact one at the maximum. lifelines' optimiser stops 1e-6 to 1e-3 short of that maximum: expect a default lifelines fit to differ from the sixth significant figure to the third.
Delayed entry conditions each subject on having survived to its entry, lifelines' entry: a
subject entering at month 4 has its likelihood divided by S(4), so it says nothing about the months
before it was watched.
The piecewise exponential needs its breakpoints, in
ParametricOptions.Breakpoints; every other model ignores them.
Applies to — net10.0, netstandard2.0.
See also — ParametricSurvival, ParametricSummary,
ParametricOptions,
ParametricSurvival.FitLeftCensored.