Skip to main content

SCPC inference in Python

Project description

Tests Python Version

███████  ██████ ██████   ██████       ██████  ██    ██ ████████ ██   ██  ██████  ███    ██ 
██      ██      ██   ██ ██            ██   ██  ██  ██     ██    ██   ██ ██    ██ ████   ██ 
███████ ██      ██████  ██      █████ ██████    ████      ██    ███████ ██    ██ ██ ██  ██ 
     ██ ██      ██      ██            ██         ██       ██    ██   ██ ██    ██ ██  ██ ██ 
███████  ██████ ██       ██████       ██         ██       ██    ██   ██  ██████  ██   ████ 
                                                                                           

scpc-python: Spatial Correlation-Robust Inference

scpc-python provides spatial correlation-robust inference for regression coefficients following Müller and Watson (2022, 2023).

Installation

You can install scpc-python from PyPI (coming soon) with:

uv venv --python 3.11
uv pip install scpc-python

or from GitHub with:

uv venv --python 3.11
uv pip install git+https://github.com/DGoettlich/scpc-python.git

Basic Usage

This example starts from the transformed branch of the Becker, Boll, and Voth (2026) workflow. In the full workflow, you would first use spurtest to decide whether to stay in levels or transform. Here we assume the transformed branch and move directly to the regression plus scpc step.

# assumes spur-python is installed
from spur import load_chetty_data, spurtransform
from scpc import scpc
import statsmodels.formula.api as smf

data = load_chetty_data()

data = data[~data["state"].isin(["AK", "HI"])][
    ["am", "gini", "fracblack", "lat", "lon"]
]
data = data.dropna(subset=["am", "gini", "fracblack", "lat", "lon"]).copy()

transformed = spurtransform(
    "am ~ gini + fracblack",
    data,
    lon="lon",
    lat="lat",
    transformation="lbmgls",
    prefix="h_",
)

fit = smf.ols("h_am ~ h_gini + h_fracblack", data=transformed).fit()

result = scpc(
    fit,
    data=transformed,
    lon="lon",
    lat="lat",
    cvs=True,
)

scpc() returns an SCPCResult object:

  • result.scpcstats: the main inference table with coefficient estimates, standard errors, t statistics, p values, and 95% interval endpoints
  • result.scpccvs: optional stored critical values at 32%, 10%, 5%, and 1%
  • result.avc: the average pairwise correlation bound used in the analysis
  • result.c0: the kernel scale implied by avc
  • result.cv: the unconditional 5% critical value
  • result.q: the number of retained non-constant spatial principal components

Key Arguments

The most important scpc() arguments in the workflow above are:

  • model: the fitted regression model
  • data: the data frame
  • lon, lat: the geodesic coordinate column names
  • coords_euclidean: use this instead of lon / lat when coordinates are Euclidean rather than geographic
  • cluster: optional clustering column
  • ncoef: how many coefficients to report
  • avc: upper bound on the average pairwise correlation
  • uncond: whether to skip the conditional adjustment
  • cvs: whether to store the extra critical values

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

scpc_python-0.1.0b3.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

scpc_python-0.1.0b3-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file scpc_python-0.1.0b3.tar.gz.

File metadata

  • Download URL: scpc_python-0.1.0b3.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scpc_python-0.1.0b3.tar.gz
Algorithm Hash digest
SHA256 f37bad5752c05402d8dfc9151065665b4a6743b2b698b2c6e0ab589508bd3a5a
MD5 a8cb15102b3889d289e4d896f3dc0b8f
BLAKE2b-256 b081be6f819c2f619b308e08845cdef4252f5ed012d4e52b5cbac8c7bf502ec6

See more details on using hashes here.

Provenance

The following attestation bundles were made for scpc_python-0.1.0b3.tar.gz:

Publisher: pypi.yaml on spatial-spur/scpc-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 scpc_python-0.1.0b3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for scpc_python-0.1.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 1c9d7ed06108b4155c1dfadda8018eef656b29f0bb94481ce4af93f4fc56d0d6
MD5 e3e6e72e8686d8fee1ef5f135d84818c
BLAKE2b-256 2e92d9ead3dc80140717a3f027f77386b58657d54293743d50e4df62c4e07896

See more details on using hashes here.

Provenance

The following attestation bundles were made for scpc_python-0.1.0b3-py3-none-any.whl:

Publisher: pypi.yaml on spatial-spur/scpc-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