API Reference

The main statsmodels API is split into models:

  • statsmodels.api: Cross-sectional models and methods. Canonically imported using import statsmodels.api as sm.

  • statsmodels.tsa.api: Time-series models and methods. Canonically imported using import statsmodels.tsa.api as tsa.

  • statsmodels.formula.api: A convenience interface for specifying models using formula strings and DataFrames. This API directly exposes the from_formula class method of models that support the formula API. Canonically imported using import statsmodels.formula.api as smf

The API focuses on models and the most frequently used statistical test, and tools. Import Paths and Structure explains the design of the two API modules and how importing from the API differs from directly importing from the module where the model is defined. See the detailed topic pages in the User Guide for a complete list of available models, statistics, and tools.

statsmodels.api

Regression

OLS(endog[, exog, missing, hasconst])

Ordinary Least Squares

WLS(endog, exog[, weights, missing, hasconst])

Weighted Least Squares

GLS(endog, exog[, sigma, missing, hasconst])

Generalized Least Squares

GLSAR(endog[, exog, rho, missing, hasconst])

Generalized Least Squares with AR covariance structure

RecursiveLS(endog, exog[, constraints])

Recursive least squares

RollingOLS(endog, exog[, window, min_nobs, ...])

Rolling Ordinary Least Squares

RollingWLS(endog, exog[, window, weights, ...])

Rolling Weighted Least Squares

Imputation

BayesGaussMI(data[, mean_prior, cov_prior, ...])

Bayesian Imputation using a Gaussian model.

MI(imp, model[, model_args_fn, ...])

MI performs multiple imputation using a provided imputer object.

MICE(model_formula, model_class, data[, ...])

Multiple Imputation with Chained Equations.

MICEData(data[, perturbation_method, k_pmm, ...])

Wrap a data set to allow missing data handling with MICE.

Generalized Estimating Equations

GEE(endog, exog, groups[, time, family, ...])

Marginal Regression Model using Generalized Estimating Equations.

NominalGEE(endog, exog, groups[, time, ...])

Nominal Response Marginal Regression Model using GEE.

OrdinalGEE(endog, exog, groups[, time, ...])

Ordinal Response Marginal Regression Model using GEE

Generalized Linear Models

GLM(endog, exog[, family, offset, exposure, ...])

Generalized Linear Models

GLMGam(endog[, exog, smoother, alpha, ...])

Generalized Additive Models (GAM)

BinomialBayesMixedGLM(endog, exog, exog_vc, ...)

Generalized Linear Mixed Model with Bayesian estimation

PoissonBayesMixedGLM(endog, exog, exog_vc, ident)

Generalized Linear Mixed Model with Bayesian estimation

Discrete and Count Models

Logit(endog, exog[, offset, check_rank])

Logit Model

Probit(endog, exog[, offset, check_rank])

Probit Model

MNLogit(endog, exog[, check_rank])

Multinomial Logit Model

OrderedModel(endog, exog[, offset, distr])

Ordinal Model based on logistic or normal distribution

Poisson(endog, exog[, offset, exposure, ...])

Poisson Model

NegativeBinomial(endog, exog[, ...])

Negative Binomial Model

NegativeBinomialP(endog, exog[, p, offset, ...])

Generalized Negative Binomial (NB-P) Model

GeneralizedPoisson(endog, exog[, p, offset, ...])

Generalized Poisson Model

ZeroInflatedPoisson(endog, exog[, ...])

Poisson Zero Inflated Model

ZeroInflatedNegativeBinomialP(endog, exog[, ...])

Zero Inflated Generalized Negative Binomial Model

ZeroInflatedGeneralizedPoisson(endog, exog)

Zero Inflated Generalized Poisson Model

ConditionalLogit(endog, exog[, missing])

Fit a conditional logistic regression model to grouped data.

ConditionalMNLogit(endog, exog[, missing])

Fit a conditional multinomial logit model to grouped data.

ConditionalPoisson(endog, exog[, missing])

Fit a conditional Poisson regression model to grouped data.

Multivariate Models

Factor([endog, n_factor, corr, method, smc, ...])

Factor analysis

MANOVA(endog, exog[, missing, hasconst])

Multivariate Analysis of Variance

PCA(data[, ncomp, standardize, demean, ...])

