Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

statsmodels API: sm, smf and tsa Imports and Which Model Lives Where

The statsmodels API has three import paths. Learn which models live in sm, smf and tsa, how to install it and how to fix common import errors.

Written and maintained by CASRAI Editorial Board

Last updated

The statsmodels API is split across three import paths, and most import errors come from using the wrong one. The official API reference lists statsmodels.api for cross-sectional models, statsmodels.tsa.api for time-series models, and statsmodels.formula.api for formula-based versions of many of those models. This guide maps which model lives behind which import, so you can pick the right one before you write code. The version documented on the reference page at the time of checking (2026-10-29) is statsmodels 0.15.0.

What the statsmodels API is used for in research

statsmodels is a free Python package for estimating statistical models and running statistical tests. Researchers typically reach for it when they need regression output with standard errors, confidence intervals and test statistics rather than only predictions. The API reference groups its models into regression, generalized linear models, discrete and count models, multivariate models, and a set of other models, plus a separate time-series namespace.

The three canonical imports

The reference gives one canonical import for each namespace.

Import What the reference says it holds Typical use
import statsmodels.api as sm Cross-sectional models and methods Pass arrays or DataFrame columns: sm.OLS(y, X), sm.Logit(y, X)
import statsmodels.tsa.api as tsa Time-series models and methods tsa.ARIMA, tsa.SARIMAX, tsa.VAR
import statsmodels.formula.api as smf Lower case names that are aliases to the from_formula method of the corresponding model class Pass a formula string and a DataFrame: smf.ols('y ~ x1 + x2', data=df)

Two consequences follow from this layout. Time-series models such as ARIMA, SARIMAX and VAR are listed on the tsa.api page, not in the cross-sectional sm list. And the formula namespace is a set of lower case aliases for model classes, so a time-series class does not get a lower case formula alias there.

Which model lives where

The table below follows the grouping used on the API reference page. Class names are copied from that page.

Research task Classes (import path)
Linear regression, weighted or generalized least squares OLS, WLS, GLS, GLSAR, RecursiveLS, RollingOLS, RollingWLS (sm)
Generalized linear models GLM, GLMGam, BinomialBayesMixedGLM, PoissonBayesMixedGLM (sm)
Binary, multinomial and ordered outcomes Logit, Probit, MNLogit, OrderedModel (sm)
Count outcomes Poisson, NegativeBinomial, NegativeBinomialP, GeneralizedPoisson, and the ZeroInflated variants (sm)
Conditional (matched or stratified) outcomes ConditionalLogit, ConditionalMNLogit, ConditionalPoisson (sm)
Clustered or repeated measures GEE, NominalGEE, OrdinalGEE; MixedLM (sm)
Robust, quantile and survival-style models RLM, QuantReg, PHReg, SurvfuncRight (sm)
Multivariate methods Factor, MANOVA, PCA (sm)
Univariate time series AutoReg, ARDL, ARIMA, SARIMAX, UECM (tsa)
Exponential smoothing and forecasting ExponentialSmoothing, Holt, SimpleExpSmoothing, ETSModel, STLForecast, ThetaModel (tsa)
Multivariate time series DynamicFactor, DynamicFactorMQ, VAR, VARMAX, SVAR, VECM, UnobservedComponents (tsa)
Regime switching MarkovAutoregression, MarkovRegression (tsa)

The reference lists lower case formula aliases for many of the sm models, including ols, wls, gls, glsar, glm, gee, mixedlm, rlm, logit, probit, mnlogit, poisson, negativebinomial, quantreg and phreg. For the model theory behind a family, see the CASRAI guide on the generalized linear model.

Install or access (official source only)

The official installation page gives these two commands:

  • pip: python -m pip install statsmodels
  • conda: conda install -c conda-forge statsmodels

The same page lists the current minimum dependencies as Python 3.9 or later, NumPy 1.23.5, SciPy 1.8, pandas 1.4 and Patsy 0.5.6 (checked 2026-10-29 for statsmodels 0.15.0). Patsy is listed there as a dependency, and the formula interface (smf) relies on it.

Step-by-step: pick the import and fit a model

  1. Decide whether your data are time-ordered. If you are fitting ARIMA, SARIMAX, VAR, exponential smoothing or another model from the time-series table above, import statsmodels.tsa.api as tsa and use the class from there. Otherwise continue.
  2. Choose array style or formula style. With sm, you pass the outcome and a design matrix. With smf, you pass a formula string and a DataFrame.
  3. Array style. Import statsmodels.api as sm, build your predictor matrix, add an intercept if you want one, then describe and fit the model:
    import statsmodels.api as sm
    X = sm.add_constant(X)
    res = sm.OLS(y, X).fit()
    print(res.summary())

    The OLS reference states that no constant is added by the model unless you are using formulas, so the intercept is your responsibility in array style.

  4. Formula style. Import statsmodels.formula.api as smf and pass a formula and a DataFrame:
    import statsmodels.formula.api as smf
    res = smf.ols('y ~ x1 + x2', data=df).fit()
    print(res.summary())

    Because the lower case name is an alias for the model class’s from_formula method, the formula route is where the intercept is added for you.

  5. Time-series style. Import the class from the time-series namespace, for example import statsmodels.tsa.api as tsa, then use tsa.ARIMA or another class from that list.

For a complete worked regression on this API, see the CASRAI guide on statsmodels OLS. For comparing group means with the same package, see ANOVA in Python with statsmodels.

Output and how to read it

fit() returns a results object, and summary() prints the table of coefficients, standard errors, test statistics and fit measures. For the regression results classes, the same numbers are available as attributes: params, bse, tvalues, pvalues, conf_int(), rsquared_adj, fvalue and f_pvalue. Pull values from these attributes instead of copying numbers by hand from the printed table. The CASRAI guide on how to read a regression table explains each column.

Troubleshooting

The model you want is not found on sm

Check the time-series list above. ARIMA, SARIMAX, VAR and the other time-series classes appear on the statsmodels.tsa.api reference page, so import them through tsa rather than looking for them in the cross-sectional list.

The model is not found on smf

The formula namespace holds lower case aliases for model classes. Use the lower case name (smf.ols, not smf.OLS), and do not expect a formula alias for the time-series classes.

The fitted intercept is missing

In array style the model does not add a constant. Call sm.add_constant on the predictors, or switch to the formula route.

Installation or version conflicts

Compare your Python, NumPy, SciPy, pandas and Patsy versions with the minimums in the install section above, and upgrade whichever one is older.

Free alternatives

Package What it is Where to read about it
SciPy (scipy.stats) Free Python package with statistical tests and probability distributions scipy.org; CASRAI guide to scipy.stats
scikit-learn Free Python package for machine learning scikit-learn.org; CASRAI scikit-learn tutorial

statsmodels is also free. For a wider view of Python for analysis, see data analysis tools in Python.

FAQ

What is the difference between statsmodels.api and statsmodels.formula.api?

The first holds the model classes and takes arrays or DataFrame columns. The second holds lower case aliases to each model’s from_formula method, so you pass a formula string and a DataFrame instead.

How do I import statsmodels the usual way?

The reference gives import statsmodels.api as sm, import statsmodels.tsa.api as tsa and import statsmodels.formula.api as smf as the canonical forms.

Where is ARIMA in statsmodels?

On the statsmodels.tsa.api reference page, imported as tsa in the canonical form.

Do I need to add a constant to my predictors?

In array style, yes: the OLS reference says no constant is added unless you use formulas. In formula style, it is added for you.

Sources (official docs)

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about statsmodels API: sm, smf and tsa Imports and Which Model Lives Where

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →