Learn R Programming

mgwrsar (version 1.3.1)

search_bandwidths: Bandwidth Selection via Multi-round Grid Search based on AICc

Description

This function selects the optimal bandwidths (spatial and/or temporal) for GWR or MGWR models by minimizing the Corrected Akaike Information Criterion (AICc). It uses a multi-round grid search approach (coarse-to-fine) to efficiently narrow down the optimal parameter space before optionally applying a golden section search for final refinement.

Usage

search_bandwidths(
  formula,
  data,
  coords,
  fixed_vars = NULL,
  kernels = c("gauss", "gauss"),
  Model = "GWR",
  control = list(),
  hs_range = NULL,
  ht_range = NULL,
  n_seq = 10,
  ncore = 1,
  n_rounds = 0,
  refine = TRUE,
  verbose = FALSE,
  show_progress = FALSE,
  tol = NULL,
  parallel_method = "auto"
)

Value

A list containing:

mode

The mode of optimization ("spatial_only" or "spatio-temporal").

results

A list of data frames containing the results (bandwidths and AICc) for each round.

best

A data frame row corresponding to the best parameter combination found.

refined

The result of the refinement step (if refine = TRUE).

best_model

The final mgwrsar model object fitted with the optimal bandwidths.

ctime

The total computation time.

Arguments

formula

A formula object specifying the model (e.g., y ~ x1 + x2).

data

A data frame containing the variables in the model.

coords

A matrix or data frame of coordinates (2 columns for spatial, 1 for temporal, or more for GDT).

fixed_vars

A character vector indicating the names of variables with spatially stationary (fixed) coefficients. Default is NULL (all coefficients are varying).

kernels

A character vector specifying the kernel types for spatial and temporal components (e.g., c("gauss", "gauss")).

Model

A character string specifying the model type. Options include "GWR", "MGWR", "OLS", "SAR", etc. Default is "GWR".

control

A named list of extra control arguments passed to the MGWRSAR function (e.g., adaptive, NN, Z).

hs_range

A numeric vector of length 2 defining the lower and upper bounds for the spatial bandwidth search.

ht_range

A numeric vector of length 2 defining the lower and upper bounds for the temporal bandwidth search. Set to NULL for spatial-only models.

n_seq

An integer specifying the number of bandwidth candidates to test per dimension in each round.

ncore

An integer specifying the number of CPU cores to use for parallel processing. Default is parallel::detectCores() - 1.

n_rounds

An integer specifying the number of grid search rounds (zooming steps). Default is 3.

refine

Logical. If TRUE, a final optimization step using golden section search is performed around the best candidate found. Default is FALSE.

verbose

Logical. If TRUE, prints progress messages to the console.

show_progress

Logical. If TRUE, displays a progress bar during computation.

tol

A numeric vector of length 2 (or 1) specifying the tolerance for spatial and temporal bandwidths. If NULL, it is calculated automatically based on the range.

parallel_method

Parallelization method ("auto", "fork", "socket"); "auto" selects the best available backend depending on the OS, other values run sequentially.

Details

The function performs a grid search over n_rounds. In the first round, it tests n_seq candidates linearly or geometrically spaced within the provided ranges. In subsequent rounds, the search range is narrowed around the best candidate from the previous round.

See Also

MGWRSAR