Survival aalenadditive 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

AalenAdditive.Fit

Fits the model to right-censored durations: lifelines' fit.

public static AalenSummary Fit(ReadOnlySpan<double> design, ReadOnlySpan<double> durations, ReadOnlySpan<bool> eventObserved, int featureCount, AalenOptions options = null)
public static AalenSummary Fit(ReadOnlySpan<double> design, ReadOnlySpan<double> durations, ReadOnlySpan<bool> eventObserved, ReadOnlySpan<double> weights, int featureCount, AalenOptions options = null)

The second overload takes lifelines' weights_col.

Parameters โ€” design holds the covariates row-major, featureCount values per subject, with no intercept column: AalenOptions.FitIntercept adds it, last. durations holds one non-negative, 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. featureCount is the number of covariates, zero for a fit on the intercept alone. options sets the level, the intercept and the two penalties; null takes the defaults.

Returns โ€” an AalenSummary: the increments at each event time, their cumulative sums with variance and bounds, the slopes table, the concordance, and the predictions.

Exceptions โ€” ArgumentOutOfRangeException when featureCount is negative. ArgumentException in any of these cases:

  • the spans do not match the subjects, or a value is not finite;
  • a duration is negative;
  • fewer than two subjects are given, or no subject has the event;
  • a covariate does not vary beside the intercept, or there is no column at all;
  • the weights are neither empty nor one positive, finite value per subject;
  • the subjects, the event times or the columns themselves times the columns are more cells than one array holds;
  • the design is more cells than one array holds, or its length only matches the subjects times featureCount once that product wraps int (#1614).

Example โ€” a covariate that does not vary has no coefficient beside the intercept, and is refused.

using Lodestar.Survival;

double[] months = [3, 10, 5, 4, 8, 18, 12, 6, 9, 20, 7, 15];
bool[] died = [true, true, true, false, true, true, true, true, true, false, true, true];
double[] everyone = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];

string refusal;
try
{
    AalenAdditive.Fit(everyone, months, died, featureCount: 1);
    refusal = "fitted";
}
catch (ArgumentException error)
{
    refusal = error.ParamName!;
}

string parameter = refusal;  // => design

Remarks โ€” the subjects are sorted by duration and stepped through the distinct event times. At each, the increments solve (Xแต€X + (cโ‚ + cโ‚‚)I) v = Xแต€y + cโ‚‚ vโ‚‹, over the rows of the subjects at risk, with y the square root of each weight at that time's deaths and zero elsewhere, cโ‚ and cโ‚‚ the two penalties of AalenOptions and vโ‚‹ the previous time's increments. Each column is scaled to unit sample deviation and each row weighted by the square root of its weight; the answer is rescaled back. A system that is singular gives zero increments, as lifelines answers its LinAlgError: a covariate constant among the subjects left at risk makes it so, and there LAPACK's pivot lands a few ulps either side of zero by the order of its sums, so lifelines fails or solves by chance. This answers zeros, without a penalty, wherever the pivot is within 8 ulps of its diagonal per subject at risk, the rounding those sums leave growing with their length.

The fit stops once no more than three subjects per covariate remain, as lifelines does, so EventTimes may end before the last event.

lifelines' readings are kept on purpose, so the numbers are lifelines':

  • a subject leaves the risk set only at an event time. One censored between two event times is never removed, and stays at risk to the end: among the twelve patients above, the one censored at month 4 is still in the regression at month 18.
  • CumulativeVariance is rescaled by the covariate's deviation, not its square; AalenSummary has it, with the concordance's own reading.

Applies to โ€” net10.0, netstandard2.0.

See also โ€” AalenAdditive, AalenSummary, AalenOptions.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