Joint subset, kernel and bandwidth selection for unpenalized GWR
Source:R/model-selection.R
gwr_select.RdCompares ordinary Gaussian GWR models on one frozen sample. All five criteria are reported; the selected criterion ranks eligible models. No coefficient penalty is fitted.
Usage
gwr_select(
formula,
data,
coords,
kernels = c("bisquare", "gaussian", "exponential", "tricube", "boxcar"),
bandwidth = "adaptive",
k = NULL,
bw = NULL,
criterion = "aicc",
search = c("exhaustive", "stepwise"),
required = character(),
include_ols = TRUE,
standardize = FALSE,
moran_weights = NULL,
moran_permutations = 999L,
moran_seed = 1L,
moran_row_standardize = TRUE,
moran_zero_policy = c("error", "keep"),
f_tests = TRUE,
max_models = 50000L,
max_evaluations = Inf,
memory_limit_mb = 512,
checkpoint = NULL,
resume = FALSE,
checkpoint_every = 25L,
dry_run = FALSE,
control = gwrs_control(),
verbose = interactive(),
local_inference = TRUE
)Arguments
- formula
Formula defining the response and full candidate scope. An intercept is required. Factors/multi-column terms are selected as groups.
- data
Data frame. Missing/nonfinite values in the full scope fail.
- coords
Coordinate matrix or two column names. Distances are Euclidean; use appropriate projected coordinates. No projection is performed.
- kernels
Candidate kernels supported by [gwr_fit()].
- bandwidth
"adaptive", "fixed", or both.
- k
Adaptive neighbor grid including the target. NULL searches all integers from p + 2 to n per subset (p excludes the intercept).
- bw
Fixed-distance grid. NULL uses 30 log-spaced values from the smallest positive interpoint distance to twice the largest distance.
- criterion
"aicc" (default), "aic", "bic", "gcv", or "loo_cv". "loo" aliases conditional LOO SSE.
- search
"exhaustive" or "stepwise". Stepwise is deterministic best-improvement addition/deletion after full-model and hierarchy-closed required-plus-single-term seeds. Every subset searches all requested kernels/bandwidths. It has no global optimum guarantee.
- required
Character term labels or a one-sided formula of required terms. Their interaction parents are also retained.
- include_ols
Compare corresponding OLS fits and, when no terms are required, intercept-only OLS. best_model is always GWR; best_overall can be OLS.
- standardize
Passed to [gwr_fit()]. FALSE preserves the input scale.
- moran_weights
Fixed numeric/sparse weight matrix in data row order, shared by all candidates. NULL reports Moran as not calculated.
- moran_permutations, moran_seed
Exploratory Moran permutation count/seed.
- moran_row_standardize
Row-standardize the supplied weights.
- moran_zero_policy
"error" rejects islands; "keep" retains all rows.
- f_tests
Compute conditional F1/F2/F3 diagnostics for valid GWR fits.
- max_models
Whole-search candidate cap. Oversized exhaustive designs fail before fitting. Stepwise stops explicitly incomplete at the cap.
- max_evaluations
New candidate cap for this invocation; resume can continue a provisional result. Inf means no invocation cap.
- memory_limit_mb
Workspace guard, not a hard process memory limit.
- checkpoint
New output directory for immutable checkpoint packs and a SHA-256 manifest. Requires the suggested package jsonlite.
- resume
Resume verified, data/settings/software-matching packs.
- checkpoint_every
Maximum number of new candidate records per pack.
- dry_run
Return design/resource bounds without fitting or testing.
- control
[gwrs_control()] settings. Selection always retains training data and standard diagnostics.
- verbose
Print progress every 30 seconds and at phase changes.
- local_inference
Compute exploratory local coefficient p-values and BH-adjusted p-values for the selected GWR only. TRUE by default. Candidate fits retain standard diagnostics; only the final selected GWR uses full diagnostics. FALSE skips this additional calculation.
Value
A gwrs_selection with best_model, best_overall, ranking, best_by_criterion, global_tests, coefficient_tests, candidate_diagnostics, local_inference, local_inference_status, settings, provenance and search_status. local_inference is a [gwr_local_inference()] result, or NULL if disabled/unavailable. No valid GWR gives best_model=NULL and status "no_valid_gwr". Incomplete searches are provisional. dry_run returns a gwrs_selection_plan.
Details
Adaptive Gaussian/exponential kernels retain only k neighbors, matching existing gwrs semantics; fixed-distance fits retain all n. Finite fixed grids do not guarantee a continuous-bandwidth optimum. Exact criterion ties prefer fewer design columns, OLS for overall ranking, larger bandwidths, then canonical kernel/subset order.
Eligibility requires full local predictor rank, direct converged solves, finite coefficients/predictions and positive residual effective df. Each criterion separately requires a finite value. CN > 30, VIF > 10, effective sample size at most the local parameter count, leverage > 0.99, or residual effective df < 5 are descriptive warnings, not exclusion gates or universal inferential cutoffs. All failures remain in the result.
F3 tests spatial variability, not zero coefficients. F references are moment-matched approximations; Moran uses total residual randomization. P-values are raw, exploratory and conditional, never ranking objectives or post-selection/multiplicity corrections. Conditional LOO fixes fitted weights/neighborhoods. Predictive claims require external/nested spatial validation repeating selection inside training folds.
Local coefficient p-values concern zero coefficients, not spatial constancy (F3). The default BH adjustment is separate for each coefficient across locations, including the intercept. Neither BH nor the local reference distribution accounts for response-based subset, kernel or bandwidth selection. These results are exploratory, not calibrated post-selection inference, and never affect ranking.
References
Gollini et al. (2015), doi:10.18637/jss.v063.i17 . Hurvich et al. (1998), doi:10.1111/1467-9868.00125 . Leung et al. (2000), doi:10.1068/a3162 .
Examples
set.seed(1401)
d <- data.frame(east = runif(24), north = runif(24),
x1 = rnorm(24), x2 = rnorm(24))
d$y <- 1 + (1 + d$east) * d$x1 + rnorm(24, sd = 0.5)
s <- gwr_select(y ~ x1 + x2, d, c("east", "north"),
kernels = c("bisquare", "gaussian"), k = c(16, 24),
f_tests = FALSE, control = gwrs_control(n_threads = 1))
s$best_by_criterion
summary(s)