Survival logrank test - 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
Compares the survival of two right-censored samples.
public static LogRankResult Test(ReadOnlySpan<double> durationsA, ReadOnlySpan<bool> eventObservedA, ReadOnlySpan<double> durationsB, ReadOnlySpan<bool> eventObservedB)public static LogRankResult Test(ReadOnlySpan<double> durationsA, ReadOnlySpan<bool> eventObservedA, ReadOnlySpan<double> durationsB, ReadOnlySpan<bool> eventObservedB, LogRankOptions options)public static LogRankResult Test(ReadOnlySpan<double> durationsA, ReadOnlySpan<bool> eventObservedA, ReadOnlySpan<double> weightsA, ReadOnlySpan<double> durationsB, ReadOnlySpan<bool> eventObservedB, ReadOnlySpan<double> weightsB, LogRankOptions options)The second overload runs a weighting of the family, lifelines' weightings=, p, q and t_0; the
third also weighs each subject, lifelines' weights_A and weights_B.
Parameters — durationsA holds the first group's non-negative durations and eventObservedA
the flag for each of them, true where the duration ends in the event. durationsB and
eventObservedB are the same pair for the second group. Each group's two spans must be the same
length; the two groups need not be the same size as each other. weightsA and weightsB hold one
positive, finite weight per subject of their group, or are empty for ones. options is the
LogRankOptions: the weighting, its exponents and the truncation.
Returns — a LogRankResult carrying the statistic, its upper-tail chi-squared p-value, and the
degrees of freedom, which are one for a two-sample comparison.
Exceptions — ArgumentException when a group's spans differ in length, a group is empty, a
duration is negative or NaN, a weight span is neither empty nor one positive, finite value per
subject, or the distinct durations times two are more cells than one array holds. ArgumentOutOfRangeException when options names no weighting, or holds a negative or non-finite
exponent, or a negative or NaN truncation.
Example — two arms that separate, and two that cannot.
using Lodestar.Survival;
LogRankResult differ = LogRank.Test(
[6, 7, 10], [true, true, true],
[1, 2, 3], [true, true, true]);
LogRankResult same = LogRank.Test(
[2, 4, 6, 8], [true, true, true, true],
[2, 4, 6, 8], [true, true, true, true]);
double statistic = same.Statistic; // => 0
double p = same.PValue; // => 1
int df = differ.DegreesOfFreedom; // => 1Remarks — the second call is the test's own sanity check: identical arms give a statistic of exactly zero, because at every time the observed count equals the expected one.
The order of the two groups does not change the statistic. It is a square, and swapping the arms flips the sign of the difference being squared. What it does change is nothing a caller can observe, which is why there is no "reference group" argument.
A group entirely censored still contributes. Its subjects sit in the pooled risk sets and raise the other arm's expected counts, which is the opposite of dropping them — and the result is a larger statistic, not a smaller one.
A weight of two is the subject written twice, in every risk set and every event count — except in
the pooled curve Fleming-Harrington weighs by, which counts subjects unweighted, as lifelines' does;
LogRank.MultiGroup has what lifelines keeps about fractional ones.
Applies to — net10.0, netstandard2.0.
See also — LogRank,
Distributions.ChiSquaredSf.