statsmodels

Fit statistical models in Python with diagnostics, inference, and forecasting.

Updated Aug 12, 2026
One-click install
npx skills add https://github.com/littlt-momo-c-yfc/skills --skill statsmodels-littlt-momo-c-yfc
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: statsmodels
Source: https://github.com/littlt-momo-c-yfc/skills/tree/main/skills/scientific-toolkit-skill/references/scientific-skills/statsmodels
Command: npx skills add https://github.com/littlt-momo-c-yfc/skills --skill statsmodels-littlt-momo-c-yfc

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires statsmodels, numpy, pandas, scipy, matplotlib, scikit-learn, and includes references (resource) components.

What problem does it solve? Running rigorous statistical analysis in Python often requires stitching together model fitting, assumption testing, and inference reporting by hand. This Skill provides guided workflows for statsmodels so you can fit regression, GLM, discrete choice, and time series models with proper diagnostics and publication-ready output. ## Core Features & Use Cases - Regression and GLM Modeling: Fit OLS, WLS, GLS, quantile regression, logistic, Poisson, Negative Binomial, and Gamma models with coefficient tables and robust standard errors. - Time Series Analysis: Build ARIMA, SARIMAX, VAR, and state space models with stationarity tests, ACF/PACF identification, and forecast intervals. - Diagnostics and Inference: Run heteroskedasticity, autocorrelation, normality, and influence tests, plus ANOVA, multiple comparisons, and power analysis. - Use Case: A researcher analyzing count data on hospital visits can fit a Poisson model, detect overdispersion, switch to Negative Binomial, and report rate ratios with confidence intervals. ## Quick Start Ask the agent to fit an OLS regression of your outcome on your predictors using statsmodels and show the full summary with residual diagnostics.

Frequently Asked Questions about statsmodels

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run a linear regression in Python with statsmodels?

Use sm.OLS with a constant added via sm.add_constant, then call fit() and print results.summary() for coefficients, p-values, and R-squared. The formula API smf.ols('y ~ x1 + x2', data=df) offers R-style syntax with automatic categorical handling.

How to choose between Poisson and Negative Binomial regression?

Fit a Poisson model first and check overdispersion by dividing Pearson chi-squared by residual degrees of freedom. If the ratio exceeds roughly 1.5, switch to Negative Binomial, which adds a dispersion parameter to handle variance exceeding the mean.

statsmodels vs scikit-learn for regression, which should I use?

statsmodels is better for statistical inference: detailed coefficient tables, p-values, confidence intervals, and diagnostic tests. scikit-learn targets prediction accuracy with cross-validation and pipelines but lacks built-in inferential statistics.

Does statsmodels support logistic regression with odds ratios?

Yes, fit a Logit model from statsmodels.discrete.discrete_model and exponentiate the coefficients with np.exp(results.params) to get odds ratios. Marginal effects are available via results.get_margeff().

Why does my ARIMA forecast fail on non-stationary data?

ARIMA requires stationary input, so test with the ADF test first and difference the series if the p-value exceeds 0.05. Alternatively specify the integration order d in ARIMA(order=(p,d,q)) so differencing happens inside the model.

How do I get heteroskedasticity-robust standard errors in statsmodels?

Call results.get_robustcov_results(cov_type='HC3') on a fitted model for heteroskedasticity-consistent standard errors. Use cov_type='HAC' with maxlags for autocorrelated time series errors or cov_type='cluster' with groups for clustered data.