Skip to contents

A realistic set of projections varies at the same time in climate model (GCM), emission scenario, modelling algorithm and cross-validation run (or any other factors). partition_uncertainty() splits, in every cell, the variance of the projected suitability among these factors, so you can see which choice matters most, and where.

Usage

partition_uncertainty(
  projections,
  design,
  region = NULL,
  filename = NULL,
  overwrite = FALSE,
  rescale = TRUE,
  pattern = "\\.tif{1,2}$",
  recursive = FALSE,
  seed = 1
)

Arguments

projections

Projection rasters: a terra::SpatRaster with one layer per projection, or raster files and/or folders (as in ensemble_models()). All on the same grid.

design

A data.frame with one row per projection (in the order of the layers, or with a column layer naming them) and one column per factor, e.g. gcm, scenario, algorithm, run.

region

Optional part of the area for a second set of summaries: polygons (sf, SpatVector) or a raster (cells that are not NA and not 0), as in transfer_bias_test().

filename

Optional GeoTIFF for the result.

overwrite

Overwrite filename.

rescale

Bring every projection to the 0-1 scale (layers on 0-100 or 0-1000 are divided by 100 or 1000, with a message); see extract_predictions().

pattern, recursive

File search in folders.

seed

Seed for the cell sample used to recognise the scales.

Value

A list of class uncertainty_partition: raster (a terra::SpatRaster with one share layer per factor, share_residual for interactions and residual, variance (the total variance between projections) and dominant (the factor with the largest share, categorical)), shares (the shares pooled over the area and, with region, over the region, each cell weighted by its variance, and the share of cells each factor dominates), factors, balanced, design and scales.

Details

Method. For each cell, the projections are the response of a linear model with the factors as main effects, as in an analysis of variance; the variance explained by each factor (its sum of squares divided by the total sum of squares) is its share. What the main effects do not explain (interactions between factors, and replicate noise) is reported as interactions/residual. The shares sum to 1 in every cell. This is the variance partitioning used for climate projections (Hawkins and Sutton 2009) and their ecological consequences (Wilson et al. 2024).

  • With a balanced design (every combination of levels equally often) the factors are independent and the shares do not depend on their order. Otherwise sequential (type I) sums of squares are used, in the order of the columns of design, and a warning says that the shares then depend on that order.

  • The share of scenario depends on which scenarios are included: it describes the spread between the chosen futures, not an error, so it cannot be compared directly with the share of climate models (Wilson et al. 2024).

  • Shares are relative: where the projections hardly differ, a large share of a tiny variance means little. The variance layer and the pooled shares (each cell weighted by its variance) show where the variance is.

The rasters are read and written block by block, so stacks larger than memory work.

References

Wilson, R.J., Kay, S., Ciavatta, S. (2024) Partitioning climate uncertainty in ecological projections: Pacific oysters in a hotter Europe. Ecological Informatics 80, 102537. doi:10.1016/j.ecoinf.2024.102537

Hawkins, E., Sutton, R. (2009) The potential to narrow uncertainty in regional climate predictions. Bulletin of the American Meteorological Society 90, 1095-1108. doi:10.1175/2009BAMS2607.1

Examples

# 2 GCMs x 2 scenarios x 3 algorithms
sim <- simulate_enm_data(seed = 1)
base <- sim$models[[c("GLM", "GBM", "Maxent_LQ")]]
design <- expand.grid(algorithm = names(base), gcm = c("A", "B"),
                      scenario = c("ssp1", "ssp5"),
                      stringsAsFactors = FALSE)
proj <- terra::rast(lapply(seq_len(nrow(design)), function(i) {
  d <- design[i, ]
  shift <- 0.05 * (d$gcm == "B") + 0.15 * (d$scenario == "ssp5")
  terra::clamp(base[[d$algorithm]] - shift, 0, 1)
}))
pu <- partition_uncertainty(proj, design)
pu
#> Uncertainty partition: 12 projections; factors algorithm, gcm, scenario
#> 
#> IN SHORT
#> - Across the area, the choice of algorithm explains most of the variance in
#>   predicted suitability (64%), followed by scenario (31%), gcm (3%),
#>   interactions/residual (1.0%). algorithm is the largest source in 50% of
#>   the cells.
#> - The share of scenarios depends on which scenarios were chosen: it is the
#>   spread between the futures considered, not an error, and is not directly
#>   comparable with the share of climate models (Wilson et al. 2024).
#> 
#> Shares (pooled, each cell weighted by its variance):
#>  scope                source share dominant_cells dominant_share median_sd
#>   area             algorithm   64%           2407            50%     0.107
#>   area                   gcm    3%              0             0%     0.107
#>   area              scenario   31%           2278            47%     0.107
#>   area interactions/residual  1.0%            115             2%     0.107
#> 
#> share = sum of squares of a factor / total sum of squares, from a linear
#> model with the factors as main effects (as in an analysis of variance);
#> interactions/residual = the rest. dominant = the source with the largest
#> share in a cell. The 0.02 limit of the standard deviation is a preENM
#> default, not from the literature.
#> 
#> A preENM sensitivity analysis: how much the result depends on the data,
#> algorithm, climate model and scenario. The others are listed in
#> ?sensitivity_analyses.
plot_partition(pu)