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.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, and compare_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


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.3.tar.gz (46.0 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.3-py3-none-any.whl (52.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spmixw-0.2.3.tar.gz
  • Upload date:
  • Size: 46.0 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.3.tar.gz
Algorithm Hash digest
SHA256 3dde1039b62583e8b5bbebceb022514cecdd1031405990f2f5179335d7d76163
MD5 ad733b6ecf3a2167d02bbdadb963179a
BLAKE2b-256 0bc84e6fe6861bca6c582d2bc393fb8b57022a2dbbb81fa4fa481d30bb62ad43

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spmixw-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 52.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9922fe1ba3509375a653e5a02e3f0a0c49314d6e9c7ecdcc9f22a31e82618fe7
MD5 bea3a394b7bd356a7fc8a9125af826b1
BLAKE2b-256 c74bff9aa829ce39002313fae212751f25f7b7a5bcf28c58a8c913a890b3dc39

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