Computes Gaussian-kernel spatial weights between a target location and a set of reference locations.
spatial_kernel_weights(
s0,
s,
bandwidth = NULL,
t0 = NULL,
t = NULL,
temporal_bandwidth = NULL
)A numeric vector of weights (not necessarily summing to one),
one per row of s, giving higher weight to reference points that
are spatially (and, if requested, temporally) closer to s0.
A numeric vector (or 1-row matrix) giving the coordinates of the target (prediction) location.
A numeric matrix of coordinates (one row per observation) for the reference (calibration) set.
Positive numeric bandwidth of the Gaussian kernel. If
NULL (default), the bandwidth is chosen automatically as the
median pairwise distance among s (Silverman-type rule).
Optional numeric scalar: time index of the target observation,
for spatio-temporal weighting. If supplied, t must be supplied too.
Optional numeric vector: time indices for the reference set,
same length as nrow(s).
Positive numeric bandwidth for the temporal
kernel; only used if t0/t are supplied. Defaults to the
spatial bandwidth logic applied to t.
Weights are computed as
$$w_i = \exp(-\|s_0 - s_i\|^2 / (2 h^2))$$
for the spatial-only case, and multiplied by an analogous temporal
kernel term when t0/t are provided. This is the core
device used to relax the exchangeability assumption required by
standard conformal prediction: observations located near the point to
be predicted contribute more to the calibration of the prediction
interval than distant ones (Mao, Martin and Reich, 2020).
set.seed(1)
s <- matrix(runif(20), ncol = 2)
s0 <- c(0.5, 0.5)
w <- spatial_kernel_weights(s0, s)
round(w, 3)
Run the code above in your browser using DataLab