Package 'spatialSpur'

Title: Spatial Correlation-Robust Inference and Unit Root Diagnostics
Description: Spatial correlation-robust regression inference, spatial unit root diagnostics, half-life confidence sets, spatial transformations, and spatial coefficient-variability testing and scale estimation using the methods of Mueller and Watson (2022) <doi:10.3982/ECTA19465>, Mueller and Watson (2023) <doi:10.1080/07350015.2022.2127737>, Mueller and Watson (2024) <doi:10.3982/ECTA21654>, and Mueller and Watson (2025).
Authors: Paul David Boll [aut, cre, cph], Daniel Goettlich [aut, cph], Sascha O. Becker [aut, cph], Hans-Joachim Voth [aut, cph], Ulrich K. Mueller [ctb], Mark W. Watson [ctb], Authors of vendored Rust crates and bundled example data [cph] (see inst/COPYRIGHTS)
Maintainer: Paul David Boll <[email protected]>
License: MIT + file LICENSE
Version: 0.7.0
Built: 2026-12-02 20:53:02 UTC
Source: https://github.com/spatial-spur/spatial-rust

Help Index


Spatial Correlation-Robust Inference, SVP Stability Tests, and SPUR Diagnostics

Description

Calculate spatial correlation-robust intervals for fitted unweighted regressions, test for spatially varying coefficients (svptest) and estimate variation scale (svpscale), run spatial unit root diagnostics, invert spatial half-life tests, and transform spatial observations. The functions use a shared native numerical engine.

Usage

scpc(model, data = NULL, lon = NULL, lat = NULL, coords_euclidean = NULL,
  cluster = NULL, ncoef = NULL, avc = 0.03, method = "auto",
  large_n_seed = 1, uncond = FALSE, cvs = FALSE, backend = NULL,
  nthreads = NULL, coords = NULL, geographic = FALSE, row_id = NULL,
  units = NULL, inference = NULL, landmarks = 1000L,
  landmark_samples = 20L, cv_tolerance = 0.001)

spur(formula, data, lon = NULL, lat = NULL, coords_euclidean = NULL,
  q = 15, nrep = NULL, nrep_tune = NULL, seed = 42, avc = 0.03,
  uncond = FALSE, cvs = FALSE, backend = NULL, nthreads = NULL,
  draws = NULL, tuning_draws = NULL, method = "auto", large_n_seed = 1)

spurtest(formula, data, test, lon = NULL, lat = NULL, coords_euclidean = NULL,
  q = 15, nrep = NULL, nrep_tune = NULL, seed = 42, backend = NULL,
  nthreads = NULL, draws = NULL, tuning_draws = NULL)
spurtest_i0(formula, data, ...)
spurtest_i1(formula, data, ...)
spurtest_i0resid(formula, data, ...)
spurtest_i1resid(formula, data, ...)

spurhalflife(formula, data, lon = NULL, lat = NULL, coords_euclidean = NULL,
  q = 15, nrep = NULL, level = 95, normdist = FALSE, seed = 42,
  backend = NULL, nthreads = NULL, draws = NULL)

spurhalflife_point(formula, data, h0, lon = NULL, lat = NULL, coords_euclidean = NULL,
  q = 15, nrep = NULL, level = 95, normdist = FALSE, seed = 42,
  backend = NULL, nthreads = NULL, draws = NULL)

spurtransform(formula, data, lon = NULL, lat = NULL, coords_euclidean = NULL,
  prefix = "h_", transformation = "lbmgls", radius = NULL,
  clustvar = NULL, backend = NULL, nthreads = NULL, replace = FALSE)

svptest(model, data = NULL, lon = NULL, lat = NULL, coords_euclidean = NULL,
  cluster = NULL, parm = NULL, avc = 0.01, q = NULL, alpha = 0.05,
  method = "auto", large_n_seed = 1, landmarks = 1000L,
  landmark_samples = 20L, cv_tolerance = 1e-5, backend = NULL,
  nthreads = NULL, coords = NULL, geographic = FALSE,
  row_id = NULL, units = NULL)

svpscale(model, data = NULL, lon = NULL, lat = NULL, coords_euclidean = NULL,
  cluster = NULL, parm = NULL, avc = 0.01, q = NULL,
  reference_distance = NULL, seed = 42, nrep = 100000L,
  max_iter = 200L, multipliers = NULL, method = "auto",
  large_n_seed = 1, landmarks = 1000L, landmark_samples = 20L,
  backend = NULL, nthreads = NULL, coords = NULL,
  geographic = FALSE, row_id = NULL, units = NULL)

load_chetty_data()
spatial_build_info()

## S3 method for class 'scpc'
print(x, ...)
## S3 method for class 'scpc'
summary(object, ...)
## S3 method for class 'summary.scpc'
print(x, ...)
## S3 method for class 'scpc'
coef(object, ...)
## S3 method for class 'scpc'
confint(object, parm, level = 0.95, ...)
## S3 method for class 'spatial_spur_halflife'
print(x, ...)
## S3 method for class 'spatial_spur_halflife_point'
print(x, ...)
## S3 method for class 'spatial_spur_test'
print(x, ...)
## S3 method for class 'spatial_spur_test'
summary(object, ...)
## S3 method for class 'spatial_spur_pipeline'
print(x, ...)
## S3 method for class 'spatial_spur_pipeline'
summary(object, ...)
## S3 method for class 'spatial_svp_test'
print(x, ...)
## S3 method for class 'spatial_svp_test'
summary(object, ...)
## S3 method for class 'spatial_svp_scale'
print(x, ...)
## S3 method for class 'spatial_svp_scale'
summary(object, ...)

