WeibullAFT<T>
Models & Types · AiDotNet.SurvivalAnalysis
Implements the Weibull Accelerated Failure Time (AFT) model for survival analysis.
Inheritance: SurvivalModelBase<T> → WeibullAFT<T>
For Beginners
The Weibull AFT model assumes survival times follow a Weibull distribution. Unlike Cox models that model hazard ratios, AFT models directly model how covariates “accelerate” or “decelerate” time to event. Coefficients can be interpreted as the effect on survival time.
How It Works
The Model: log(T) = β₀ + β₁X₁ + … + βₚXₚ + σε where T is survival time, X are covariates, β are coefficients, σ is scale, and ε ~ extreme value distribution.
Interpretation:
- A positive coefficient means longer survival (protective effect)
- A negative coefficient means shorter survival (risk factor)
- exp(β) gives the multiplicative effect on survival time
Weibull distribution:
- Shape parameter κ controls hazard shape (κ < 1: decreasing, κ = 1: constant, κ > 1: increasing)
- Scale parameter λ controls time scale
Reference: Lawless (2003), Statistical Models and Methods for Lifetime Data
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 WeibullAFT<double>(maxIterations: 100, tolerance: 1e-6))
.Build(features, times, events);
var risk = result.Predict(features);
Constructors
| Constructor | Summary |
|---|---|
WeibullAFT(int maxIterations, double tolerance) |
Creates a new Weibull AFT model. |
Properties
| Property | Summary |
|---|---|
T Intercept { get; set; } |
Gets the intercept term (β₀). |
T Scale { get; set; } |
Gets the scale parameter (σ). |
T Shape { get; } |
Gets the shape parameter (κ = 1/σ). |
Vector<T> Coefficients { get; set; } |
Gets the regression coefficients (β). |
double Tolerance { get; } |
Gets the tolerance for convergence. |
int MaxIterations { get; } |
Gets the maximum iterations for optimization. |
Methods
| Method | Summary |
|---|---|
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
|
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 median survival time. |
Vector<T> PredictHazardRatio(Matrix<T> x) |
Predicts hazard ratios (acceleration factors) relative to baseline. |