spglm
Sparse Generalized Linear Models
What it is and what it does
spglm is a lightweight, sparse-compatible implementation of generalized linear modeling adapted from Statsmodels. It provides estimation of Gaussian, Poisson, QuasiPoisson, and Logistic regression models using iteratively weighted least squares (IWLS), designed specifically for the sparse design matrices that arise in spatial interaction and geographic weighted regression problems. The package trades some diagnostic breadth for computational efficiency and sparse-matrix support, making it a specialized tool for spatial statistics rather than a general-purpose GLM framework.
The package depends on numpy, scipy, libpysal, and spreg, and is maintained as part of the PySAL ecosystem. It supports Python 3.9 and later and installs with low friction. The implementation solves least-squares normal equations directly rather than using pseudo-inverse methods, which the authors note is less robust for ill-conditioned data; for more comprehensive GLM functionality they recommend the original Statsmodels package.
Use it for:
- Fit Poisson or Logistic models to sparse spatial interaction matrices in transportation or migration studies.
- Estimate geographic weighted regression (GWR) components with sparse design matrices.
- Perform QuasiPoisson regression when overdispersion is present in count data.
- Compute GLM diagnostics (residuals, fitted values, deviance) for sparse regression problems.
- Build spatial statistical models as part of a PySAL-based analysis pipeline.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Fits Gaussian, Poisson, QuasiPoisson, and Logistic generalized linear models using iteratively weighted least squares, with full support for sparse design matrices.
Yes, if you are working with sparse generalized linear models in a spatial statistics context (especially within PySAL). Install with caution if you need robust estimation of ill-conditioned data—the package's direct normal-equation solver is not the most numerically stable approach; Statsmodels is better for that. No known vulnerabilities and active maintenance make it a safe dependency.
Install
spglm on PyPI
pip
pip install spglmuv
uv add spglmpoetry
poetry add spglmInstalling spglm
Before you install
Low friction: pure Python wheel with four standard dependencies (numpy, scipy, libpysal, spreg). Actively maintained as of July 2026 with no known vulnerabilities.
License in practice
BSD 3-Clause permissive license allows commercial and private use with attribution; no restrictions on derivative works.
Quickstart
pip install spglm
import spglm
from spglm.glm import GLM
model = GLM(y, X, family=spglm.family.Gaussian())
results = model.fit()
Requires Python 3.9 or later.
Verify before relying
- Whether the package is actively used in production spatial analysis workflows beyond PySAL ecosystem.
- Performance characteristics and scalability limits for very large sparse matrices.
- Availability and completeness of documentation beyond the homepage.
Package facts
| License | BSD 3-Clause (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — libpysal, numpy, scipy, spreg |
| Maintenance | actively maintained — 1,024 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 103,036/month — #12,832 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: spglm-1.1.0-py3-none-any.whl
Keywords: spatial, statistics
Tags
More GIS packages
Shapely provides Python tools for creating,…
permissive · top 1,000 on PyPI
pyprojpyproj provides a Python interface to PROJ,…
permissive · top 1,000 on PyPI
geopandasGeoPandas extends pandas DataFrames to handle…
permissive · top 1,000 on PyPI
geopygeopy is a Python client for geocoding and…
permissive · top 5,000 on PyPI
pyogrioPyogrio provides fast, bulk-oriented read and…
permissive · top 5,000 on PyPI
h3h3 provides Python bindings to Uber's H3…
permissive · top 5,000 on PyPI
glumglum is a high-performance Python library for…
permissive · top 15,000 on PyPI
gmrGaussian Mixture Models for clustering and…
permissive · top 15,000 on PyPI
mgwrCalibrates multiscale and traditional…
permissive · top 15,000 on PyPI
qdldlProvides a Python interface to QDLDL, a free…
permissive · top 5,000 on PyPI
spintSpInt calibrates spatial interaction models…
permissive · top 15,000 on PyPI
statsmodelsstatsmodels provides statistical models,…
permissive · top 1,000 on PyPI
dask-glmDistributed generalized linear model fitting…
permissive · top 15,000 on PyPI
linearmodelsProvides panel regression, instrumental…
unclear · top 15,000 on PyPI
spregspreg estimates simultaneous autoregressive…
permissive · top 15,000 on PyPI
tabmatProvides efficient matrix classes for tabular…
unclear · top 15,000 on PyPI