bsreg: Bayesian Spatial Regression Models

Nikolas KuschnigOpenalex Unknown 2021 · DOI · OpenAlex

Abstract: Fit Bayesian models with a focus on the spatial econometric models.

Introduction

Spatial data is inherently "noisy" because observations are rarely independent; what happens in one geographic area, such as a city or state, often spills over into its neighbors. While spatial econometrics provides tools to model these dependencies, implementing them within a Bayesian framework has traditionally been difficult. Researchers often face a steep learning curve, needing to write custom Markov Chain Monte Carlo (MCMC) samplers to handle specific priors or complex error structures.

bsreg is an R package designed to streamline Bayesian spatial econometrics, providing a unified framework for fitting complex spatial regression models. It addresses the implementation gap by providing a standardized, user-friendly interface for Bayesian spatial modeling, making sophisticated uncertainty quantification accessible to a broader range of social scientists and data analysts.

The bsreg Framework: The bm() Function

The package is built around a core function, bm(), which fits models using MCMC sampling. This function serves as the primary interface for fitting a wide variety of spatial models. It is designed to be intuitive for users familiar with standard R regression syntax, while offering the flexibility needed for sophisticated spatial analysis.

Table 1: Arguments for the core bm function, illustrating the flexibility in model specification and spatial connectivity.

As shown in the function arguments, bm() requires a formula specification and a spatial weight matrix (W). The type argument allows users to switch between different spatial architectures, including Spatially Lagged X (slx), Spatial Autoregressive (sar), Spatial Error (sem), and Spatial Durbin Models (sdm/sdem). This modularity is a key strength of the package, enabling rapid hypothesis testing across different spatial specifications.

Advanced Modeling Capabilities

One of the standout features of bsreg is its support for advanced shrinkage priors. In many spatial datasets, researchers may have a large number of potential predictors but limited observations. Standard flat priors can lead to overfitting in these scenarios. bsreg implements Normal-Gamma and Horseshoe priors, which are designed for automatic variable selection. These "smart" priors effectively shrink the coefficients of irrelevant variables toward zero, improving model parsimony and predictive performance.

Furthermore, the package integrates with the stochvol framework to allow for Stochastic Volatility (SV). This is particularly useful in panel data or time-series spatial models where the variance of the error term may change over time or across different spatial units. By accounting for heteroskedasticity through SV, researchers can obtain more robust estimates of spatial spillover effects.

Workflow Control and Diagnostics

Effective Bayesian modeling requires careful monitoring of the MCMC process. bsreg provides dedicated functions for managing the sampling lifecycle, including setting prior hyperparameters (set_NG, set_SAR) and tuning the Metropolis-Hastings (MH) step.

Table 2: Parameters for tuning the Metropolis-Hastings step, ensuring efficient sampling and convergence.

The tuning parameters—such as acc_target and acc_change—allow users to optimize the acceptance rate of the sampler, which is critical for ensuring that the MCMC chain explores the posterior distribution efficiently. Additionally, the package is designed to be fully compatible with the coda package, the industry standard for MCMC diagnostics, ensuring that users can rigorously check if their models have converged.

Datasets and Reproducibility

The package includes two primary datasets for demonstration and benchmarking:

  • cigarettes: A panel dataset tracking cigarette demand across 46 US states from 1963 to 1992. This is a classic econometric dataset, here extended with longitude and latitude to facilitate spatial analysis.
  • us_states: A dataset of US state boundary polygons (1960–2000), which is essential for constructing spatial weight matrices (the "W" matrix) that define which regions are considered "neighbors."

These resources enable users to reproduce results from recent literature, such as Kuschnig (2022), providing a bridge between theoretical research and practical application.

Limitations and Future Work

While bsreg significantly lowers the barrier to entry for Bayesian spatial modeling, it is not without limitations. MCMC-based estimation is inherently more computationally intensive than frequentist (Maximum Likelihood) approaches. While the package utilizes the Matrix package for efficient sparse matrix operations, very large spatial datasets may still face significant processing times. Additionally, the choice of the spatial weight matrix (W) remains a critical researcher-led decision that can significantly impact results. Despite these challenges, the modular R6 class structure of the package suggests it is built for future expansion into even more complex hierarchical spatial models.

Summary updated

Abstract

Fit Bayesian models with a focus on the spatial econometric models.
BibTeX
@inproceedings{kuschnig2021bsreg,
  author = {Nikolas Kuschnig},
  title = {{bsreg: Bayesian Spatial Regression Models}},
  booktitle = {Openalex Unknown},
  year = {2021},
  doi = {10.32614/cran.package.bsreg},
}
Figure