statsmodels

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

Updated Oct 7, 2022
One-click install
npx skills add https://github.com/tamagusko/linux-cfg --skill statsmodels-tamagusko
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: statsmodels
Source: https://github.com/tamagusko/linux-cfg/tree/main/dotfiles/claude/skills/statsmodels
Command: npx skills add https://github.com/tamagusko/linux-cfg --skill statsmodels-tamagusko

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 means stitching together model fitting, assumption testing, and inference by hand. This Skill provides guided workflows for statsmodels so you get correct model classes, diagnostics, and publication-ready coefficient tables without memorizing the API. ## Core Features & Use Cases - Regression and GLM modeling: Fit OLS, WLS, GLS, quantile regression, logistic, Poisson, Negative Binomial, and mixed effects models with robust standard errors. - Time series analysis: Build ARIMA, SARIMAX, VAR, and state space models with stationarity tests, ACF/PACF identification, and forecasts with confidence intervals. - Diagnostics and inference: Run heteroskedasticity, autocorrelation, normality, and influence tests, plus ANOVA, multiple comparisons, and power analysis. - Use Case: Given a dataset of patient visits, fit a Negative Binomial model after detecting overdispersion in a Poisson fit, interpret rate ratios, and validate residuals before reporting. ## Quick Start Ask the AI to fit an OLS regression of your outcome on your predictors using statsmodels, including a constant term, residual diagnostics, and a full summary table.

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(X), then call fit() and print results.summary() for coefficients, p-values, and R-squared. The formula API smf.ols('y ~ x1 + x2', data=df) handles categorical variables automatically.

How do I check for overdispersion in a Poisson regression?

Divide the Pearson chi-squared statistic by residual degrees of freedom; a ratio above roughly 1.5 indicates overdispersion. When detected, refit with NegativeBinomial and compare AIC values to confirm the improvement.

What is the difference between statsmodels and scikit-learn for regression?

statsmodels focuses on statistical inference with detailed summaries, p-values, confidence intervals, and diagnostic tests. scikit-learn targets prediction accuracy with cross-validation and pipelines but provides minimal inferential statistics.

Does statsmodels support time series forecasting with ARIMA?

Yes, statsmodels includes ARIMA, SARIMAX, VAR, and exponential smoothing models. Use adfuller to test stationarity, ACF/PACF plots to identify orders, then call forecast() or get_forecast() for predictions with confidence intervals.

Why does my logistic regression fail to converge in statsmodels?

Non-convergence usually comes from perfect separation, where a predictor perfectly predicts the outcome, or from unscaled features. Check for separation in contingency tables, scale continuous predictors, and inspect optimization warnings.

When should I use robust standard errors in regression?

Use heteroskedasticity-consistent (HC) or cluster-robust standard errors when Breusch-Pagan or White tests reject homoskedasticity, or when observations are grouped. Apply them via results.get_robustcov_results(cov_type='HC3') without refitting the model.