Skip to main content

Correcting inference in SAR models for rho-estimation uncertainty

Project description

rho-uncertainty

Correcting inference in spatial autoregressive (SAR) models for the estimation uncertainty in ρ.

The standard plug-in procedure treats ρ̂ as known, producing standard errors that are systematically too small. This package provides two corrections:

  • VIF (instant, closed-form): captures 40-67% of the true correction
  • SANI (seconds, numerical): captures ~98% of the true correction

Installation

pip install rho-uncertainty

Or download rho_uncertainty.py directly and place it in your working directory.

Usage with PySAL/spreg

from spreg import ML_Lag
model = ML_Lag(y, X, w=w)

from rho_uncertainty import correct
correct(model)           # prints corrected regression table
correct(model, 'sani')   # higher accuracy (~10s)

Usage with raw matrices

from rho_uncertainty import rho_test

# W: spatial weights (n x n), X: design matrix (n x p, with intercept)
# y: dependent variable (n,), rho_hat: estimated rho
result = rho_test(W, X, y, rho_hat=0.3)

Quick VIF-only correction

from rho_uncertainty import vif_correction

factor = vif_correction(W, X, rho_hat)
se_corrected = se_naive * factor

Example output

======================================================================
  SAR Regression with Rho-Uncertainty Correction
======================================================================
  Dependent variable: crime
  n = 49,  p = 3,  rho_hat = 0.4159
  Method: VIF

      Variable      Coef  SE(naive)    SE(VIF)    t(VIF)   p-value
  -----------------------------------------------------------------
        income    0.4795     0.1587     0.1597    3.0020    0.0043  ***
         hoval   -0.0760     0.1583     0.1589   -0.4784    0.6346
  -----------------------------------------------------------------
  Average variance inflation: +1.07%
======================================================================

How it works

The VIF captures only 40-67% of the true variance correction due to a structural limitation called phantom substitution. SANI bypasses this through Rao-Blackwellized numerical integration.

Requirements

  • Python >= 3.8
  • NumPy >= 1.20
  • SciPy >= 1.7

License

MIT

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

rho_uncertainty-0.1.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

rho_uncertainty-0.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file rho_uncertainty-0.1.1.tar.gz.

File metadata

  • Download URL: rho_uncertainty-0.1.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rho_uncertainty-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3ee177a4abce641b95b409680592e6b53f5fab1e46c6556f29ccb899f8a001e2
MD5 d3271a16eaa00e4e8864cdc88d0cc698
BLAKE2b-256 0a04a040927cd6e4130ae7096c0c5344859e367d41092bd8cd009f129b304c00

See more details on using hashes here.

Provenance

The following attestation bundles were made for rho_uncertainty-0.1.1.tar.gz:

Publisher: publish.yml on WillWeiQiang/rho-uncertainty

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rho_uncertainty-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for rho_uncertainty-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8d9922cf8c0652a98b4fa34517b8b1c8cf8c1c6da710684051ddf920c54ab3e4
MD5 d481a6cf432a0915b92ac19b2bbeb307
BLAKE2b-256 2fb9e7c82666cf2a057e6af565fcded53335514a7a959747e81d7d780a9295c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for rho_uncertainty-0.1.1-py3-none-any.whl:

Publisher: publish.yml on WillWeiQiang/rho-uncertainty

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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