skillfed

spglm

Sparse Generalized Linear Models

spglm v1.1.0 103.0K downloads/30d#12,832 on PyPI37
Permissive license BSD 3-Clause Active released

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 spglm

uv

uv add spglm

poetry

poetry add spglm

Installing 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

Intended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.9Topic :: Scientific/Engineering :: GIS

Tags

sparse generalized linear modelsGLM with sparse matricespoisson regression sparselogistic regression sparsespatial statistics regressionIWLS estimationquasipoisson regression
spatial-statisticssparse-matricesglm

More GIS packages

Further reading