NelsonAalenEstimator<T>
Models & Types · AiDotNet.SurvivalAnalysis
Implements the Nelson-Aalen estimator for non-parametric cumulative hazard function estimation.
Inheritance: SurvivalModelBase<T> → NelsonAalenEstimator<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
The Nelson-Aalen estimator calculates the cumulative hazard function H(t), which represents the accumulated risk of an event up to time t. Unlike Kaplan-Meier which estimates survival probability S(t), Nelson-Aalen estimates H(t) directly. They’re related by S(t) = exp(-H(t)).
How It Works
How it works:
- At each event time t, add d(t)/n(t) to the cumulative hazard
- d(t) = number of events at time t
- n(t) = number of subjects at risk just before time t
Variance estimation: The Nelson-Aalen estimator uses the variance formula: Var(H(t)) = sum over event times of d(t)/n(t)^2
When to use:
- When you want to estimate cumulative hazard directly
- As input to other models that work with cumulative hazard
- When comparing hazard rates across groups
Reference: Nelson (1972), Aalen (1978)
Example
// age and treatment arm per patient
var features = new Matrix<double>(new double[,]
{
{ 45, 1 }, { 52, 0 }, { 38, 1 }, { 61, 0 }, { 47, 1 }, { 55, 0 }
});
// months each patient was observed
var times = new Vector<double>(new double[] { 5.0, 12.0, 3.0, 18.0, 9.0, 21.0 });
// 1 = the event happened; 0 = censored, still fine when the study ended or lost to follow-up
var events = new Vector<int>(new int[] { 1, 0, 1, 0, 1, 1 });
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new NelsonAalenEstimator<double>())
.Build(features, times, events);
var risk = result.Predict(features);
Constructors
| Constructor | Summary |
|---|---|
NelsonAalenEstimator() |
Creates a new Nelson-Aalen estimator. |
Properties
| Property | Summary |
|---|---|
Vector<T> CumulativeHazard { get; } |
Gets the cumulative hazard function values at event times. |
Vector<T> Variance { get; } |
Gets the variance estimates at event times. |
Methods
| Method | Summary |
|---|---|
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
|
Matrix<T> PredictCumulativeHazard(Vector<T> times, Matrix<T> features) |
Predicts cumulative hazard at specified times (override to use direct estimate). |
Matrix<T> PredictSurvivalProbability(Matrix<T> x, Vector<T> times) |
Predicts survival probabilities at specified times. |
Vector<T> GetBaselineSurvival(Vector<T> times) |
Gets the baseline survival function. |
Vector<T> Predict(Matrix<T> input) |
Predicts survival probability at median event time. |
Vector<T> PredictHazardRatio(Matrix<T> x) |
Returns hazard ratios (all 1s for non-parametric estimator). |