Abstract
Bayesian approaches play an important role in the development of new spatial econometric methods, but are uncommon in applied work. This is partly due to a lack of accessible, flexible software for the Bayesian estimation of spatial models. Established probabilistic software struggles with the specifics of spatial econometrics, while classical implementations do not harness the flexibility of Bayesian modelling. In this paper, I present a layered, objected-oriented software architecture that bridges this gap. An R implementation in the bsreg package allows quick and easy estimation of spatial econometric models, while remaining maintainable and extensible. I demonstrate the benefits of the Bayesian approach and using a well-known dataset on cigarette demand. First, I show that Bayesian posterior densities yield better insights into the uncertainty of non-linear models. Second, I find that earlier studies overestimate spillover effects for distance-based connectivities due to a scaling error, highlighting the need for tried and tested software.
Introduction
Spatial econometrics is a specialized field focused on understanding "spillovers"—the phenomenon where economic activities or policy changes in one geographic location influence outcomes in neighboring areas. A classic example is how cigarette taxes in one state might affect sales in an adjacent state. While Bayesian methods are theoretically well-suited for these models—offering robust handling of uncertainty and complex hierarchical structures—they remain underutilized in applied research. This paper introduces the bsreg package for R, which addresses this adoption gap through a novel software architecture.
The Software Gap
The lack of Bayesian adoption in spatial econometrics stems from a "software gap." On one side, classical (frequentist) software often functions as a "black box," making it difficult for researchers to extend models or inspect internal processes. On the other side, general-purpose probabilistic programming languages (PPLs) like Stan or JAGS, while flexible, are often inefficient for spatial models. These models frequently require calculating the determinant of large $N \times N$ connectivity matrices, a task that general PPLs are not optimized for.
A Layered, Object-Oriented Architecture
To bridge this gap, the bsreg package employs a layered architecture built on the R6 object-oriented system. This design creates a "stateful" sampler, where the Markov chain Monte Carlo (MCMC) process is treated as a machine with a current state and a defined set of rules for updates.
This core engine is wrapped in a user-friendly S3 interface, mimicking the syntax of standard R functions like lm(). This dual-layer approach ensures that the software is maintainable and extensible for developers while remaining accessible to practitioners. The underlying algorithms utilize a hybrid approach: Gibbs sampling for linear parameters and Metropolis-Hastings steps for non-linear spatial parameters, such as connectivity strength.
Empirical Application: Cigarette Demand
The software's capabilities are demonstrated using the Baltagi and Li (2004) cigarette demand dataset, which tracks sales, prices, and income across 46 US states from 1963 to 1992. This dataset serves as a benchmark for evaluating how spatial models handle regional dependencies over time.
Key Insights: Uncertainty and Scaling Errors
The Bayesian approach implemented in bsreg reveals two critical insights that frequentist methods often overlook.
1. Capturing True Uncertainty
Frequentist methods typically provide point estimates and standard errors, assuming a Gaussian (bell-curve) distribution. However, for non-linear spatial models, the actual distribution of "total effects" can be heavily skewed with "heavy tails." Bayesian posterior densities capture this full range of uncertainty, providing a more accurate basis for risk assessment and policy planning.
2. The Scaling Trap
A significant finding of this work is the discovery of a scaling error in previous influential studies and popular software like spatialreg. When using distance-based connectivity, an incorrect scaling factor led researchers to overestimate the reach of spatial spillovers by as much as a factor of seven. This highlights the critical importance of using verified, specialized software.
Learning the Neighborhood
Beyond correcting errors, the Bayesian framework allows for more flexible modeling. Instead of assuming a fixed decay rate for spatial effects, the SLX($\delta$) model lets the data determine the optimal decay parameter ($\delta$). In the cigarette demand case, the distance-decay parameter was estimated at approximately 3.01 (99% CI: [2.54, 3.74]), offering a data-driven definition of "neighborhoods" that surpasses simple binary contiguity.
Conclusion and Future Work
The bsreg package provides a robust foundation for Bayesian spatial econometrics. While currently focused on core spatial models, future development will aim to support more complex "layered" adjustments, such as those found in Spatial Autoregressive Combined (SAC) models, and optimize the system for even larger datasets. By making these sophisticated methods accessible, bsreg empowers researchers to gain deeper, more accurate insights into spatial economic phenomena.
Summary updated