---
kind: concept
slug: nested-case-control-sampling
title: Nested case-control sampling
summary: >-
  Replaces the full risk-set sum in a survival likelihood with one control drawn per event, so the loss can be trained on mini-batches. The paper reports that one control stays close to the exact likelihood on simulations, and that more controls lower training error at higher compute cost.
tags: [survival-analysis, case-control-sampling, sampling]
papers: ["1907.00825"]
related: [cox-proportional-hazards]
status: draft
updated_at: 2026-10-18
---

## Overview

A survival likelihood compares each event with everyone still at risk at that
moment. For large data sets that sum is expensive and does not batch
[arxiv:1907.00825 §3.2]. The sampling idea keeps the comparison but draws a
small set of controls from the risk set for each event, so the loss touches
only a few individuals per event [arxiv:1907.00825 §3.2]. The invariant every
variant keeps is that each event is paired with at least one control drawn
from the risk set at the event time, and the pair loss is
log(1 + exp(difference of risk scores)) [arxiv:1907.00825 §3.2] [eq. 9].

## Variants

### One sampled control per event

Draw one control j for each event i and average log(1 + exp[g(x_j) - g(x_i)])
over events [arxiv:1907.00825 §3.2] [eq. 8] [eq. 9]. Controls are drawn with
replacement, and a new control is drawn in every iteration
[arxiv:1907.00825 §3.2]. Because the loss has no unique minimiser for a
non-linear g, the paper adds lambda times the sum of |g| over the sampled
outputs [arxiv:1907.00825 §3.3] [eq. 10]. The paper's own experiments use
lambda in {0.1, 0.01, 0.001, 0} [arxiv:1907.00825 app. A.1]. Card:
[Time-to-Event Prediction with Neural Networks and Cox Regression](/papers/1907.00825).

On simulated data, one control gives a mean log-likelihood gap of about 0.1 %
to the exact partial likelihood on the smallest sets [arxiv:1907.00825 §5]
[arxiv:1907.00825 fig. 3].

### Sampled control with time as an input

The network receives time as a covariate. Each event i is paired with a
control j drawn from its risk set, and both are evaluated at the event time
T_i [arxiv:1907.00825 §3.4] [eq. 12]. The sampled set has fixed size, so the
cost per epoch is O(n) rather than O(n^2) for the full risk set
[arxiv:1907.00825 §3.4]. Card: [Time-to-Event Prediction with Neural Networks and Cox Regression](/papers/1907.00825).

### Full risk set for the baseline

Sampling is used only for training. The Breslow increments at each distinct
event time sum over the full risk set [arxiv:1907.00825 §3.5] [eq. 13]. The
paper allows a random subset of training rows to estimate the baseline, at
the price of a coarser time grid and no error analysis
[arxiv:1907.00825 §3.5]. Card: [Time-to-Event Prediction with Neural Networks and Cox Regression](/papers/1907.00825).

### Number of controls per event

The simulations compare 1, 2, 4 and 8 controls [arxiv:1907.00825 §5]. More
controls give lower training error, but the convergence speed does not change
and the computation grows with the number of controls [arxiv:1907.00825 fig. 1]
[arxiv:1907.00825 §5]. Card: [Time-to-Event Prediction with Neural Networks and Cox Regression](/papers/1907.00825).

## When to use which

| Situation | Use | Why |
|---|---|---|
| Large data set, neural risk term, mini-batch training | One sampled control per event | The loss needs only sampled individuals, not a full risk-set sum [arxiv:1907.00825 §3.2] |
| Mini-batch training and covariate effects may change over time | Sampled control with time as an input | Drops proportional hazards and keeps the O(n) cost per epoch [arxiv:1907.00825 §3.4] |
| Need survival curves at many times | Time as input, plus Breslow baseline | Each curve needs one network call per distinct event time up to the horizon [arxiv:1907.00825 §3.5] |
| Tight prediction latency, many individuals | A time-independent risk term | Cumulative hazard factorises into a baseline times exp[g(x)] [arxiv:1907.00825 §3.5] |
| Training error matters more than compute per step | More controls per event | Lower training error; cost grows with controls [arxiv:1907.00825 fig. 1] |

The number of controls is varied only in the simulations [arxiv:1907.00825 §5].
The real-data tables compare whole models, not control counts
[arxiv:1907.00825 tab. 2] [arxiv:1907.00825 tab. 7].

## Implementation sketch

The common core is the pair loss over one sampled control per event. Pseudocode
follows the paper's equations; the case-inclusion question is in
Contradictions.

```pseudocode
# Sampled-control loss for one mini-batch of events  [arxiv:1907.00825 §3.2]
# Input:  g (network on covariates); x_case (B, d); risk_sets per event
# Output: scalar loss

def sampled_control_loss(g, x_case, risk_sets, lam):
    # Draw one control per event from its risk set, with replacement  [§3.2]
    x_ctrl = sample_one_per_row(risk_sets)
    g_case = g(x_case)
    g_ctrl = g(x_ctrl)
    # Pair loss, averaged over events  [eq. 9] [eq. 8]
    loss = mean(log(1 + exp(g_ctrl - g_case)))
    # Penalty on sampled outputs, pulls them toward 0  [eq. 10]
    return loss + lam * (sum(abs(g_case)) + sum(abs(g_ctrl)))
```

For the time-as-input variant, evaluate both members of each pair at the
event time T_i and feed the time to the network [arxiv:1907.00825 §3.4]
[eq. 12]. For the baseline, sum over the full risk set at each distinct event
time [arxiv:1907.00825 §3.5] [eq. 13].

## Contradictions

- The sampled set is said to include the event individual itself
  [arxiv:1907.00825 §3.2], but eq. 9 draws the control from the risk set without
  that individual [arxiv:1907.00825 eq. 9]. The paper does not resolve this.
  Excluding the case is the cleaner reading of eq. 9, but the paper does not
  say which one its experiments used.

## Papers

- [Time-to-Event Prediction with Neural Networks and Cox Regression](/papers/1907.00825): introduces a sampled-control loss for a neural Cox model, and a time-as-input variant that drops proportional hazards.
