Random Survival Forests › Formula
Machine Learning from ScratchAll chapters Random Survival Forests › FormulaSection view · Sections in this chapter4 / 10 ↓
Reading tools Definitions, links & notes
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
We organize the construction around three questions: how to choose a split, what to store at a leaf, and how to combine the trees.
- How do we choose a split? A classification tree compares class purity in the two children, and a regression tree compares the spread of the numeric outcome. Their usual complete-data formulas require observed labels or numeric outcomes. Censored event times cannot be inserted as though their observed lower bounds were the outcomes. We need a criterion that uses only what is observed: the ordering of events in time and the sizes of the risk sets on each side of the candidate threshold.
- What do we store at a leaf? A regression leaf stores a numeric prediction; a classification leaf stores class probabilities (a probability vector for multiple classes). A survival leaf has to store a function: the survival curve of the patients in the node, estimated from its own risk sets without assuming a parametric shape.
- How do we combine the trees? Scikit-learn classification forests average class probabilities, while regression forests average numeric predictions; some classification forests instead combine class votes. A survival forest combines function-valued predictions. Averaging cumulative hazards and averaging survival curves are different choices; either can be meaningful, and averaging alone does not establish unbiasedness or consistency.
Bootstrap sampling, random feature subsets, and recursive axis-aligned partitioning reuse the usual forest scaffold. Event-count stopping rules and out-of-bag scoring also have to account for censored outcomes. We begin with risk sets, derive the split criterion and leaf estimator, then combine the trees.
Notation and risk sets
In the formulas below, "death" denotes the event of interest, including readmission in the opening example.
Everything in the forest is built from the same three quantities observed at each event time: how many patients are still at risk, how many fail, and how the failures are distributed across the children of a split. To write those quantities down, we start with the observation model. Let be the observed time for patient and the event indicator, so that for an event and for a censored observation. The underlying event time is and the censoring time is , with
The quantities are:
- : the observed time for patient , equal to the smaller of the event time and the censoring time
- : the underlying (latent) event time for patient
- : the censoring time for patient
- : the event indicator, equal to 1 when the event is observed at or before the censoring time and 0 otherwise
- : the indicator function, equal to 1 when its argument is true and 0 otherwise
The feature vector is . The central object in everything that follows is the risk set: the set of patients still observable just before time . Its size is the number at risk:
The quantities are:
- : the risk set, the set of patients still under observation just before time
- : the number at risk at time , the size of the risk set
- : the total number of patients
- : the observed time for patient
- : the indicator function, equal to 1 when its argument is true and 0 otherwise
A risk set contains patients whose events could still be observed at time . Under the convention , a patient censored at time 5 contributes at earlier event times and at time 5 itself, then leaves all later risk sets. Dropping that patient at the start would undercount those earlier denominators. Keeping the patient after censoring would overcount later denominators. Risk-set bookkeeping uses the observed follow-up without imputing a later failure time.
The quantity is the number of deaths observed exactly at :
The quantities are:
- : the number of deaths observed exactly at time
- : the observed time for patient
- : the event indicator for patient , equal to 1 for an event and 0 for a censored observation
- : the indicator function, equal to 1 when its argument is true and 0 otherwise
Grouping events at their recorded times also handles tied observations; it does not require an intrinsically discrete event-time model. At any time , we observe the pair : how many failed and how many were eligible to fail. For a fixed assignment of patients to candidate children or terminal leaves, these event-time counts determine the log-rank and Nelson–Aalen calculations. The search still needs covariate values and thresholds to form those assignments.
Survival-tree risk sets and split criteria
Now we can state the split criterion. A survival tree recursively partitions covariate space. At each node it compares thresholds on candidate features, forming a left child and right child . Ordinary squared-error splitting cannot use unobserved failure times as if they were known. Log-rank splitting instead compares the observed event counts with those expected from the two children's risk-set sizes.
What we can compare is what the risk sets tell us at every event time: the fraction of deaths that occur in the left child versus the fraction of patients who were at risk there. Under equal hazards and suitable censoring assumptions, their conditional expectations agree. Observed fractions can differ by chance even for an uninformative split, and crossing hazards can make signed differences cancel. The log-rank statistic sums those observed-minus-expected differences and divides by an aggregate standard deviation. That is the intuition. The formula makes it precise.
For a candidate split, let
be the number at risk in each child, and let be the number of deaths at time that fall in the left child, where:
- : the risk set at time , the set of patients still under observation just before
- : the set of patients in the left child of the split
- : the set of patients in the right child of the split (this symbol is overloaded with the risk set ; the argument disambiguates the risk set here)
- : the number at risk at time in the left child
- : the number at risk at time in the right child
- : the total number at risk at time
- : the number of deaths at time that fall in the left child
If the two children have the same hazard, then the deaths at time are allocated between the children in proportion to how many people were at risk there, so the expected number of deaths in the left child is
The quantities are:
- : the expected number of deaths in the left child at time under the null of equal hazards
- : the total number of deaths at time
- : the number at risk at time in the left child
- : the total number at risk at time
The observed number minus the expected number,
is the observed-minus-expected event contribution at that time. The log-rank numerator sums these contributions, and its denominator is the square root of their summed null variances. It does not standardize each event-time contribution separately. The variance calculation below accounts for the number of deaths and the allocation of patients between the two risk sets.
The probability of exactly deaths in when deaths are drawn without replacement from a population of with members is hypergeometric, and its variance is
The quantities are:
- : the hypergeometric variance of the number of deaths in the left child at time
- : the total number of deaths at time
- : the total number at risk at time
- : the number at risk at time in the left child
- : the number at risk at time in the right child
Write . For , the same hypergeometric variance is . The first factor is the binomial variance for draws, and the last factor corrects for sampling without replacement. An empty child or an event count equal to the whole risk set gives zero variance. When , the displayed fraction is undefined; the implementation assigns zero because no between-child comparison remains.
Summing the surprises and the variances over all event times gives a single standardized statistic. Writing for the distinct event times,
The quantities are:
- : the standardized log-rank statistic for candidate split
- : the index of the candidate split
- : the -th distinct event time
- : the observed number of deaths in the left child at time
- : the total number of deaths at time
- : the number at risk at time in the left child
- : the total number at risk at time
- : the hypergeometric variance of the left-child death count at time
The tree picks the split that maximizes . A positive sign indicates more observed left-child events than expected in the summed comparison; it need not mean a larger hazard at every time. For a prespecified split, the standardized statistic has an approximately standard-normal null distribution under the usual log-rank central-limit conditions, including independent censoring, growing nondegenerate event information, and no dominating event-time contribution. With untied failures it is the standardized Cox score at for the binary group indicator. Tied-failure conventions can change the Cox information calculation, so that exact equivalence needs its convention stated.
This is a greedy search, and it is biased. The maximum of a large collection of statistics is not itself a standard normal, and features with many distinct values offer more candidate thresholds and therefore more chances to find a large maximum. Because we maximize over thresholds, we should not turn the split value into a -value. The random survival forest mitigates the problem by considering only a random subset of features at each split and by requiring a minimum number of events in each child, but the mitigation is not a cure.
Terminal-node survival and hazard estimates
The split criterion gives us a partition, but a partition is only useful if we can describe the survival behavior of each cell. This is the second piece of machinery. Once a node is declared terminal, we need to turn its patients into a survival curve, and we want the curve to assume no parametric shape. The natural starting point is the nonparametric estimator from the counting-process chapter, the Nelson–Aalen estimator. For a terminal node with event times , the number of deaths at is and the number at risk just before it is . The estimated cumulative hazard is
The quantities are:
- : the Nelson–Aalen estimate of the cumulative hazard in node at time
- : the terminal node
- : the -th distinct event time in node
- : the number of deaths at in node
- : the number at risk just before in node
and the implied survival function is .
Compare this estimate with the Kaplan–Meier product . Each factor is the empirical conditional survival fraction at an event time. Where every increment is small, the expansion explains why the negative log of Kaplan–Meier is close to Nelson–Aalen. They need not be equal in a finite leaf. If the last remaining patient fails, Kaplan–Meier reaches zero while remains positive. Both are valid finite-follow-up survival estimates; neither flat tail identifies the unobserved lifetime distribution beyond follow-up.
The terminal node therefore stores a step function, not a number. Its jumps are at the event times of the node, and its height is determined by the node's own risk sets. Jump sizes depend on at each event time. A small late risk set can create a large jump even when earlier risk sets were large. This makes event counts and risk-set sizes useful tuning considerations, and it is why the forest's terminal nodes are not "pure" in the sense of classification trees: they are small samples from which a cumulative hazard can be estimated.
A second estimate, the "mortality" or risk score, is used to rank patients and is a summary of the whole step function. It exists because ranking and reporting often demand a single number per patient, even though the primary output is a curve. With a common grid of times shared by all trees,
The quantities are:
- : the risk score for a patient with covariates , the sum of the ensemble cumulative hazard over the grid
- : the covariate vector of the patient
- : the common time grid shared by all trees
- : the number of points on the common grid
- : the ensemble cumulative hazard at time for covariates
which is the sum of the ensemble cumulative hazard over the grid, i.e. the average across trees of the total hazard accumulated over the grid. It is a rank-order score and it is not a probability. A larger means a larger sum on this grid, but does not imply larger cumulative hazard or lower survival at every time when curves cross; two patients whose scores differ by a factor of two are simply in a different order, not "twice as sick".
Bootstrap ensembles and out-of-bag predictions
The third piece is the ensemble. A single tree can have high sampling variance: its splits depend on the training sample, and a small change in the data can move a threshold and change predictions below it. The ensemble can reduce that variance by averaging trees with imperfectly correlated predictions. Bootstrap samples provide diversity and omitted observations for OOB assessment, subject to the evaluation caveats below.
The forest is a collection of trees, each grown on a bootstrap sample of the observations. Let be the cumulative hazard for the -th tree, evaluated at a point by pushing down the tree and returning the step function of the terminal node it reaches. The ensemble estimate is
The quantities are:
- : the ensemble cumulative hazard at time for covariates
- : the number of trees in the forest
- : the cumulative hazard of the -th tree at time for covariates
- : the ensemble survival function at time for covariates
Our scratch forest uses the cumulative-hazard average shown above and defines survival as its negative exponential. For any fixed collection of tree hazards, convexity gives . Both sides are nonincreasing curves in , but they need not agree. This finite-ensemble inequality supplies no automatic unbiasedness or consistency result. Scikit-survival's cumulative-hazard method also averages Nelson–Aalen estimates; its survival method instead averages leaf Kaplan–Meier estimates. Those survival curves are not the left-hand expression unless the leaf estimators happen to coincide. Check the actual prediction method before comparing implementations.
The following deterministic toy ensemble isolates that gap. Five nondecreasing cumulative-hazard curves share one baseline shape but differ in scale, so the difference between the two aggregation conventions is not confounded by sampling noise.
VisualizationOut [4]Expand

