statsmodels
Statistical modeling and econometrics in Python, with rigorous estimation and inference.
Repository Health
Technical Analysis
statsmodels is a Python package that complements SciPy/NumPy with classical statistical modeling: linear and generalized linear models, time series analysis (ARIMA, VAR, state space models), survival analysis, and a large library of statistical tests. It emphasizes estimation, inference, and diagnostics — every model returns detailed result objects with standard errors, confidence intervals, hypothesis tests, and diagnostic statistics, not just point predictions.
Unlike machine-learning-focused libraries such as scikit-learn, statsmodels is built for researchers, economists, and analysts who need interpretable models with statistical rigor: p-values, R-style formulas, robust covariance estimators, and detailed summary tables modeled on R and Stata output conventions.
What You Get
- Linear models: OLS, GLS, WLS, quantile regression, and recursive least squares
- Generalized linear models (GLM) covering the full exponential family, plus GEE and mixed linear models
- A complete time series framework: SARIMAX, VAR/VARMAX, state space models, unobserved components, and Markov switching models
- Discrete choice models: logit, probit, multinomial logit, Poisson and negative binomial regression
- Survival analysis (Cox proportional hazards, Kaplan-Meier), multivariate methods (PCA, factor analysis, MANOVA), and a large battery of statistical tests
Common Use Cases
- Econometric research requiring detailed regression diagnostics, robust standard errors, and hypothesis tests
- Time series forecasting with ARIMA, exponential smoothing, or state space models for business and economic data
- A/B test analysis and hypothesis testing where statistical significance and confidence intervals matter more than raw prediction
- Academic and applied research reproducing R/Stata-style statistical summaries in Python
Under The Hood
Architecture — statsmodels is organized around a base.model.Model/Results split: every estimator (in regression/, genmod/, tsa/, discrete/, duration/, etc.) subclasses a common Model base that handles data preparation (base/data.py), optimization (base/optimizer.py), and formula parsing (formula/), while .fit() returns a Results wrapper exposing parameters, covariance, and diagnostics uniformly across model families; a shared wrapper.py layer re-attaches pandas indices/column names to NumPy-computed output so results stay dataframe-aware regardless of the underlying linear algebra. Tech Stack — pure Python/Cython (95% Python, ~1.4% Cython for performance-critical inner loops) built on NumPy>=1.22 and SciPy>=1.8, using Meson/meson-python as the build backend (migrated from setuptools) with Cython>=3.0 for compiled extensions; patsy/formulaic power the R-style formula API. Code Quality — the statsmodels/ package contains over 1,075 Python files with a dedicated tests/ subdirectory inside nearly every module (regression, discrete, tsa, robust, multivariate, etc.), reflecting a long-standing convention of colocated unit tests exercising each estimator against known reference values (often cross-checked against R or Stata output); the project has 500+ contributors and 16,000+ commits, indicating mature review practices. API Design — the model/fit/results pattern (sm.OLS(y, X).fit()) is highly consistent across the ~30 model families, and the formula interface (smf.ols('y ~ x1 + x2', data=df)) lowers the barrier for users coming from R, though the sheer breadth of the API and dense statistical terminology in docstrings mean newcomers face a real learning curve before finding the right model class.
Used by 3 apps in this directory
FeatBit
Devops · Developer Tools
Self-hosted, enterprise-grade feature flag platform for safe, targeted, and data-driven feature releases.
Flowfile
Data Engineering
Visual ETL that compiles to Polars — build pipelines on a canvas, export as standalone Python, and run anywhere without platform lock-in.
skrub
Developer Tools
Turn messy real-world dataframes into machine learning features — no manual wrangling required.