| Title: | Geographically Weighted Panel Regression |
|---|---|
| Description: | 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. |
| Authors: | Chao Li [aut, cre] (ORCID: <https://orcid.org/0000-0002-6854-4456>), Shunsuke Managi [aut] (ORCID: <https://orcid.org/0000-0001-7883-1427>) |
| Maintainer: | Chao Li <[email protected]> |
| License: | AGPL (>= 3) |
| Version: | 1.0.0 |
| Built: | 2026-05-30 07:22:54 UTC |
| Source: | https://github.com/michaelchaoli-cpu/gwpr.light |
High-level user-facing functions for Geographically Weighted Panel Regression. These four functions form the complete public interface; all internal complexity is hidden behind them.
gwpr – full pipeline (bandwidth search + fitting +
optional diagnostics).
select_bandwidth – standalone bandwidth search.
fit_gwpr – fit with a known bandwidth.
diagnose_gwpr – run diagnostics on a fitted model.
The counties' boundary in California
data(California)data(California)
An sf object with 58 rows (one per county) and two columns:
a numeric vector, fips IDs of the counties
sfc_MULTIPOLYGON, county boundary polygons (CRS: NAD83 longlat)
Chao Li <[email protected]> Shunsuke Managi <[email protected]>
data(California) class(California)data(California) class(California)
Top-level interface that dispatches to individual diagnostic sub-functions. Returns a 'gwpr_diagnostics' object containing all requested test results.
diagnose_gwpr( object, diagnostics = c("moran", "f_test", "hausman", "lm_test"), spatial_weights = NULL, panel_index = NULL, ... )diagnose_gwpr( object, diagnostics = c("moran", "f_test", "hausman", "lm_test"), spatial_weights = NULL, panel_index = NULL, ... )
object |
A 'gwpr_fit' object returned by 'fit_gwpr()' or similar. |
diagnostics |
Character vector naming the tests to run. Any subset of 'c("moran", "f_test", "hausman", "lm_test")'. Default is all four. |
spatial_weights |
Required when '"moran"' is in 'diagnostics'. A row-standardised n x n spatial weights matrix. |
panel_index |
Required when '"moran"' is in 'diagnostics'. A data.frame with columns 'id' and 'time' identifying each element of 'object$residuals'. |
... |
Additional arguments passed to individual diagnostic functions. |
Tests that are not applicable to the fitted model (e.g., Hausman test on a pooling model) return a list with 'status = "not_applicable"' and an explanatory 'message', rather than an error.
A 'gwpr_diagnostics' object (list with class '"gwpr_diagnostics"') whose 'diagnostics' slot contains the result of each requested test.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diag_result <- diagnose_gwpr(fit, diagnostics = c("f_test", "hausman")) print(diag_result)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diag_result <- diagnose_gwpr(fit, diagnostics = c("f_test", "hausman")) print(diag_result)
Performs a local Hausman test (within vs. random) for each spatial unit using test statistics pre-computed during model fitting or stored in 'local_results'.
diagnose_hausman(object, ...)diagnose_hausman(object, ...)
object |
A 'gwpr_fit' object. |
... |
Currently ignored. |
**Applicable models**: gaussian with 'model = "random"'. For pooling models the Hausman test is not meaningful; the function returns a 'status = "not_applicable"' result. For logistic models the function also returns 'status = "not_applicable"'.
**Panel balance requirement**: No constraint at the unit level.
**Failure conditions**: Returns 'status = "missing_hausman_data"' for any unit where the required statistics are absent from 'local_results'.
**Logistic interpretation limit**: Not applicable.
A named list with elements:
Data frame with columns 'unit_id', 'statistic', 'p_value', 'df', 'status'.
Number of units tested.
Number of units where the test could not be computed.
Overall status: '"ok"', '"not_applicable"', or '"no_local_results"'.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diagnose_hausman(fit)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diagnose_hausman(fit)
Performs a local Breusch-Pagan Lagrange Multiplier test for random effects for each spatial unit using test statistics stored in 'local_results'.
diagnose_lm(object, ...)diagnose_lm(object, ...)
object |
A 'gwpr_fit' object. |
... |
Currently ignored. |
**Applicable models**: gaussian with 'model = "pooling"' or 'model = "random"'. For 'within' models the test is not directly applicable (it tests for random effects vs. OLS); the function returns 'status = "not_applicable"'. For logistic models also not applicable.
**Panel balance requirement**: No constraint at the unit level.
**Failure conditions**: Returns 'status = "missing_lm_data"' for units missing the required statistics.
**Logistic interpretation limit**: Not applicable.
A named list with elements:
Data frame with columns 'unit_id', 'statistic', 'p_value', 'df', 'status'.
Number of units tested.
Number of units where the test could not be computed.
Overall status.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diagnose_lm(fit)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diagnose_lm(fit)
Performs a local F test (fixed effects vs. pooling) using per-unit local residuals stored in the fitted model object.
diagnose_local_f(object, ...)diagnose_local_f(object, ...)
object |
A 'gwpr_fit' object. |
... |
Currently ignored. |
**Applicable models**: gaussian (linear). Not applicable to logistic models; returns a 'status = "not_applicable"' result when 'family = "binomial"'.
**Panel balance requirement**: No constraint; the test uses per-unit local residuals already computed during fitting.
**Failure conditions**: If 'local_results' is empty or missing, all units are reported as failed. If a unit's local result does not contain the information needed (within and pooling residuals), that unit is reported as failed with an informative 'status'.
**Logistic interpretation limit**: Not applicable; see above.
A named list with elements:
Data frame with columns 'unit_id', 'statistic', 'p_value', 'df1', 'df2', 'status'.
Number of units tested.
Number of units where the test could not be computed.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diagnose_local_f(fit)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diagnose_local_f(fit)
Extracts residuals from a fitted GWPR model (Pearson residuals for logistic models, raw residuals for linear models) and computes the panel Moran's I statistic.
diagnose_moran(object, spatial_weights, panel_index, ...)diagnose_moran(object, spatial_weights, panel_index, ...)
object |
A 'gwpr_fit' object returned by 'fit_gwpr()' or similar. |
spatial_weights |
A row-standardised n x n spatial weights matrix. 'n' must equal the number of spatial individuals in the fitted model. |
panel_index |
A data.frame or list with columns/elements 'id' and 'time' that identify each element of 'object$residuals'. |
... |
Currently ignored. |
**Applicable models**: gaussian (linear residuals) and binomial (Pearson residuals).
**Panel balance**: See 'compute_panel_moran()'.
**Failure conditions**: Fails if 'object' is not a 'gwpr_fit', if 'object$residuals' is 'NULL', or if 'spatial_weights' dimensions do not match the number of individuals.
**Logistic interpretation limit**: Moran's I computed on Pearson residuals is exploratory; the asymptotic distribution differs from the linear case.
A named list compatible with the 'diagnostics' slot of a 'gwpr_diagnostics' object. Contains the elements returned by 'compute_panel_moran()' plus 'residual_type'.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) W <- matrix(1/3, nrow = 4, ncol = 4); diag(W) <- 0 idx <- dat[, c("id", "time")] diagnose_moran(fit, W, idx)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) W <- matrix(1/3, nrow = 4, ncol = 4); diag(W) <- 0 idx <- dat[, c("id", "time")] diagnose_moran(fit, W, idx)
Unified diagnostic interface for Geographically Weighted Panel Regression models. Provides Moran's I (spatial autocorrelation), local F test (fixed vs. pooling), local Hausman test (fixed vs. random), and local Breusch-Pagan LM test.
**Model applicability**
| Diagnostic | Linear | Logistic | Notes | |————–|——–|———-|——————————————–| | moran | yes | yes | Logistic uses Pearson residual | | f_test | yes | no | Requires within and pooling models | | hausman | yes | no | Only meaningful for random-effect models | | lm_test | yes | no | Pooling or random-effect models |
**Panel balance**
'compute_panel_moran()' is fully supported for balanced panels. For unbalanced panels a 'warning()' is issued and the function attempts computation using only the time periods present in every individual; results may be unreliable.
**Logistic interpretation**
Moran's I computed from Pearson residuals of a Logistic model does not follow the same asymptotic distribution as for linear models. Treat the test result as an exploratory heuristic, not a formal test.
Validates inputs, prepares data, builds spatial weights, and fits the
Geographically Weighted Panel Regression for the specified bandwidth.
Returns a gwpr_fit object.
fit_gwpr( formula, data, spatial, id, time, bandwidth, family = c("gaussian", "binomial"), model = c("within", "pooling", "random"), effect = c("individual", "time", "two-way", "nested"), kernel = c("bisquare", "gaussian", "exponential", "tricube", "boxcar"), adaptive = FALSE, threshold = 0.5, workers = 1L, seed = NULL, ... )fit_gwpr( formula, data, spatial, id, time, bandwidth, family = c("gaussian", "binomial"), model = c("within", "pooling", "random"), effect = c("individual", "time", "two-way", "nested"), kernel = c("bisquare", "gaussian", "exponential", "tricube", "boxcar"), adaptive = FALSE, threshold = 0.5, workers = 1L, seed = NULL, ... )
formula |
A |
data |
A |
spatial |
An |
id |
Character scalar; unit ID column name. |
time |
Character scalar; time column name. |
bandwidth |
Numeric scalar. The bandwidth to use (fixed distance or
number of neighbours when |
family |
|
model |
|
effect |
|
kernel |
Kernel function name (default |
adaptive |
Logical; |
threshold |
Numeric; classification threshold (binomial only,
default |
workers |
Positive integer; number of parallel workers (default 1). |
seed |
Integer random seed, or |
... |
Currently unused. |
A gwpr_fit object.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) print(fit)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) print(fit)
Orchestrates the complete GWPR pipeline: input validation, data preparation, optional memory estimation, optional bandwidth search, model fitting, and optional diagnostics.
gwpr( formula, data, spatial, id, time, family = c("gaussian", "binomial"), model = c("within", "pooling", "random"), effect = c("individual", "time", "two-way", "nested"), bandwidth = NULL, bandwidth_method = c("sgd", "grid", "random"), bandwidth_control = list(), kernel = c("bisquare", "gaussian", "exponential", "tricube", "boxcar"), adaptive = FALSE, threshold = 0.5, workers = 1L, seed = NULL, diagnostics = TRUE, ... )gwpr( formula, data, spatial, id, time, family = c("gaussian", "binomial"), model = c("within", "pooling", "random"), effect = c("individual", "time", "two-way", "nested"), bandwidth = NULL, bandwidth_method = c("sgd", "grid", "random"), bandwidth_control = list(), kernel = c("bisquare", "gaussian", "exponential", "tricube", "boxcar"), adaptive = FALSE, threshold = 0.5, workers = 1L, seed = NULL, diagnostics = TRUE, ... )
formula |
A |
data |
A |
spatial |
An |
id |
Character scalar. Name of the unit (individual) ID column shared
by |
time |
Character scalar. Name of the time-period column in |
family |
Character scalar. Model family: |
model |
Character scalar. Panel model type: |
effect |
Character scalar. Panel effect: |
bandwidth |
Numeric scalar or |
bandwidth_method |
Character scalar. Method for automatic bandwidth
search: |
bandwidth_control |
Named list of control parameters passed to the
bandwidth search function. For |
kernel |
Character scalar. Kernel function: |
adaptive |
Logical scalar. |
threshold |
Numeric scalar. Classification threshold for
|
workers |
Positive integer. Number of parallel workers. |
seed |
Integer or |
diagnostics |
Logical scalar. When |
... |
Additional arguments passed to the bandwidth search or fitting functions. |
A gwpr_fit object. Key fields:
local_resultsPer-unit local model results.
predictionsIn-sample predicted values / probabilities.
residualsResiduals or Pearson residuals.
metricsOverall goodness-of-fit metrics.
spatial_resultsData frame of per-unit coefficients.
searchBandwidth search result (gwpr_bandwidth), or
NULL when bandwidth was supplied directly.
diagnosticsA gwpr_diagnostics object, or
NULL.
# Minimal linear GWPR with a fixed bandwidth library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, diagnostics = FALSE, workers = 1) print(fit)# Minimal linear GWPR with a fixed bandwidth library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) fit <- gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, diagnostics = FALSE, workers = 1) print(fit)
Functions for computing evaluation metrics for linear and logistic panel regression models.
Unified parallel execution interface for bandwidth search, local model fitting, and diagnostics. Shields backend differences and ensures CRAN-friendly behaviour.
Displays the search method, best bandwidth, criterion score, and number of iterations explored.
## S3 method for class 'gwpr_bandwidth' print(x, ...)## S3 method for class 'gwpr_bandwidth' print(x, ...)
x |
A 'gwpr_bandwidth' object. |
... |
Currently ignored. |
Invisibly returns 'x'.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) bw <- select_bandwidth(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", method = "grid", control = list(lower = 1, upper = 3, step = 1), workers = 1) print(bw)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) bw <- select_bandwidth(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", method = "grid", control = list(lower = 1, upper = 3, step = 1), workers = 1) print(bw)
Displays each diagnostic test name and, where available, its statistic and p-value.
## S3 method for class 'gwpr_diagnostics' print(x, ...)## S3 method for class 'gwpr_diagnostics' print(x, ...)
x |
A 'gwpr_diagnostics' object. |
... |
Currently ignored. |
Invisibly returns 'x'.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diag_obj <- diagnose_gwpr(fit, diagnostics = c("f_test", "hausman")) print(diag_obj)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diag_obj <- diagnose_gwpr(fit, diagnostics = c("f_test", "hausman")) print(diag_obj)
Displays a concise summary of a fitted GWPR model: family, panel model type, effect, bandwidth, and top-level goodness-of-fit metrics.
## S3 method for class 'gwpr_fit' print(x, ...)## S3 method for class 'gwpr_fit' print(x, ...)
x |
A 'gwpr_fit' object. |
... |
Currently ignored. |
Invisibly returns 'x'.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) print(fit)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) print(fit)
S3 classes and constructor functions for the three result objects returned by the GWPR.light public API: 'gwpr_fit', 'gwpr_bandwidth', and 'gwpr_diagnostics'. Also provides 'build_spatial_results()' for assembling a data.frame that can be aligned with an 'sf' geometry column.
Validates inputs, prepares data, and dispatches to the appropriate bandwidth
search algorithm: grid search, stochastic gradient descent (sgd), or random
search, depending on the method argument.
select_bandwidth( formula, data, spatial, id, time, family = c("gaussian", "binomial"), model = c("within", "pooling", "random"), effect = c("individual", "time", "two-way", "nested"), method = c("sgd", "grid", "random"), control = list(), kernel = c("bisquare", "gaussian", "exponential", "tricube", "boxcar"), adaptive = FALSE, threshold = 0.5, workers = 1L, seed = NULL, ... )select_bandwidth( formula, data, spatial, id, time, family = c("gaussian", "binomial"), model = c("within", "pooling", "random"), effect = c("individual", "time", "two-way", "nested"), method = c("sgd", "grid", "random"), control = list(), kernel = c("bisquare", "gaussian", "exponential", "tricube", "boxcar"), adaptive = FALSE, threshold = 0.5, workers = 1L, seed = NULL, ... )
formula |
A |
data |
A |
spatial |
An |
id |
Character scalar; unit ID column name. |
time |
Character scalar; time column name. |
family |
|
model |
|
effect |
|
method |
Bandwidth search method: |
control |
Named list of search control parameters. |
kernel |
Kernel function name. |
adaptive |
Logical; |
threshold |
Numeric; classification threshold (binomial only). |
workers |
Positive integer; number of parallel workers. |
seed |
Integer random seed, or |
... |
Additional arguments (currently unused). |
A gwpr_bandwidth object with fields:
best_bandwidthThe selected bandwidth value.
best_scoreThe criterion value at the best bandwidth.
methodThe search method used.
historySearch history data frame.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) bw <- select_bandwidth( y ~ x1, data = dat, spatial = pts, id = "id", time = "time", method = "grid", control = list(lower = 0.5, upper = 2, step = 0.5), workers = 1 ) bw$best_bandwidthlibrary(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame( id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20) ) bw <- select_bandwidth( y ~ x1, data = dat, spatial = pts, id = "id", time = "time", method = "grid", control = list(lower = 0.5, upper = 2, step = 0.5), workers = 1 ) bw$best_bandwidth
Prints the search method, best bandwidth, and a brief history overview.
## S3 method for class 'gwpr_bandwidth' summary(object, ...)## S3 method for class 'gwpr_bandwidth' summary(object, ...)
object |
A 'gwpr_bandwidth' object. |
... |
Currently ignored. |
Invisibly returns 'object'.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) bw <- select_bandwidth(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", method = "grid", control = list(lower = 1, upper = 3, step = 1), workers = 1) summary(bw)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) bw <- select_bandwidth(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", method = "grid", control = list(lower = 1, upper = 3, step = 1), workers = 1) summary(bw)
Prints each diagnostic test result with statistic and p-value where available.
## S3 method for class 'gwpr_diagnostics' summary(object, ...)## S3 method for class 'gwpr_diagnostics' summary(object, ...)
object |
A 'gwpr_diagnostics' object. |
... |
Currently ignored. |
Invisibly returns 'object'.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diag_obj <- diagnose_gwpr(fit, diagnostics = c("f_test", "hausman")) summary(diag_obj)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) diag_obj <- diagnose_gwpr(fit, diagnostics = c("f_test", "hausman")) summary(diag_obj)
Prints the global model overview, quantile summary of local coefficients (when available), and goodness-of-fit metrics.
## S3 method for class 'gwpr_fit' summary(object, ...)## S3 method for class 'gwpr_fit' summary(object, ...)
object |
A 'gwpr_fit' object. |
... |
Currently ignored. |
Invisibly returns 'object'.
library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) summary(fit)library(sf) pts <- sf::st_as_sf( data.frame(id = 1:4, X = c(0,1,0,1), Y = c(0,0,1,1)), coords = c("X", "Y"), crs = NA_integer_ ) dat <- data.frame(id = rep(1:4, each = 5), time = rep(1:5, 4), y = rnorm(20), x1 = rnorm(20)) fit <- fit_gwpr(y ~ x1, data = dat, spatial = pts, id = "id", time = "time", bandwidth = 2, workers = 1) summary(fit)
Panel dataset to estimate the relationship between county-level PM2.5 concentration and on-road transporation in California.
data(TransAirPolCalif)data(TransAirPolCalif)
A data.frame with 23 variables, and 928 observations, which are:
a numeric vector, fips IDs of the counties
a numeric vector, year
a numeric vector, annually average PM2.5 concentration in the counties
a numeric vector, geographically average CO2 emission from on-road transportation in each year, million tons/km2
a numeric vector, percentage of developed open space of total area in each county
a numeric vector, percentage of low-intensity developed area of total area in each county
a numeric vector, percentage of medium-intensity developed area of total area in each county
a numeric vector, percentage of high-intensity develope area of total area in each county
a numeric vector, percentage of open water of total area in each county
a numeric vector, percentage of woody wetland of total area in each county
a numeric vector, percentage of emergent herbaceous wetland of total area in each county
a numeric vector, percentage of deciduous forest of total area in each county
a numeric vector, percentage of evergreen forest of total area in each county
a numeric vector, percentage of mixed forest of total area in each county
a numeric vector, percentage of shrub of total area in each county
a numeric vector, percentage of grassland of total area in each county
a numeric vector, percentage of pasture of total area in each county
a numeric vector, percentage of cultivated crops of total area in each county
a numeric vector, average population density in each county
a numeric vector, average temperature in summer
a numeric vector, average temperature in winter
a numeric vector, average humidity in summer
a numeric vector, average humidity in winter
Chao Li <[email protected]> Shunsuke Managi <[email protected]>
data(TransAirPolCalif) head(TransAirPolCalif)data(TransAirPolCalif) head(TransAirPolCalif)
Sets set.seed(seed) before evaluating expr, then restores the
prior RNG state so the caller's random stream is unaffected.
with_reproducible_seed(seed, expr)with_reproducible_seed(seed, expr)
seed |
Integer scalar. Seed value passed to |
expr |
An R expression to evaluate. |
The value of expr.
r1 <- with_reproducible_seed(42, runif(3)) r2 <- with_reproducible_seed(42, runif(3)) stopifnot(identical(r1, r2))r1 <- with_reproducible_seed(42, runif(3)) r2 <- with_reproducible_seed(42, runif(3)) stopifnot(identical(r1, r2))