Which distance measure should you use to compare time series?
Clustering population trends, classifying bird calls, checking a model against data: they all come down to measuring how different two time series are. There are dozens of ways to do it, and they don't agree.
Distance is a choice
A distance measure takes two time series and returns one number: 0 if they're identical, bigger the more they differ. Ecologists use them, often without noticing, to cluster similar population responses, assign recordings to species, flag anomalies like droughts, and score how close a model's predictions are to the data.
Most people reach for the Euclidean distance because it's familiar. But "different" can mean many things. Two population trends might differ because one starts higher, because one has a spike, because one is noisier, or because the same pattern happens a few years later. Each distance measure responds to these differences in its own way. Some barely notice a time shift; others treat it as a huge change. Some are thrown by a single outlier; others shrug it off.
We tested 42 distance measures, drawn from computer science, information theory and statistics, for 16 properties that matter in ecology, and turned the results into a way of choosing a measure that suits your data and question.
There is not always a right choice of distance measure, but there are wrong ones.
Distort a time series, watch the distances react
Pick a type of difference and drag the strength slider. The bars show how strongly each measure responds to that difference, relative to its strongest response to any of the nine distortions at the same strength. A full bar means "this is what this measure notices most". An empty bar means it barely notices at all.
Measures computed here: 13 of the 42 in the paper, implemented from their standard formulas (EDR with threshold 0.1). This is a live demonstration in the spirit of the paper's controlled tests, not a reproduction of its sensitivity scores, which are in the finder below.
Sixteen properties worth knowing
The paper groups them into four kinds. Whether you want a measure to be sensitive or insensitive to each one depends entirely on your question.
Find a measure for your task
The paper's selection method has three steps: use a decision tree to pick a category of measures, deal with any problems in the data, then filter by the properties that matter for your question. The finder below runs all three on the paper's test results for all 42 measures. Try the two presets from the paper's worked example first.
Five wading bird species, each with a 25-year breeding trend inside RSPB wet grassland reserves and a matched trend outside. Task: rank the species by how far the two trends diverge, as a measure of conservation impact (data from Jellesmark et al. 2021).
Step 1 · Category
Step 2 · Property filters
Values are the relative sensitivities shown in the paper's Figures 4–6, read from the published figures (rounded to one decimal place), so a value sitting exactly on a category boundary may be classed slightly differently from the original. Antiparallelism: N neutral, + positive, − negative. Non-positive values: "all" handles zeros and negatives, "zeros" handles zeros only, "none" handles neither.
With the noisy trends, only two measures, the K divergence and the Kullback–Leibler distance, pass the filters, and both rank the five species the same way as the original study's percentage-improvement method. After smoothing, seven measures pass, and all seven agree on one order: Redshank, Snipe, Lapwing, Curlew, Yellow Wagtail. Of the 40 measures not selected for the noisy trends, only two happened to give the original ranking. Pick a measure at random and you'll probably reach a different conclusion.
Common problems in ecological data
Step 2 of the method: most data problems can be solved either by pre-processing the data or by choosing a measure with the right property (paper, Table 1).
| Problem | Pre-processing solution | Properties-based solution |
|---|---|---|
| Missing data points | Interpolate missing values | Choose an elastic measure, which handles gaps by matching one point to none or to many |
| Different starting values, similar scales | Apply a translation shift | Choose a measure invariant (or sensitive) to translation |
| Different value scales | Normalize or standardize | – |
| Zeros or negative values | Transform to positive values | Choose a measure that handles non-positive values |
| Noise | Apply a smoothing algorithm (carefully: it can distort the series) | Choose a measure robust (or sensitive) to the kind of noise that matters |
| Out of phase | – | Choose a phase-invariant (or phase-sensitive) measure |
| Unequal lengths | Cut all series to the same length | Choose an elastic, model-based or compression-based measure |
| Different time scales | – | Choose a measure invariant (or sensitive) to uniform time scaling |
| Uneven sampling intervals | Interpolate intermediate values | Choose a measure that uses the time information, such as STS |
A few rules of thumb from the paper. Short, non-stationary series like most population trends suit shape-based measures. Elastic measures such as dynamic time warping (DTW) are the most versatile, and DTW is the standard for accuracy in classification, but it's slow on very large datasets and rarely used in ecology. Compression-based measures were unpredictable on the series tested; they're meant for series with thousands or millions of points. And as with any statistic, choose the measure up front for stated reasons. Trying several and keeping the one that gives the most convenient answer is cherry-picking.