The bootstrap also supplies the out-of-bag estimate. Observation is out of bag for tree if the -th bootstrap sample did not contain it. Let be the set of trees for which is out of bag. The probability that a given observation is in a given bootstrap sample is , so its exact expected size is , approximately for large . The out-of-bag prediction is
The quantities are:
- : the out-of-bag cumulative hazard at time for observation
- : the covariate vector of observation
- : the set of trees for which observation is out of bag
- : the number of such trees
- : the cumulative hazard of tree at time for observation
Here only trees whose bootstrap samples exclude observation contribute to its prediction. If , that prediction is unavailable. This avoids training those trees' splits and leaves on the held-out observation, but it does not make the complete OOB procedure independent of that observation: this implementation uses the full training event-time grid when forming mortality scores. Shared preprocessing or repeated OOB tuning can introduce further dependencies. Treat OOB concordance as an internal estimate, and reserve an independent test set for a final comparison.
Mathematical Properties
Three properties summarize what we have built, and each points to a different reason to be careful when the forest is applied.
For a prespecified binary grouping with untied failures, the log-rank comparison agrees with the standardized Cox score at zero coefficient. This connects the split criterion to a local proportional-hazards comparison without imposing proportional hazards on the fitted forest. Choosing the largest statistic over many thresholds changes its null distribution, and crossing hazards can reduce the power of the signed comparison.
The Nelson–Aalen estimator adds the non-negative increments . At a fixed time , a commonly used variance estimate is . This estimates uncertainty in the cumulative-hazard staircase; it is distinct from the hypergeometric variance used in the log-rank split statistic.
Averaging can reduce variance; it does not in itself remove bias. If random tree predictions at a fixed have common variance and common pairwise correlation , the covariance sum gives . This is an exchangeable-prediction model, not a claim that trees are unbiased. Independently randomized trees can be conditionally independent given the training data while remaining dependent across repeated training datasets. More trees reduce the remaining randomization variation, with diminishing gains; feature subsampling can change both correlation and individual-tree strength.
The variance formula can be read directly from a small curve. For a fixed unit individual-prediction variance, the floor is the tree correlation, and more trees cannot remove variance that the trees share.
VisualizationOut [6]Expand

The predictions are step functions with jumps at the union of the training event times, so they have jumps rather than a smooth time derivative and supply no learned extrapolation beyond the largest observed event time. At that point the cumulative hazard is flat, the survival function is constant, and the model is silent about what happens next.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!