A modern, first implementation of Geographically Weighted Panel Regression (GWPR) for spatial panel data. The package provides a unified public API supporting Gaussian and binomial family models, within/pooling/random panel effects, three bandwidth search strategies (grid, Stochastic Gradient Descent, random), five kernel functions, and optional parallel execution via the 'future' framework. Diagnostic tools include spatial Moran's I, local F-test, Hausman test, and Lagrange Multiplier test.
A modern, sf-first implementation of Geographically Weighted Panel
Regression (GWPR) for spatial panel data. Version 1.0.0 provides a
clean public API, three bandwidth search strategies (grid, SGD, random),
Gaussian and binomial model families, and optional parallel execution
via the future framework.
Chao Li [email protected]
Shunsuke Managi [email protected]
Install the released version from CRAN:
install.packages("GWPR.light")
Or install the development version from GitHub:
# install.packages("remotes")
remotes::install_github("MichaelChaoLi-cpu/GWPR.light")
The four public functions form the complete interface:
| Function | Purpose |
|---|---|
gwpr() |
Full pipeline: bandwidth search + fit + diagnostics |
select_bandwidth() |
Standalone bandwidth optimisation |
fit_gwpr() |
Fit with a known bandwidth |
diagnose_gwpr() |
Diagnostic tests on a fitted model |
library(GWPR.light)
library(sf)
# --- Simulate a small spatial panel ---
set.seed(1)
pts <- sf::st_as_sf(
data.frame(id = 1:6, X = c(0,1,2,0,1,2), Y = c(0,0,0,1,1,1)),
coords = c("X", "Y"), crs = NA_integer_
)
dat <- data.frame(
id = rep(1:6, each = 4),
time = rep(1:4, 6),
x1 = rnorm(24),
x2 = rnorm(24)
)
dat$y <- 1.5 * dat$x1 - 0.8 * dat$x2 + rnorm(24, sd = 0.3)
# --- Fit with a known bandwidth ---
fit <- fit_gwpr(
y ~ x1 + x2, data = dat, spatial = pts,
id = "id", time = "time",
bandwidth = 2, model = "pooling", workers = 1
)
print(fit)
bw <- select_bandwidth(
y ~ x1 + x2, data = dat, spatial = pts,
id = "id", time = "time",
method = "grid",
control = list(lower = 0.5, upper = 3, step = 0.5),
workers = 1
)
cat("Optimal bandwidth:", bw$best_bandwidth, "\n")
diag_result <- diagnose_gwpr(fit, diagnostics = c("f_test", "hausman"))
print(diag_result)
vignette("gwpr-introduction") — Getting started with the 1.0.0 APIvignette("introduction_of_GWPR") — Legacy 0.2.x API reference