Principal Component Analysis

Other Models

MixedLM(endog, exog, groups[, exog_re, ...])

Linear Mixed Effects Model

SurvfuncRight(time, status[, entry, title, ...])

Estimation and inference for a survival function.

PHReg(endog, exog[, status, entry, strata, ...])

Cox Proportional Hazards Regression Model

QuantReg(endog, exog, **kwargs)

Quantile Regression

RLM(endog, exog[, M, missing])

Robust Linear Model

BetaModel(endog, exog[, exog_precision, ...])

Beta Regression.

Graphics

ProbPlot(data[, dist, fit, distargs, a, ...])

Q-Q and P-P Probability Plots

qqline(ax, line[, x, y, dist, fmt])

Plot a reference line for a qqplot.

qqplot(data[, dist, distargs, a, loc, ...])

Q-Q plot of the quantiles of x versus the quantiles/ppf of a distribution.

qqplot_2samples(data1, data2[, xlabel, ...])

Q-Q Plot of two samples' quantiles.

Statistics

Description(data[, stats, numeric, ...])

Extended descriptive statistics for data

describe(data[, stats, numeric, ...])

Extended descriptive statistics for data

Tools

test([extra_args, exit])

Run the test suite

add_constant(data[, prepend, has_constant])

Add a column of ones to an array.

load_pickle(fname)

Load a previously saved object

show_versions([show_dirs])

List the versions of statsmodels and any installed dependencies

webdoc([func, stable])

Opens a browser and displays online documentation

statsmodels.tsa.api

Statistics and Tests

acf(x[, adjusted, nlags, qstat, fft, alpha, ...])

Calculate the autocorrelation function.

acovf(x[, adjusted, demean, fft, missing, nlag])

Estimate autocovariances.

adfuller(x[, maxlag, regression, autolag, ...])

Augmented Dickey-Fuller unit root test.

bds(x[, max_dim, epsilon, distance])

BDS Test Statistic for Independence of a Time Series

ccf(x, y[, adjusted, fft, nlags, alpha])

The cross-correlation function.

ccovf(x, y[, adjusted, demean, fft])

Calculate the cross-covariance between two series.

coint(y0, y1[, trend, method, maxlag, ...])

Test for no-cointegration of a univariate equation.

kpss(x[, regression, nlags, store])

Kwiatkowski-Phillips-Schmidt-Shin test for stationarity.

pacf(x[, nlags, method, alpha])

Partial autocorrelation estimate.

pacf_ols(x[, nlags, efficient, adjusted])

Calculate partial autocorrelations via OLS.

pacf_yw(x[, nlags, method])

Partial autocorrelation estimated with non-recursive yule_walker.

q_stat(x, nobs)

Compute Ljung-Box Q Statistic.

range_unit_root_test(x[, store])

Range unit-root test for stationarity.

zivot_andrews

Zivot-Andrews structural-break unit-root test.

Univariate Time-Series Analysis

AutoReg(endog, lags[, trend, seasonal, ...])

Autoregressive AR-X(p) model

ARDL(endog, lags[, exog, order, trend, ...])

Autoregressive Distributed Lag (ARDL) Model

ARIMA(endog[, exog, order, seasonal_order, ...])

Autoregressive Integrated Moving Average (ARIMA) model, and extensions

SARIMAX(endog[, exog, order, ...])

Seasonal AutoRegressive Integrated Moving Average with eXogenous regressors model

ardl_select_order(endog, maxlag, exog, maxorder)

ARDL order selection

arma_order_select_ic(y[, max_ar, max_ma, ...])

Compute information criteria for many ARMA models.

arma_generate_sample(ar, ma, nsample[, ...])

Simulate data from an ARMA.

ArmaProcess([ar, ma, nobs])

Theoretical properties of an ARMA process for specified lag-polynomials.

UECM(endog, lags[, exog, order, trend, ...])

Unconstrained Error Correlation Model(UECM)

Exponential Smoothing

ExponentialSmoothing(endog[, trend, ...])

Holt Winter's Exponential Smoothing

Holt(endog[, exponential, damped_trend, ...])

Holt's Exponential Smoothing

SimpleExpSmoothing(endog[, ...])

Simple Exponential Smoothing

