Skip to contents

Tests whether models projected to past climates predict independent, dated occurrences, e.g. fossil or pollen records. Records have no true absences and each is matched to the climate of its own time, so instead of a classical AUC each record is compared with background cells of the same time slice:

Usage

temporal_validation(
  sites,
  background,
  model = "model",
  run = NULL,
  record = "record",
  slice = "slice",
  pred = "pred",
  period = NULL,
  novel = NULL,
  thresholds = NULL,
  combine = NULL,
  pool = NULL,
  n_boot = 0,
  conf = 0.95,
  compare = NULL,
  margin = 0,
  seed = NULL,
  prefix = "temporal",
  rescale = TRUE,
  weight = NULL
)

Arguments

sites

Long data.frame of predictions at the records: one row per record x time slice x model (x run), with the columns named by record, slice, model, pred and optionally run, period and novel.

background

Long data.frame of predictions at background cells: one row per cell x time slice x model (x run), with columns slice, model, pred (and run). Use the same cells in every slice and several hundred or more cells per slice.

model, run, record, slice, pred, period, novel

Column names. run (e.g. the cross-validation model or background set) is optional: when given, scores are computed per run and then averaged per model, with an SD. period must be constant within a record; novel is logical (TRUE = non-analog climate).

thresholds

Optional thresholds for sensitivity: a named numeric vector (names = models) or a data.frame with columns model, run (if used) and threshold.

combine

Optional named list of period groups, e.g. list(deep = c("Lateglacial", "Glacial")). Records of these periods are pooled (so periods with more records weigh more).

pool

How the runs are combined (only with run). TRUE: the records of all runs are pooled and every metric is computed over them, so each record counts once. FALSE: the metric is computed per run and the run values are averaged. NULL (default): pooled when no record is scored by more than one run of a model, i.e. out-of-fold evaluation where each record belongs to one cross-validation fold; there, averaging fold means would give a few records of a small fold as much weight as many records of a large one. Otherwise (e.g. every record scored by every run or background set) the run values are averaged. The _sd columns are always the SD across runs.

n_boot

Number of bootstrap resamples of the records (0 = none; 1000-2000 for final results). See Record bootstrap.

conf

Confidence level of the bootstrap intervals.

compare

The metric (output column) for the paired comparison between models, e.g. "fossil_AUC_deep". Default: the first combine group if given, otherwise <prefix>_AUC.

margin

Smallest difference to the best model that matters (in units of compare, e.g. 0.02). A model is flagged _worse only if its gap to the best is larger than margin in the lower bound of the paired interval. Set it before looking at the results.

seed

Optional random seed for the bootstrap.

prefix

Prefix of the output columns, e.g. "fossil" gives fossil_AUC.

rescale

Bring the predictions of each model to the 0-1 scale (0-100 or 0-1000 are divided by 100 or 1000, with a message; see extract_predictions()); thresholds given on the model's scale are divided by the same factor.

weight

Optional column of sites with the weight of each record-slice row, e.g. the probability of the slice from the dating of the record (age_slice_weights()); a record's score is then the weighted mean of its slice scores. NULL (default) weighs the slices of a record equally.

Value

A data.frame with one row per model: <prefix>_AUC, per-period and combined columns <prefix>_AUC_<period>, <prefix>_AUC_analog, <prefix>_sens, <prefix>_area, <prefix>_lift, <prefix>_n_records, and with run the SD of each metric across runs (_sd) and <prefix>_n_runs; with n_boot, the bootstrap columns (see Record bootstrap). Per-run results are in attr(x, "runs"), the per-record scores in attr(x, "records") and whether runs were pooled in attr(x, "pooled").

Details

  1. For every record and every time slice it falls into, the score is the proportion of background cells of that slice with lower predicted suitability (ties count half). 0.5 = random, 1 = the record is more suitable than every background cell.

  2. A record that spans several slices (e.g. a 1000-year bin covering ten 100-year climate slices) gets the mean of its slice scores, or, with weight, their weighted mean: the probability of each slice from the record's dating (age_slice_weights()), so that a record whose age is uncertain counts each plausible slice by how likely it is.

  3. The temporal AUC of a model is the mean over records. It equals the probability that a record is more suitable than a random background cell of its time, which is the definition of AUC.

