SCPC inference in Python
Project description
███████ ██████ ██████ ██████ ██████ ██ ██ ████████ ██ ██ ██████ ███ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██
███████ ██ ██████ ██ █████ ██████ ████ ██ ███████ ██ ██ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
███████ ██████ ██ ██████ ██ ██ ██ ██ ██ ██████ ██ ████
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,
)
print(result)
scpc() returns an SCPCResult object:
print(result): prints an R-like SCPC inference tableresult.scpcstats: the main inference table with coefficient estimates, standard errors, t statistics, p values, and 95% interval endpointsresult.scpccvs: optional stored critical values at 32%, 10%, 5%, and 1%result.coef(): returns named coefficient estimates inscpc-python>=0.1.2result.confint(): returns named confidence intervals inscpc-python>=0.1.2result.summary(): prints the main table plus confidence intervals inscpc-python>=0.1.2result.avc: the average pairwise correlation bound used in the analysisresult.c0: the kernel scale implied byavcresult.cv: the unconditional 5% critical valueresult.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 modeldata: the data framelon,lat: the geodesic coordinate column namescoords_euclidean: use this instead oflon/latwhen coordinates are Euclidean rather than geographiccluster: optional clustering columnncoef: how many coefficients to reportavc: upper bound on the average pairwise correlationuncond: whether to skip the conditional adjustmentcvs: whether to store the extra critical values
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scpc_python-0.1.2.tar.gz.
File metadata
- Download URL: scpc_python-0.1.2.tar.gz
- Upload date:
- Size: 42.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
031d59006eb2cae0ebce9068b11fc30403a7f284107015fadf11743692a2a142
|
|
| MD5 |
41d113b9171ea903645fced013663d3c
|
|
| BLAKE2b-256 |
6c2f4ef7e49f1f0a8888f4efff274a023fe8a6783385f8894a14fc80f893bb58
|
Provenance
The following attestation bundles were made for scpc_python-0.1.2.tar.gz:
Publisher:
pypi.yaml on spatial-spur/scpc-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scpc_python-0.1.2.tar.gz -
Subject digest:
031d59006eb2cae0ebce9068b11fc30403a7f284107015fadf11743692a2a142 - Sigstore transparency entry: 1362572842
- Sigstore integration time:
-
Permalink:
spatial-spur/scpc-python@a418ab102b08a5cc494cf5fa1473b1a9e0823347 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/spatial-spur
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@a418ab102b08a5cc494cf5fa1473b1a9e0823347 -
Trigger Event:
release
-
Statement type:
File details
Details for the file scpc_python-0.1.2-py3-none-any.whl.
File metadata
- Download URL: scpc_python-0.1.2-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be715bdf7bf6dae2eca84b4a1fa92dd38578090f8ee667457e5bb085a346bc38
|
|
| MD5 |
f68e37ce67750a2b8f9bea335d9ed5a7
|
|
| BLAKE2b-256 |
dd5b4c86a10f9ca9d8cea149cac05ed6fa3d6662b70c192210d31ae126f66881
|
Provenance
The following attestation bundles were made for scpc_python-0.1.2-py3-none-any.whl:
Publisher:
pypi.yaml on spatial-spur/scpc-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scpc_python-0.1.2-py3-none-any.whl -
Subject digest:
be715bdf7bf6dae2eca84b4a1fa92dd38578090f8ee667457e5bb085a346bc38 - Sigstore transparency entry: 1362572894
- Sigstore integration time:
-
Permalink:
spatial-spur/scpc-python@a418ab102b08a5cc494cf5fa1473b1a9e0823347 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/spatial-spur
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@a418ab102b08a5cc494cf5fa1473b1a9e0823347 -
Trigger Event:
release
-
Statement type: