Constructs a specification of how a single distance family — environment or
geography — is filtered and weighted in an analog search. A kernel
bundles the per-family choices: the hard distance thresholds (max and
min), the weighting kernel shape (weight), that kernel's scale
parameter (theta), and the distance units they are expressed in
(units). Pass one to the env argument of analog_search()
and/or one to the geog argument.
Usage
kernel(
weight = NULL,
theta = NULL,
max = NULL,
min = NULL,
units = c("distance", "sigma")
)Arguments
- weight
Kernel shape for this family. One of
"uniform"(constant weight 1; the default whenNULL),"gaussian"(exp(-d^2 / (2 theta^2))), or"inverse"(1 / (1 + d / theta), a heavy-tailed inverse-distance kernel). The family (environmental vs geographic) is determined by whether the kernel is passed asenvorgeog, so the shape name is unqualified.- theta
Scale parameter for the
weightkernel. For"gaussian"it is the bandwidth (standard deviation); for"inverse"it is the half-weight distance (the weight is 1/2 atd = theta). Ignored for"uniform". Defaults toNULL, which lets downstream code apply a default of 1. Seekernel_params()for help choosing a value calibrated to a target coverage fraction.- max
Hard upper distance threshold for this family: candidates beyond
max(in this family's distance) are excluded.NULL(default) means no upper threshold. Usually a single radius. For the environmental family,maxmay also be a vector of per-variable absolute-difference thresholds (length equal to the number of environmental variables); the geographic family uses a single radius. Supplied to the search asmax_env/max_geog.- min
Hard lower distance threshold for this family: candidates closer than
min(in this family's distance) are excluded, so the retained candidates form an annulusmin <= d <= max. A single positive scalar, orNULL(default) for no lower threshold. Currently supported only for the geographic family; settingminon an environmental kernel is an error. The primary use case is buffered spatial cross-validation (e.g. viaanalog_cv()), where excluding geographically near-duplicate candidates around each focal gives a less optimistic estimate of predictive skill than plain leave-one-out. Supplied to the search asmin_geog.- units
Units of
theta,maxandmin:"distance"(default, the raw distance) or"sigma". Sigma units are environmental-only; see Details.
Value
An object of class "analog_kernel": a list with elements
weight, theta, max, min (each possibly NULL), and units.
Details
The overall kernel weight for a candidate is the product of the two
families' weights, so the families are specified independently and may use
different shapes (e.g. an inverse-distance environmental kernel together with a
Gaussian geographic kernel). A family with weight = "uniform" (or NULL)
contributes a constant weight of 1, i.e. it filters (if max/min are set)
but does not down-weight by distance.
All four components are optional. Which combinations are valid depends on
the operation and is checked by analog_search() downstream (for example,
climate velocity requires an environmental max; a weighted statistic requires a
non-uniform weight on at least one family). A bare NULL passed as the
env or geog argument is equivalent to kernel() with all components
unset: no threshold and no weighting for that family.
With units = "sigma", environmental distances are expressed as sigma
dissimilarity (Mahony et al. 2017): a Mahalanobis distance \(D\) over
\(k\) environmental variables becomes the one-dimensional distance with
the same chi-square percentile, \(\sigma = \sqrt{F^{-1}_{\chi^2_1}(
F_{\chi^2_k}(D^2))}\). theta and max are then read in sigma units, and
reported environmental distances (env_dist) are converted to sigma. For
\(k = 1\), sigma equals \(D\). The conversion assumes \(D\) is a
Mahalanobis distance: either supply focal-specific covariances via x_cov
(as in Mahony et al., who use local interannual variability), or whiten the
data first with mahalanobis_transform(). Sigma units cannot be combined
with per-variable max thresholds. To calibrate theta and max in sigma
units, use kernel_params() with d = 1.
References
Mahony CR, Cannon AJ, Wang T, Aitken SN (2017). "A closer look at novel climates: new methods and insights at continental to landscape scales." Global Change Biology, 23(9), 3934-3955. doi:10.1111/gcb.13645
Examples
# Environment: keep analogs within 2 environmental-distance units, Gaussian-weighted
kernel(weight = "gaussian", theta = 0.5, max = 2)
#> <analog_kernel>
#> weight: gaussian
#> theta: 0.5
#> max: 2
#> min: none
# Geography: hard 100 km cutoff, no distance weighting (uniform)
kernel(max = 100)
#> <analog_kernel>
#> weight: uniform
#> max: 100
#> min: none
# Geography: annulus keeping analogs between 5 km and 100 km of each focal
# (e.g. a 5 km buffer for spatial cross-validation)
kernel(max = 100, min = 5)
#> <analog_kernel>
#> weight: uniform
#> max: 100
#> min: 5
# Inverse-distance environmental weighting, no hard cutoff
kernel("inverse", theta = 1)
#> <analog_kernel>
#> weight: inverse
#> theta: 1
#> max: none
#> min: none
# Environment in sigma units: analogs within 2 sigma, Gaussian-weighted
kernel("gaussian", theta = 1, max = 2, units = "sigma")
#> <analog_kernel>
#> weight: gaussian
#> theta: 1
#> max: 2
#> min: none
#> units: sigma