Optionally the score is also given per period (e.g. Holocene, Lateglacial, Glacial) and for groups of periods (combine). Older periods are usually what hindcasts are about, while the far more numerous recent records dominate the overall mean. Further options: an "analog" score that ignores record-slices with climate outside the calibration range (novel, see outside_range()), and sensitivity, the share of records predicted above a present-day threshold (thresholds, see threshold_p10()), with the share of background predicted suitable (area) and their ratio (lift = sensitivity / area; 1 = no better than chance, so a model cannot gain sensitivity simply by predicting everything as suitable).

Uncertainty of fossil records. Fossils carry their own uncertainty: identification (a fossil taxon may not match the modern species concept), position, dating, and preservation and collection bias. Palaeoclimate simulations are model outputs too, and validating with records whose ages or ranges were inferred with the same climate model is circular. Treat the score as one line of evidence.

Record bootstrap

With a few hundred records, differences between models of a few hundredths may be noise. With n_boot > 0 the records are resampled with replacement, and the same resampled records are scored for every model, so the comparison is paired: a record that is hard for one model is usually hard for all, and a consistent gap shows up even when the intervals of the models overlap. Records are matched between models by their record id; each record's score is its pooled score (or its mean over runs, when runs are averaged). The output gains, for every metric, _lower and _upper (percentile interval), and for the compare metric:

  • <compare>_diff: the gap to the best model (best minus this model), with _diff_lower and _diff_upper (paired interval);

  • <compare>_p_best: share of resamples in which the model is the best;

  • <compare>_p_worse: share of resamples in which the best model is better than this one;

  • <compare>_worse: TRUE if the gap exceeds margin with the confidence conf (_diff_lower > margin).

A consistent gap is not necessarily an important one: with margin = 0 even tiny but consistent differences are flagged. Choose margin (the difference you would consider meaningful) before looking at the results. The replicates are in attr(x, "bootstrap").

References

Nogues-Bravo, D. (2009) Predicting the past distribution of species climatic niches. Global Ecology and Biogeography 18, 521-531. doi:10.1111/j.1466-8238.2009.00476.x

Examples

set.seed(1)
# 3 time slices, 500 background cells each, 40 records
bg <- expand.grid(cell = 1:500, slice = 1:3, model = c("good", "random"))
bg$pred <- runif(nrow(bg))
st <- expand.grid(record = 1:40, model = c("good", "random"))
st$slice <- sample(1:3, nrow(st), replace = TRUE)
st$pred <- ifelse(st$model == "good", rbeta(nrow(st), 5, 1),
                  runif(nrow(st)))
st$period <- ifelse(st$record <= 30, "Holocene", "Glacial")
temporal_validation(st, bg, period = "period", prefix = "fossil")
#>    model fossil_AUC fossil_AUC_Glacial fossil_AUC_Holocene fossil_n_records
#> 1   good    0.85260             0.8272           0.8610667               40
#> 2 random    0.48645             0.4280           0.5059333               40

# paired record bootstrap: is "random" really worse than "good"?
tv <- temporal_validation(st, bg, period = "period", prefix = "fossil",
                          n_boot = 200, margin = 0.02, seed = 1)
tv[c("model", "fossil_AUC", "fossil_AUC_lower", "fossil_AUC_upper",
     "fossil_AUC_diff", "fossil_AUC_p_best", "fossil_AUC_worse")]
#>    model fossil_AUC fossil_AUC_lower fossil_AUC_upper fossil_AUC_diff
#> 1   good    0.85260        0.8004713        0.8968362         0.00000
#> 2 random    0.48645        0.4085675        0.5740550         0.36615
#>   fossil_AUC_p_best fossil_AUC_worse
#> 1                 1            FALSE
#> 2                 0             TRUE