Skip to content

LK006 — temporal_split

Test index dates that precede the training period's end.

default severity warning
injector ehrlint.inject.inject_lk006

Why this matters

A split described as temporal but not ordered in time reports an optimistic number: the model is evaluated on a period it was partly trained on, so it benefits from knowing the era's coding practices, formulary, and case mix.

What it looks like in practice

A random split described in the paper as temporal, or a temporal split taken on admission date while the index date is something else.

A note on severity

error when the task spec declares splits.temporal: true, warning otherwise. A declared property that does not hold is a broken claim; an undeclared one is a design question.

The query it runs

WITH train_max AS (
  SELECT MAX(index_date) AS t FROM index_dates
  WHERE subject_id IN train_split
)
SELECT * FROM index_dates WHERE subject_id IN test_split
  AND index_date < (SELECT t FROM train_max)

Worked example

On the clean synthetic cohort, which is clean by construction:

$ ehrlint audit --data clean/ --task task.yaml --checks LK006

LK006 did not fire.
  Every test index date falls at or after the training maximum (2019-11-30 02:57:48.704281).
exit code 0

With the matching leak planted by ehrlint.inject.inject_lk006:

$ ehrlint audit --data leaky/ --task task.yaml --checks LK006

LK006 temporal_split  [error]
  4 test subject(s) have an index date before the training period ends (2019-11-30 02:57:48.704281). The task spec declares this split temporal, so this invalidates it.
  affected: 4 of 28 subject(s) (14.3%), 4 row(s)

  example rows:
    subject_id  index_date                train_max_index_date    
    S000023     2018-01-12 05:51:36.9421  2019-11-30 02:57:48.7042
    S000035     2018-01-05 13:49:23.4206  2019-11-30 02:57:48.7042
    S000100     2018-01-05 18:58:23.7195  2019-11-30 02:57:48.7042

exit code 1

Reproduce both:

ehrlint synth --out clean/ --n-subjects 120 --seed 0
ehrlint synth --out leaky/ --n-subjects 120 --seed 0 --inject LK006
ehrlint audit --data leaky/ --task leaky/task.yaml \
  --labels leaky/labels.parquet --splits leaky/splits.json --checks LK006

What to do about it

Split on the same timestamp the task indexes on, and check the boundary rather than trusting the sort.

When it skips

A skip is not a pass. This check reports a skip, with the reason, when its inputs are not available — see reading a report.