Bayesian Spatial Panel Data Models with Convex Combinations of Weight Matrices
Project description
spmixw
Bayesian Spatial Panel Data Models with Convex Combinations of Weight Matrices.
Python port of the R package spmixW, implementing Bayesian Markov chain Monte Carlo (MCMC) estimation of spatial panel data models including Spatial Autoregressive (SAR), Spatial Durbin Model (SDM), Spatial Error Model (SEM), Spatial Durbin Error Model (SDEM), and Spatial Lag of X (SLX) specifications with fixed effects.
Status
v0.2.1 (current) — feature-complete:
- Standard panel models: OLS, SAR, SDM, SEM, SDEM, SLX with fixed effects and optional heteroscedastic errors
- Convex combinations of multiple weight matrices (Debarsy and LeSage, 2021)
- Bayesian Model Averaging (BMA) over subsets of weight matrices
- Formula interface (
spmodel),simulate_panel, andcompare_models - Tidy output via
.tidy()and.glance()methods
Installation
pip install spmixw
Quick start
import numpy as np
from spmixw import simulate_panel, spmodel, make_knw
# Generate weight matrix from random coordinates
rng = np.random.default_rng(42)
coords = rng.uniform(size=(80, 2))
W = make_knw(coords, k=5)
# Simulate from a SAR DGP
panel = simulate_panel(
N=80, T=10, W=W, rho=0.5,
beta=[1.0, -0.5], seed=42,
)
# Estimate using formula interface
res = spmodel(
"y ~ x1 + x2",
data=panel, W=W, model="sar",
id="region", time="year",
effects="twoway",
ndraw=8000, nomit=2000, seed=42,
)
print(res)
print(res.tidy())
print(res.glance())
Models supported
| Model | Function | Spatial parameter | Formula interface |
|---|---|---|---|
| OLS | ols_panel() |
none | model="ols" |
| SAR | sar_panel() |
ρ (lag) | model="sar" |
| SDM | sdm_panel() |
ρ (lag) | model="sdm" |
| SEM | sem_panel() |
λ (error) | model="sem" |
| SDEM | sdem_panel() |
λ (error) | model="sdem" |
| SLX | slx_panel() |
none | model="slx" |
All models support fixed-effects specifications ("none", "region",
"time", "twoway") and optional heteroscedastic errors via the
Geweke (1993) Student-t mixture.
Model comparison
from spmixw import compare_models
comp = compare_models(
"y ~ x1 + x2",
data=panel, W=W,
id="region", time="year", effects="twoway",
)
print(comp)
# model log_marginal probability
# 0 SLX -3587.68 0.0000
# 1 SDM -3503.57 0.9817
# 2 SDEM -3528.06 0.0183
License
GPL-3.0-or-later
References
- Debarsy, N. and LeSage, J.P. (2021). "Bayesian model averaging for spatial autoregressive models based on convex combinations of different types of connectivity matrices." Journal of Business & Economic Statistics, 40(2), 547-558. doi:10.1080/07350015.2020.1840993
- LeSage, J.P. and Pace, R.K. (2009). Introduction to Spatial Econometrics. Taylor & Francis/CRC Press.
- LeSage, J.P. (2020). "Fast MCMC estimation of multiple W-matrix spatial regression models and Metropolis-Hastings Monte Carlo log-marginal likelihoods." Journal of Geographical Systems, 22(1), 47-75.
- Geweke, J. (1993). "Bayesian Treatment of the Independent Student-t Linear Model." Journal of Applied Econometrics, 8(S1), S19-S40.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spmixw-0.2.1.tar.gz.
File metadata
- Download URL: spmixw-0.2.1.tar.gz
- Upload date:
- Size: 45.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e14bce1bc289188ccccb534035480b624fe12aa6792ade67ef46a05b916d499e
|
|
| MD5 |
eec383657353d5a61e3afb5934555bd3
|
|
| BLAKE2b-256 |
7c5686715fa9d3a9d2b706df1e586f532f594406044155627ab902e54bfb6061
|
File details
Details for the file spmixw-0.2.1-py3-none-any.whl.
File metadata
- Download URL: spmixw-0.2.1-py3-none-any.whl
- Upload date:
- Size: 51.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65e1fe704ddfdf30b24c0055c265a7e0d5d31fe715bd2b4d835813bc5df8c39b
|
|
| MD5 |
e142d81f5486d66d99d2eda6c90c4865
|
|
| BLAKE2b-256 |
b3c7ec5572e8b4c20ca2cca711b3698cf2975781cd152e4c858f16494cf5ba7f
|