Similarity-Based Geographically Weighted Regression Models

Research software for modeling spatial heterogeneity through geographic proximity, attribute similarity, multiscale processes, and computationally efficient estimation.

Python Package

Reproducible implementation

Python implementations are available for both models: SGWR supports serial and parallel execution, while M-SGWR currently supports serial execution.

Software Implementation

The SGWR/M-SGWR software provides a graphical interface for estimating four local spatial regression models: SGWR, M-SGWR, GWR, and MGWR. Users begin by loading a CSV dataset containing coordinate fields, a dependent variable, and predictor variables. The X and Y coordinate fields are assigned under the coordinate section, and users specify whether the data are projected or spherical. Projected coordinates are appropriate when the data are already expressed in a planar coordinate system, while spherical coordinates are used for longitude and latitude.

Under the Model option, users can choose among the four supported models. SGWR combines geographic proximity and attribute similarity using a single bandwidth and a single α value. M-SGWR extends this framework by allowing predictor-specific bandwidths and α values, so different relationships can operate at different spatial and similarity scales. GWR represents the geographic-only version of SGWR, and MGWR represents the multiscale geographic-only version. When GWR or MGWR is selected, the software automatically fixes α at 1, meaning that only geographic proximity contributes to the weighting scheme.

The Model Type option specifies the statistical family used for estimation, such as Gaussian for continuous outcomes. The Kernel Function determines how nearby observations receive spatial weights; an adaptive bisquare kernel, for example, defines neighborhoods based on a varying number of nearby observations. Under Bandwidth Searching, users can either let the software optimize the bandwidth, such as through a Golden Section search, or provide a predefined bandwidth. The Optimization Criterion, such as AICc, determines how the software evaluates competing bandwidth or parameter choices.

For SGWR-based models, the Alpha option controls how geographic proximity and attribute similarity are balanced. Users can provide a predefined α or use an optimization strategy such as Divide and Conquer or another available search procedure. The Similarity Weight option determines how similarity between observations is quantified in attribute space. The Running Mode allows users to select serial or parallel computation, where supported, and specify the number of CPUs for faster processing.

After estimation, the software generates a summary text file containing the model configuration, runtime, global-model results, diagnostic statistics, bandwidth information, α values, goodness-of-fit measures, and summaries of local parameter estimates. A separate CSV file stores observation-level local coefficients and related outputs so users can map, compare, and further analyze spatially varying relationships.

SGWR software interface with data, model, optimization, and output controls
Figure. SGWR/M-SGWR software interface.
Additional resource

Further implementation details, including a video demonstration, are available on the Penn State GIScience website.

View implementation guide

Python Package Implementation

The SGWR Python package provides both sequential and MPI-parallel implementations. Before fitting the model, users should prepare point-based spatial data and import the required Python libraries. If the original dataset is polygon-based, point coordinates such as polygon centroids should first be generated because SGWR requires coordinates for distance calculations. In the sequential implementation, the principal inputs are the coordinate pairs (u, v), dependent variable y, predictor matrix X, and the predictor data used to construct the attribute-similarity weight matrix.

01

Sequential implementation

For the default adaptive bisquare kernel, initialize the joint bandwidth-and-alpha search and then pass the optimized parameters to the SGWR model:

Python · Adaptive bisquare kernel
selector = ALPHA((u, v), y, X, data)
BW, Alpha = selector.fit()

model = SGWR(
    (u, v),
    y,
    X,
    BW,
    data,
    Alpha
).fit()

The first step initializes the parameter-search procedure. The selector.fit() method jointly identifies the optimized bandwidth (BW) and alpha (Alpha). These optimized values are then passed to the SGWR model for final estimation.

02

Fixed Gaussian kernel

For a fixed Gaussian kernel, use the same implementation and specify the additional kernel arguments in both the search and estimation stages:

Python · Fixed Gaussian kernel
selector = ALPHA(
    (u, v),
    y,
    X,
    data,
    fixed=True,
    kernel="gaussian"
)

BW, Alpha = selector.fit()

model = SGWR(
    (u, v),
    y,
    X,
    BW,
    data,
    Alpha,
    fixed=True,
    kernel="gaussian"
).fit()
03

Model diagnostics

After fitting the model, common goodness-of-fit and model-comparison statistics can be obtained directly from the fitted model object:

Python · Diagnostic outputs
R2 = model.R2
Adj_R2 = model.adj_R2
AIC = model.aic
AICc = model.aicc
RSS = np.sum(model.resid_response ** 2)

These outputs provide the primary statistics needed to evaluate SGWR model fit and compare alternative model specifications.

04

Parallel MPI implementation

For larger datasets, the package provides an MPI implementation that distributes SGWR computations across multiple processors. Users must first install MPI and mpi4py. The input CSV must follow this column order:

longitudelatitudedependent variablepredictor 1predictor 2

The basic parallel command is:

Terminal · Basic execution
fastsgwr run -np x -data path_to_data

Here, x is the number of processors or CPU cores and path_to_data is the path to the input dataset. By default, the parallel implementation uses the adaptive bisquare kernel and does not standardize the variables.

05

Command-line options

Optional flags can be added to select the kernel, standardize variables, run conventional GWR, or access the earlier SGWR implementation:

Terminal · Optional configurations
# Fixed Gaussian kernel
fastsgwr run -np x -data path_to_data -fixed

# Standardize variables
fastsgwr run -np x -data path_to_data -standardize

# Run conventional GWR
fastsgwr run -np x -data path_to_data -gwr

# Fixed Gaussian kernel with standardization
fastsgwr run -np x -data path_to_data -fixed -standardize

# Access the earlier SGWR implementation
fastsgwr run -np x -data path_to_data -biga

The order of optional suffixes does not affect execution; for example, -fixed -standardize and -standardize -fixed are equivalent. After execution, the software prints key diagnostics, including R², adjusted R², and AICc, and saves the detailed model output as a CSV file in the input-data directory.

Citation references

  1. SGWR

    Lessani, M. N., & Li, Z. (2024). SGWR: Similarity and geographically weighted regression. International Journal of Geographical Information Science, 1–24. Access

  2. M-SGWR

    Lessani, M. N., Li, Z., Yu, M., Greatrex, H., & Shen, C. Multiscale Similarity and Geographically Weighted Regression (M-SGWR). Access

  3. FastSGWR

    Lessani, M. N., & Li, Z. (2025). Enhancing the computational efficiency of the SGWR model and introducing its software implementation. Annals of GIS, 1–16. Access