ExponentialSmoothing(endog[, trend, ...])

Linear exponential smoothing models

ETSModel(endog[, error, trend, ...])

ETS models.

Multivariate Time Series Models

DynamicFactor(endog, k_factors, factor_order)

Dynamic factor model

DynamicFactorMQ(endog[, k_endog_monthly, ...])

Dynamic factor model with EM algorithm; option for monthly/quarterly data.

VAR(endog[, exog, dates, freq, missing])

Fit VAR(p) process and do lag order selection

VARMAX(endog[, exog, order, trend, ...])

Vector Autoregressive Moving Average with eXogenous regressors model

SVAR(endog, svar_type[, dates, freq, A, B, ...])

Fit VAR and then estimate structural components of A and B, defined:

VECM(endog[, exog, exog_coint, dates, freq, ...])

Class representing a Vector Error Correction Model (VECM).

UnobservedComponents(endog[, level, trend, ...])

Univariate unobserved components time series model

Filters and Decompositions

seasonal_decompose(x[, model, filt, period, ...])

Seasonal decomposition using moving averages.

STL(endog[, period, seasonal, trend, ...])

Season-Trend decomposition using LOESS.

MSTL(endog[, periods, windows, lmbda, ...])

Season-Trend decomposition using LOESS for multiple seasonalities.

bkfilter(x[, low, high, K])

Filter a time series using the Baxter-King bandpass filter.

cffilter(x[, low, high, drift])

Christiano Fitzgerald asymmetric, random walk filter.

hpfilter(x[, lamb])

Hodrick-Prescott filter.

Markov Regime Switching Models

MarkovAutoregression(endog, k_regimes, order)

Markov switching regression model

MarkovRegression(endog, k_regimes[, trend, ...])

First-order k-regime Markov switching regression model

Forecasting

STLForecast(endog, model, *[, model_kwargs, ...])

Model-based forecasting using STL to remove seasonality

ThetaModel(endog, *[, period, ...])

The Theta forecasting model of Assimakopoulos and Nikolopoulos (2000)

Time-Series Tools

add_lag(x[, col, lags, drop, insert])

Returns an array with lags included given an array.

add_trend(x[, trend, prepend, has_constant])

Add a trend and/or constant to an array.

detrend(x[, order, axis])

Detrend an array with a trend of given order along axis 0 or 1.

lagmat(x, maxlag[, trim, original, use_pandas])

Create 2d array of lags.

lagmat2ds(x, maxlag0[, maxlagex, dropex, ...])

Generate lagmatrix for 2d array, columns arranged by variables.

DeterministicProcess(index, *[, period, ...])

Container class for deterministic terms.

X12/X13 Interface

x13_arima_analysis(endog[, maxorder, ...])

Perform x13-arima analysis for monthly or quarterly data.

x13_arima_select_order(endog[, maxorder, ...])

Perform automatic seasonal ARIMA order identification using x12/x13 ARIMA.

statsmodels.formula.api

Models

The lower case names are aliases to the from_formula method of the corresponding model class. The function descriptions of the methods exposed in the formula API are generic. See the documentation for the parent model for details.

gls(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

wls(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

ols(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

glsar(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

mixedlm(formula, data[, re_formula, ...])

Create a Model from a formula and dataframe.

glm(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

gee(formula, groups, data[, subset, time, ...])

Create a Model from a formula and dataframe.

ordinal_gee(formula, groups, data[, subset, ...])

Create a Model from a formula and dataframe.

nominal_gee(formula, groups, data[, subset, ...])

Create a Model from a formula and dataframe.

rlm(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

logit(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

probit(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

mnlogit(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

poisson(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

negativebinomial(formula, data[, subset, ...])

Create a Model from a formula and dataframe.

quantreg(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

phreg(formula, data[, status, entry, ...])

Create a proportional hazards regression model from a formula and dataframe.

glmgam(formula, data[, subset, drop_cols])

Create a Model from a formula and dataframe.

conditional_logit(formula, data[, subset, ...])

Create a Model from a formula and dataframe.

conditional_mnlogit(formula, data[, subset, ...])

Create a Model from a formula and dataframe.

conditional_poisson(formula, data[, subset, ...])

Create a Model from a formula and dataframe.


Last update: Oct 03, 2024