MyNixOS website logo
Description

Tools for Statistical Inference with Geo-Coded Data.

Fast computation of Conley (1999) <doi:10.1016/S0304-4076(98)00084-0> spatial heteroskedasticity and autocorrelation consistent (HAC) standard errors for linear regression models with geo-coded data, with a fast C++ implementation by Christensen, Hartman, and Samii (2021) <doi:10.1017/S0020818321000187>. Performance-critical distance calculations, kernel weighting, and variance component accumulation are implemented in C++ via 'Rcpp' and 'RcppArmadillo'. Includes tools for estimating the spatial correlation range from covariograms and correlograms following the bandwidth selection method proposed in Lehner (2026) <doi:10.48550/arXiv.2603.03997>, and diagnostic visualizations for bandwidth selection.

SpatialInference

R-CMD-check License: GPL v3

Fast computation of Conley (1999) spatial HAC standard errors for regression models with geo-coded data, using the C++ implementation by Darin Christensen (Christensen, Hartman, and Samii 2021). Includes a data-driven bandwidth selection method based on the covariogram range of regression residuals (Lehner 2026).

Features

  • Conley spatial HAC standard errors with six kernel functions (Bartlett, Epanechnikov, Gaussian, Parzen, Biweight, Uniform) and Haversine great-circle distances
  • Covariogram-based bandwidth selection — estimates the spatial correlation range from the empirical covariogram, providing a principled cutoff distance as proposed by Lehner (2026)
  • Inverse-U diagnostic plot — visualises how the Conley SE varies with the bandwidth, revealing the inverse-U relationship documented in Lehner (2026)
  • Performance — distance matrix computation, kernel weighting, and variance component accumulation are implemented in C++ via Rcpp/RcppArmadillo

Installation

Install the development version from GitHub:

# install.packages("devtools")
devtools::install_github("axlehner/SpatialInference")

macOS note

A Fortran compiler is required for LAPACK/BLAS. If you encounter gfortran issues, see this thread.

Quick start

library(SpatialInference)
library(lfe)
data("US_counties_centroids")

# 1. Estimate the correlation range from the covariogram
covgm_range(US_counties_centroids)
# 2. Compute Conley standard errors at the estimated bandwidth
reg <- felm(noise1 ~ noise2 | unit + year | 0 | lat + lon,
            data = US_counties_centroids, keepCX = TRUE)

vcvs <- conley_SE(reg, unit = "unit", time = "year",
                  lat = "lat", lon = "lon",
                  kernel = "epanechnikov", dist_cutoff = 831)

# Spatial standard errors:
sqrt(diag(vcvs$Spatial))

# Convenience wrapper (returns a single SE):
compute_conley_lfe(reg, cutoff = 831, kernel_choice = "epanechnikov")
# 3. Visualise the inverse-U relationship
inverseu_plot_conleyrange(US_counties_centroids,
                          cutoffrange = seq(1, 2501, by = 200))

Key functions

FunctionDescription
conley_SE()Conley spatial HAC variance-covariance matrices (spatial, serial, and combined)
compute_conley_lfe()Convenience wrapper returning a single Conley SE
covgm_range()Estimate and plot the correlation range from a covariogram
extract_corr_range()Extract the zero-crossing range from a covariogram or correlogram
inverseu_plot_conleyrange()Diagnostic plot of SE vs. bandwidth (inverse-U)
lm_sac()All-in-one: regression + Moran's I + Conley SEs
DistMat()Kernel-weighted spatial distance matrix (C++)

References

Lehner, A. (2026). Bandwidth selection for spatial HAC standard errors. arXiv preprint arXiv:2603.03997. doi:10.48550/arXiv.2603.03997

Conley, T. G. (1999). GMM estimation with cross sectional dependence. Journal of Econometrics, 92(1), 1--45. doi:10.1016/S0304-4076(98)00084-0

Christensen, D., Hartman, A. C. and Samii, C. (2021). Legibility and external investment: An institutional natural experiment in Liberia. International Organization, 75(4), 1087--1108. doi:10.1017/S0020818321000187

Metadata

Version

0.1.0

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows