Registry / data / spreg
library1.9.0pypypi✓ verified 83d ago

PySAL Spatial Econometric Regression in Python. Provides spatial regression models (OLS, ML, GM, Panel) and diagnostics. Current version: 1.9.0. Released approximately every 3-6 months.

pip install spreg
INSTALL
IMPORT
SIG · SPREG
S
spreg
datapythonv1.9.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OLS
from spreg import OLS
from spreg.ols import OLS
Top-level import is the correct pattern
GM_Lag
from spreg import GM_Lag
from spreg.GM import GM_Lag
GM_Lag is a top-level class, not in a submodule
ML_Error
from spreg import ML_Error
from spreg.ML import ML_Error
ML classes are at top-level
spsearch
from spreg import spsearch
Added in v1.8.0

Basic OLS with spatial diagnostics using random data and distance-based weights.

import numpy as np import libpysal from spreg import OLS # Generate random data np.random.seed(123) n = 100 x = np.random.randn(n, 2) y = 1 + 2*x[:,0] + 3*x[:,1] + np.random.randn(n)*0.5 # Create spatial weights (Queen contiguity from random points) pts = np.random.rand(n, 2) w = libpysal.weights.DistanceBand.from_array(pts, threshold=0.5, binary=True) w.transform = 'r' # Fit OLS m1 = OLS(y, x, w=w, spat_diag=True) print(m1.summary)
Debug
Known issues
breakingIn v1.8+, spreg automatically converts sparse and full weights matrices to libpysal W objects. If you relied on passing raw scipy sparse matrices, they will be converted, which may change behavior.
fix
Ensure your weights are passed as libpysal W objects or accept automatic conversion. If you need the old behavior, convert to W yourself.
affects: >=1.8.0
deprecatedcheck_spat_diag was deprecated in v1.6.1 and removed in later versions. Use spat_diag=True in model constructors instead.
fix
Replace check_spat_diag(y, x, w) with OLS(y, x, w, spat_diag=True) or equivalent.
affects: >=1.6.1
gotchaWhen using regime models (e.g., OLS_Regimes), the regimes argument must be a pandas Categorical or a list of strings with length equal to number of observations. Mixing types can cause silent errors.
fix
Convert regimes to a pandas Categorical: regimes = pd.Categorical(regimes). Then pass to the model.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'OLS' from 'spreg.ols'
Incorrect import path for OLS class.
fix
Use: from spreg import OLS
ValueError: The weights matrix must be a W object.
Passed a raw scipy sparse matrix or numpy array instead of a libpysal W object.
fix
Convert your weights using libpysal.weights.W(weights_matrix) or use libpysal.weights to read shapefiles.
TypeError: regimes must be a pandas Categorical or a list of strings with length equal to the number of observations.
Regimes argument is not properly formatted.
fix
Ensure regimes is either a pandas Categorical or a list of strings of length n. Example: regimes = pd.Categorical(['a','b']*50)
Upgrade
Version history
1.9.0latest on PyPI · released Mar 24, 2026
Audit
Dependencies
libpysalrequiredProvides spatial weights (W) and other spatial utilities
pandasrequiredData I/O and DataFrame support
numpyrequiredNumerical computation
scipyrequiredSparse matrix operations and optimization
Agent activity
18 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
spreg — pip install spreg · libregistry