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.0b1.tar.gz (180.8 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.0b1-py3-none-any.whl (168.6 kB view details)

Uploaded Python 3

File details

Details for the file spur_python-0.1.0b1.tar.gz.

File metadata

  • Download URL: spur_python-0.1.0b1.tar.gz
  • Upload date:
  • Size: 180.8 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.0b1.tar.gz
Algorithm Hash digest
SHA256 1caebabc92cd33341d1033fec9792fe0c6e05ecb44ff8c8febaf1b3674a06f2b
MD5 88f83f0d854edcd6aa77e36eca5290b2
BLAKE2b-256 ee0692f8eca158b99035dfed69cb102e1f66d7c25e86cb9287642bea8714fbcb

See more details on using hashes here.

Provenance

The following attestation bundles were made for spur_python-0.1.0b1.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.0b1-py3-none-any.whl.

File metadata

  • Download URL: spur_python-0.1.0b1-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.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b6145d7fa273d0d0d5431af8fa086679fa9f3a99d3420bb3f8b819c8fc17896
MD5 19ee3eaca0fca374e3ed7557e1a0ac4f
BLAKE2b-256 7c42088804ff26d8cbc69d3f0a62c6dab0d29f87c84ed0dd4f54699354dd6a05

See more details on using hashes here.

Provenance

The following attestation bundles were made for spur_python-0.1.0b1-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