Skip to main content

Spatial error dependence diagnostics and corrections based on Müller-Watson, Econometrica 2024

Project description

Tests Python Version

spur-python: A Python Package for Spatial Unit Roots

A Python implementation of the methods for diagnosing and correcting spatial unit roots developed by Muller and Watson (2024). This is a complete port of the Stata package SPUR (Becker, Boll and Voth 2025) — see the forthcoming Stata Journal article for the practitioner's guide.

Installation

The easiest way to get started is to install our coding-agent skills. Just point your agent at our spur-skills repository:

codex --dangerously-bypass-approvals-and-sandbox "Install spur-skills by following https://github.com/spatial-spur/spur-skills#install"
claude --dangerously-skip-permissions "Install spur-skills by following https://github.com/spatial-spur/spur-skills#install"

You can install just the package with:

uv pip install spur-python

Example Usage

We expose both the individual test functions and convenience wrappers running the entire pipeline.

To run the full pipeline, use the spur() wrapper:

import spur
from spur import load_chetty_data, standardize

#  --- data processing ---
df = load_chetty_data()

df = df[~df.state.isin(["AK", "HI"])][["am", "fracblack", "lat", "lon"]]
df = df.dropna(subset=["am", "fracblack", "lat", "lon"])
df = standardize(df, ["am", "fracblack"])

# --- spur pipeline ---
result = spur.spur(
    "am ~ fracblack",
    df,
    lon="lon",
    lat="lat",
    q=10,
    nrep=500,
    seed=42,
)
print(result.summary())

This prints both the spur-diagnostics:

--------------------------------------------
--------------------------------------------
              SPUR Diagnostics              
--------------------------------------------
Test              LR             p-value    
i0                     4.2961         0.0080
i1                     2.5240         0.4660
i0resid                3.3153         0.0700
i1resid              570.7543         0.2540
--------------------------------------------
--------------------------------------------

and the regression results with transformed and untransformed variables:

             Regression results             
--------------------------------------------
--------------------------------------------
                              am            
                  --------------------------
Coefficient       Levels         Transformed
--------------------------------------------
Intercept             -0.0000        -0.0000
                     (0.1732)       (0.0789)
fracblack             -0.6009        -0.4240
                     (0.1187)       (0.0903)
--------------------------------------------
N                         693            693
R-squared              0.3611         0.1029
Adj. R-squared         0.3601         0.1016
SCPC q                      8              8
SCPC cv                2.6097         2.6097
SCPC avc               0.0300         0.0300
--------------------------------------------

Citation

@Article{becker2025,
  author  = {Becker, Sascha O. and Boll, P. David and Voth, Hans-Joachim},
  title   = {Testing and Correcting for Spatial Unit Roots in Regression Analysis},
  journal = {Stata Journal},
  year    = {forthcoming}
}

@Article{muller2024,
  author  = {M{\"u}ller, Ulrich K. and Watson, Mark W.},
  title   = {Spatial Unit Roots and Spurious Regression},
  journal = {Econometrica},
  year    = {2024},
  volume  = {92},
  number  = {5},
  pages   = {1661--1695}
}

References

  • Muller, Ulrich K. and Mark W. Watson (2024). "Spatial Unit Roots and Spurious Regression." Econometrica 92(5), 1661-1695.
  • Becker, Sascha O., P. David Boll, and Hans-Joachim Voth (2025). "Testing and Correcting for Spatial Unit Roots in Regression Analysis." Stata Journal, forthcoming. [PDF]
  • Chetty, Raj, Nathaniel Hendren, Patrick Kline, and Emmanuel Saez (2014). "Where is the Land of Opportunity? The Geography of Intergenerational Mobility in the United States." QJE 129(4).

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

spur_python-0.1.1.tar.gz (180.7 kB view details)

Uploaded Source

Built Distribution

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

spur_python-0.1.1-py3-none-any.whl (168.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for spur_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7815db6956e640e830778f69ad82cdb6929040628e0a0919a5549ade9d7abcf8
MD5 697f2b42b98aea564cdcc22c1af89f29
BLAKE2b-256 c44664692ae8999ea8869def54046bd127a0a93f0dba6a0a79673e0d2b7db488

See more details on using hashes here.

Provenance

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

Publisher: pypi.yaml on spatial-spur/spur-python

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

File details

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

File metadata

  • Download URL: spur_python-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 168.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spur_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7e6d83b6c0e07154ad6a6146a90f2dd011d1bb5b1a6509cde42cb36186f0f73
MD5 0516a50d48b61d406baf995a3423d242
BLAKE2b-256 0405292afc99a7f0b609dad26723d506ff27174331c695de12cb78f41502fbcf

See more details on using hashes here.

Provenance

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

Publisher: pypi.yaml on spatial-spur/spur-python

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