Arguments

model

An unweighted lm or a fixest::feols OLS or 2SLS fit. For fixest, retain fitted matrices with demeaned = TRUE. Save source rows with data.save = TRUE to look up coordinates by name.

data

A data frame containing coordinates and, for formula interfaces, analysis variables.

lon, lat

The names of geographic coordinate columns in degrees.

coords_euclidean

Names of Euclidean coordinate columns.

coords

A numeric coordinate matrix in fitted observation order.

geographic

Whether coords contains longitude and latitude.

row_id

A shared unique fitted row identifier column.

cluster

A site label column or a fitted-order site label vector.

units

A descriptive label for the supplied coordinate units.

ncoef

The number of coefficients to report.

avc

The upper bound on average pairwise correlation.

method

Spatial geometry choice "auto", "exact", or "nystrom".

large_n_seed, landmarks, landmark_samples

Settings for the Nyström ensemble (landmarks >= 3 for svptest and svpscale).

uncond, inference

Select conditional OLS, conditional ordinary 2SLS, or unconditional inference.

cvs

Whether to return additional critical values.

cv_tolerance

The critical-value solver tolerance (in t units for scpc or ξqs\xi_q^s scale units for svptest).

backend

Native backend selector "rust" or "auto".

nthreads

Optional positive native thread budget.

formula

A regression formula, one-response formula, or supplied variable names, depending on the procedure.

test

One of "i0", "i1", "i0resid", or "i1resid".

q

The number of low-frequency spatial directions (NULL selects optimal q automatically in svptest and svpscale).

nrep

Requested simulation draws. Defaults to 100,000 (minimum 500 when fitting multipliers in svpscale) or the width of the supplied draw matrix.

nrep_tune

Optional tuning draw count when seeding diagnostics in the core.

seed

Unsigned 32-bit integer seed in [0, 2^32 - 1] for core ChaCha20 simulation draws. Caller R RNG state is never read or modified.

h0

Point-null half-life value in [0, Inf] for spurhalflife_point.

draws, tuning_draws

Optional matrices with q rows of independent standard Gaussian drivers for inference and tuning. Half-life uses one draw matrix.

level

Confidence level (in percent for spurhalflife and spurhalflife_point, or as a fraction in (0, 1) for confint.scpc).

normdist

Return half-life in sample diameters when true.

prefix

Prefix for transformed columns.

transformation

One of "lbmgls", "nn", "iso", or "cluster".

radius

A strictly positive ISO radius in input units or meters for geography.

clustvar

Site label column for cluster demeaning.

replace

Allow replacement of existing output columns in the returned data.

x, object

A fitted result object returned by scpc, summary.scpc, spur, spurtest, spurhalflife, spurhalflife_point, svptest, or svpscale.

parm

Optional vector of coefficient names or 1-based indices for confint.scpc, svptest, or svpscale.

alpha

Nominal significance level in (0, 1) used for automatic q selection and cv_alpha in svptest.

reference_distance

Physical reference distance d0d_0 for sigma_delta_beta in svpscale. Defaults to 1e6 meters for geographic coordinates and 1.0 otherwise.

max_iter

Maximum dual optimization iterations for Lagrange multipliers in svpscale.

multipliers

Optional 100-element Lagrange multiplier vector or spatial_svp_scale object to reuse in svpscale.

...

Additional arguments passed to spurtest or S3 print and summary methods.

Value

scpc returns coefficient estimates, uncertainty, effective critical values and a spatial basis in the reported site order. Valid conditional 2SLS t intervals assume strong identification (for weak IV, scalar Anderson–Rubin testing is recommended). Diagnostics return likelihood ratios, p-values, critical values, and tuned alternatives; spur runs the SPUR diagnostics and returns both the levels SCPC fit and the no-intercept LBM-GLS transformed SCPC fit; spurtransform evaluates formula terms or variable names on complete cases and returns the augmented data frame; spurhalflife returns half-life confidence intervals and matrices of confidence components with units and normalization using spec 0.7.0; spurhalflife_point returns point-null test exceedance counts, p-values, and acceptance indicators; svptest returns the Müller–Watson (2025) coefficient stability test statistics, p-values, critical values, selected dimension q, and eigenvalues; svpscale returns nearly median-unbiased LBM scale estimates (kappa_unit, kappa_phys, sigma_delta_beta), raw psi_hat, and reusable Lagrange multipliers; load_chetty_data returns the Chetty et al. commuting-zone example data frame; and spatial_build_info returns the compiled methods version and provider.

Examples

d <- load_chetty_data()
d <- d[complete.cases(d[c("am", "fracblack", "lat", "lon")]), ][1:60, ]
fit <- lm(am ~ fracblack, d)
scpc(fit, d, lon = "lon", lat = "lat", nthreads = 1L)
svptest(fit, d, lon = "lon", lat = "lat", q = 6L, parm = "fracblack", nthreads = 1L)