Constructs distribution-free prediction intervals for areal units (e.g. counties, census tracts, grid cells) using a leave-one-unit-out conformal procedure in which nonconformity scores are weighted by graph (neighbourhood) distance to the held-out unit, via its adjacency structure.
scp_areal(y, X = NULL, adjacency, pred_fun = NULL, alpha = 0.1, decay = 1)An object of class "spconform" (areal variant) with the
same structure as scp_geostatistical, using unit indices
in place of coordinates.
Numeric vector of observed responses, one per areal unit.
Optional numeric design matrix of covariates (one row per areal
unit); passed to pred_fun if supplied. May be NULL for
purely spatial (neighbourhood-based) prediction.
Square adjacency (contiguity) matrix describing the
neighbourhood structure among the length(y) areal units.
Non-zero entries are treated as neighbours (coerced to binary).
A function with signature function(y_train, X_train,
idx_train, idx_target, adjacency) returning a single numeric point
prediction for the areal unit indexed by idx_target, fitted
using the training units idx_train. If NULL (default), a
simple neighbourhood-mean predictor is used (the mean of y_train
over the target's graph neighbours, falling back to the global training
mean if the target has no observed neighbours).
Miscoverage level; intervals target \(1-\alpha\) coverage. Default 0.1.
Decay rate for neighbourhood weights; see
areal_neighbor_weights.
Uses a full leave-one-out (jackknife-style) conformal scheme: for each areal unit \(i\), a model is fit on all other units and used to predict unit \(i\); the resulting nonconformity scores across all units are combined into a graph-distance-weighted quantile specific to each target unit, so that the calibration set is dominated by spatially/graph-proximate units rather than treating all units as exchangeable.
If the effective neighbourhood weight for a target unit is vanishingly small (e.g., an isolated unit with no neighbours), the procedure falls back to an unweighted quantile over all other units and issues a warning.
set.seed(1)
n <- 25
adj <- matrix(0, n, n)
for (i in 1:(n - 1)) { adj[i, i + 1] <- 1; adj[i + 1, i] <- 1 }
y <- cumsum(rnorm(n)) + rnorm(n, sd = 0.2)
out <- scp_areal(y, adjacency = adj, alpha = 0.2)
print(out)
Run the code above in your browser using DataLab