
Search all variable sets that pass collinearity limits in every period and region
Source:R/variables_select.R
select_variables.RdA systematic, transparent alternative to picking predictors by hand from a correlation dendrogram. Every subset of the candidate variables is screened for collinearity in all data sets (e.g. the present and the past or future periods the model will be projected to) and, more leniently, inside regions; the sets that pass are scored on transferability, and the best trade-offs are reported, ranked, for you to choose from on ecological grounds.
Usage
select_variables(
x,
sizes = 3:6,
thr_r = 0.8,
thr_vif = 5,
regional = TRUE,
thr_r_regional = 0.85,
thr_vif_regional = 10,
min_region_n = 1000,
skip_regions = NULL,
screen_sets = NULL,
require_one_of = NULL,
targets = NULL,
gradient_pairs = NULL,
agreement = NULL,
criteria = NULL,
weights = NULL,
reference_sets = NULL,
n_mess = 1e+05,
use_common = TRUE,
max_subsets = 2e+06,
seed = 1
)Arguments
- x
An
env_samplefromsample_environment().- sizes
Set sizes to search.
- thr_r, thr_vif
Collinearity limits in the data sets.
- regional
Use the regions (if the sample has them) in the screen.
- thr_r_regional, thr_vif_regional
Softer limits inside regions.
- min_region_n
Regions with fewer sampled cells are ignored.
- skip_regions
Regions to leave out of the regional screen: region names (skipped in every data set) and/or
"data set | region"(as in theregionstable), e.g."LGM | Scandes"for a region that was under the ice at the Last Glacial Maximum.- screen_sets
Data sets used in the screen (default: all).
- require_one_of
Optional named list of variable groups; every set must contain at least one variable of each group. A group of a single variable forces that variable into every set, e.g.
list(heat = "gdd")for a predictor known to limit the species.- targets
Data sets whose novelty is scored (default: all but the reference).
- gradient_pairs
List of data-set pairs compared on common cells for gradient stability (default: the reference with each target).
- agreement
Optional pair of data sets of the same period from different sources.
- criteria
Named vector of the scores used for the Pareto front and the mean rank, with
"min"or"max". Default:novelty,gradient_min,agreement_min,worst_vif,regional_vif(scores that cannot be computed are left out).- weights
Optional named weights of the criteria in the mean rank.
- reference_sets
Optional named list of sets (e.g. your earlier choice) scored for comparison even if they fail the screen.
- n_mess
Target cells used for the novelty scores.
- use_common
Also screen the non-reference data sets on the common cells.
- max_subsets
Safety limit on the number of sets of one size that pass the pair check. Only such sets are enumerated (as cliques of the graph of compatible pairs), so the search stays exhaustive and fast when many variables are correlated, even if the number of all subsets is huge.
- seed
Seed for the subsample of cells (
n_mess) used for novelty.
Value
An object of class var_selection; see best_sets(),
plot_variable_tree(), plot_correlation(), plot_variable_sets() and
write_variable_selection(). Its elements: sets (all passing sets with
their scores, pareto, mean_rank and rank within the size; with
regions also regional_maxr, the largest |rho| of the set inside a
region, and worst_region, where it occurs),
counts (sets surviving each filter), pairs (each pair: rho per data
set, largest and smallest |rho|, the data set driving it, sign changes,
regional maximum and the region where it occurs (regional_driver),
compatible), regions (one row per data set and region, see
correlation_by_region()), variables (single-variable
properties and cluster), frequency (how often each variable appears in
passing, Pareto and top sets), reference_sets, consistency (the two
agreement data sets compared per variable), structure_agreement
(similarity of the correlation structure between data sets), tree,
rho and regional_rho.
Flagged variables. A top-ranked set containing a composite
variable flagged in climate_index_names() (bio8, bio9, bio18, bio19,
sri, synchronicity: temperature and precipitation over a period that
switches between cells) gives a warning (Booth 2022).
Details
Screen. A pair of variables is compatible when its |Spearman rho| is
below thr_r in every data set (own cells and, for the non-reference data
sets, the common cells) and below thr_r_regional in every region. A set
passes when all its pairs are compatible, its rank-based VIF is at most
thr_vif in every data set and thr_vif_regional in every region, and it
contains at least one variable of each group in require_one_of (e.g. a
temperature and a moisture variable). Because the dendrogram ("union tree"
of the largest |rho| over the data sets, complete linkage) puts every pair
with |rho| >= thr_r in one cluster, a passing set never holds two
variables of one cluster: choosing "one variable per cluster" is contained
in this search, but the pair check that cutting the tree alone does not
guarantee is enforced.
Scores (for each passing set):
novelty: the share of cells of the target data sets (default: all but the reference) outside the reference conditions, by the multivariate environmental similarity surface (MESS < 0; Elith et al. 2010); the worst target counts, the others are innovelty_<target>. Lower is better: less extrapolation.gradient_min: the weakest rank correlation, between the paired data sets on the same cells, of any member: does each variable keep its spatial pattern through time? Higher is better.agreement_min: withagreement = c(a, b)(two data sources for the same period, e.g. CHELSA and TraCE21k present), the weakest agreement of any member. Higher is better.worst_vif,regional_vif: the largest rank-based VIF over the data sets and over the regions. Lower is better.
There is no hand-made total score: within each set size the Pareto front (sets no other set beats on all criteria) is marked and a transparent mean rank over the criteria orders the sets.
What the result means. A passing set meets the chosen collinearity
limits; its variables are not statistically independent, and no limit
marks the point where collinearity starts to matter: that depends on the
algorithm and on whether coefficients are interpreted. The VIF is computed
on ranks (Spearman), separately in every data set (period, scenario) and
in every region, and the worst value counts; it is not the VIF of the raw
variables in one data set. gradient_min and agreement_min describe the
environmental data, not the species: a variable that keeps its spatial
pattern may still matter less to the species elsewhere or later. The
ranking is a shortlist; choose among the sets on ecological grounds, and
prefer a set with a clear ecological rationale over a slightly better-
scoring one without.
Status. A preENM method; the collinearity limits follow common practice (Dormann et al. 2013).
References
Booth, T.H. (2022) Checking bioclimatic variables that combine temperature and precipitation data before their use in species distribution models. Austral Ecology 47, 1506-1514. doi:10.1111/aec.13234
Elith, J., Kearney, M., Phillips, S. (2010) The art of modelling range-shifting species. Methods in Ecology and Evolution 1, 330-342. doi:10.1111/j.2041-210X.2010.00036.x
Dormann, C.F., Elith, J., Bacher, S., et al. (2013) Collinearity: a review of methods to deal with it and a simulation study evaluating their performance. Ecography 36, 27-46. doi:10.1111/j.1600-0587.2012.07348.x
Examples
sim <- simulate_enm_data(seed = 1)
e1 <- sim$env[["env1"]]
e2 <- sim$env[["env2"]]
now <- c(e1, e2, e1 + e2 + 0.05 * e1 * e2, e1 * e2, sqrt(e2))
names(now) <- c("t", "p", "tp", "txp", "sp")
past <- now - 0.2 * now[["t"]]
names(past) <- names(now)
es <- sample_environment(list(present = now, past = past), n = 3000,
seed = 1, verbose = FALSE)
vs <- select_variables(es, sizes = 2:3)
#> Criteria not available for these data (left out): agreement_min, regional_vif
best_sets(vs)
#> set n_vars rank mean_rank pareto novelty gradient_min worst_vif
#> 1 t tp 2 1 2.000000 TRUE 0.01266667 0.9926087 1.962357
#> 2 t p 2 2 2.833333 TRUE 0.12733333 0.9813521 1.038187
#> 3 t sp 2 3 3.166667 TRUE 0.05700000 0.9682347 1.062034
#> 4 p tp 2 4 4.000000 FALSE 0.11500000 0.9813521 1.962517
#> 5 tp sp 2 4 4.000000 FALSE 0.04466667 0.9682347 1.962517
#> worst_maxr
#> 1 0.7002919
#> 2 0.1917866
#> 3 0.2416826
#> 4 0.7003216
#> 5 0.7003216