statsmodels

Statistical models library for Python. Use when you need specific model classes (OLS, GLM, mixed models, ARIMA) with detailed diagnostics, residuals, and inference. Best for econometrics, time series, rigorous inference with coefficient tables. For guided statistical test selection with APA reporting use statistical-analysis.

Install

Hot:45

Download and extract to your skills directory

Copy command and send to AI Agent for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=k-dense-ai-skills-statsmodels&locale=en&source=copy

Statsmodels: Python Statistical Modeling and Econometrics Analysis Library

Overview of Skills


Statsmodels is a leading Python library for statistical modeling and econometrics analysis. It provides comprehensive statistical inference, diagnostics, and visualization capabilities—from simple linear regression to complex time-series models. It is especially well suited for academic research and professional analysis scenarios that require rigorous statistical inference and publication-quality result output.

Use Cases

1. Regression Modeling and Statistical Inference


When you need to perform regression analysis on a continuous dependent variable and obtain coefficient significance tests, confidence intervals, and diagnostic statistics, Statsmodels offers complete linear models such as OLS, WLS, and GLS, along with heteroskedasticity-consistent standard errors, influence statistics, and model comparison tests. Compared with machine learning libraries, Statsmodels emphasizes the statistical properties of parameter estimation and inference, making it an ideal tool for economics, social science, and medical research.

2. Time Series Analysis and Forecasting


When working with financial, economic, or scientific observation data, Statsmodels provides time-series models such as ARIMA, SARIMAX, and VAR. It supports stationarity tests (ADF, KPSS), autocorrelation analysis (ACF/PACF), forecasting with confidence intervals, and Granger causality tests. Whether you are predicting stock prices, analyzing macroeconomic indicators, or modeling sensor data, you can obtain statistically rigorous forecasting results and diagnostic reports.

3. Generalized Linear Models and Count Data Analysis


For binary choice (Logit/Probit), count data (Poisson/Negative Binomial), or ordered discrete outcomes, Statsmodels offers a GLM framework and discrete choice models. It supports multiple distribution families and link functions, automatically computes marginal effects and odds ratios, and is suitable for classification data analysis in market research, biostatistics, and social surveys.

Core Features

1. Linear Regression Model Suite


Statsmodels provides a complete toolbox of linear models, including OLS (ordinary least squares), WLS (weighted least squares), GLS (generalized least squares), quantile regression, and mixed-effects models. It includes built-in Breusch-Pagan heteroskedasticity tests, Durbin-Watson autocorrelation tests, VIF multicollinearity diagnostics, Cook’s distance influence statistics, and AIC/BIC model comparison. With an R-style formula API, it is easy to specify interaction terms, polynomial terms, and categorical variables.

2. Time Series Modeling and Forecasting


It supports single-variable and multivariable time-series models such as AR, ARIMA, SARIMAX, exponential smoothing (Holt-Winters), and VAR. It provides ACF/PACF autocorrelation plots, stationarity tests, rolling forecasts with prediction intervals, impulse response functions (IRF), and forecast error variance decomposition (FEVD). Built-in Ljung-Box residual tests help ensure that model assumptions hold. It is suitable for short-term forecasting and long-term dynamic analysis.

3. Statistical Testing and Diagnostic Tools


It covers both parametric and nonparametric tests, including t-tests, analysis of variance (ANOVA), chi-square tests, and Mann-Whitney tests. It supports multiple-comparison corrections (Tukey HSD, Bonferroni, FDR) and effect size calculations (Cohen’s d). It provides residual normality tests (Jarque-Bera, Anderson-Darling), specification tests (RESET), and robust standard errors (HC0–HC3, Newey-West HAC), enabling comprehensive validation of model assumptions and data quality.

Frequently Asked Questions

What are the differences between Statsmodels and scikit-learn? When should I use each?


Statsmodels focuses on statistical inference and interpretation. It provides detailed coefficient tables, significance tests, confidence intervals, and diagnostic statistics, making it suitable for academic research, econometrics, and situations where you need to interpret the effects of variables. scikit-learn focuses on predictive performance and machine learning workflows. It provides cross-validation, hyperparameter tuning, and a rich library of algorithms, making it suitable for classification prediction, regression prediction, and model deployment. If your goal is to understand variable relationships and obtain publication-quality statistical tables, choose Statsmodels; if your goal is to maximize prediction accuracy, choose scikit-learn.

How do I use Statsmodels to run linear regression and obtain significance tests?


Use the statsmodels.api module. First, call sm.add_constant(X) to add an intercept term to the design matrix, then fit the model with sm.OLS(y, X). Call .fit() to obtain the results object. The .summary() method of the results object outputs a complete regression coefficients table, including coefficient estimates, standard errors, t statistics, and p-values, as well as model fit metrics (R², adjusted R²), the F statistic, and AIC/BIC information criteria. Code example: model = sm.OLS(y, sm.add_constant(X)); results = model.fit(); print(results.summary()). You can use results.pvalues to view p-values and results.conf_int() to obtain confidence intervals.

What time-series models does Statsmodels support, and how do I choose ARIMA parameters?


Statsmodels supports autoregressive (AR) models, ARIMA (autoregressive integrated moving average) models, SARIMAX (seasonal ARIMA with exogenous variables), vector autoregression (VAR), exponential smoothing (Simple, Holt, Holt-Winters), and state-space models. When selecting ARIMA parameters, first use adfuller to perform the ADF stationarity test to determine the differencing order d. Then draw ACF and PACF correlation plots to identify the AR order p and MA order q (ACF cutoff suggests MA, PACF cutoff suggests AR). After fitting with ARIMA(y, order=(p,d,q)), check residual plots using .plot_diagnostics() and run the Ljung-Box test to ensure the residuals have no autocorrelation.