Skip to main content

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.1.0 (current): All standard panel models — OLS, SAR, SDM, SEM, SDEM, SLX — plus formula interface, model comparison via log-marginal likelihoods, and simulate_panel() for reproducible DGPs.

v0.2 (planned): Convex combinations of multiple weight matrices, following Debarsy and LeSage (2021).

v0.3 (planned): Bayesian Model Averaging (BMA) over subsets of weight matrices.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spmixw-0.2.0.tar.gz (45.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spmixw-0.2.0-py3-none-any.whl (51.9 kB view details)

Uploaded Python 3

File details

Details for the file spmixw-0.2.0.tar.gz.

File metadata

  • Download URL: spmixw-0.2.0.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

Hashes for spmixw-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fe5b43cd8c5b7455365cfbc1099ba39764776a168b987fc616ac69524ebe6e34
MD5 2ac7c664742e1c1f0e486590005ace95
BLAKE2b-256 af7fd88d62652abcf80472ce8aaa93efddf1889ece62f2f70786a16a1201fb62

See more details on using hashes here.

File details

Details for the file spmixw-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: spmixw-0.2.0-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

Hashes for spmixw-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3137b4090b5947555036fbe5f30641b20ea491500d16804756a1f722a88dd558
MD5 05eba74899d2e081b79e90006e4cb41f
BLAKE2b-256 ab6d5b33525aad96ed4f28ee85f3281aed1318fcc01ae12a17359b83feb3fa33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page