API 參考

主要的 statsmodels API 分為模型

  • statsmodels.api:橫斷面模型和方法。通常使用 import statsmodels.api as sm 匯入。

  • statsmodels.tsa.api:時間序列模型和方法。通常使用 import statsmodels.tsa.api as tsa 匯入。

  • statsmodels.formula.api:一個方便的介面,用於使用公式字串和 DataFrames 指定模型。此 API 直接公開支援公式 API 的模型的 from_formula 類別方法。通常使用 import statsmodels.formula.api as smf 匯入

API 著重於模型和最常用的統計檢定及工具。匯入路徑和結構 解釋了兩個 API 模組的設計,以及從 API 匯入與直接從模型定義所在的模組匯入有何不同。請參閱 使用者指南 中的詳細主題頁面,以取得可用模型、統計資料和工具的完整列表。

statsmodels.api

迴歸

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

普通最小平方法

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

加權最小平方法

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

廣義最小平方法

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

具有 AR 共變異數結構的廣義最小平方法

RecursiveLS(endog, exog[, constraints])

遞迴最小平方法

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

滾動普通最小平方法

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

滾動加權最小平方法

插補

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

使用高斯模型的貝氏插補。

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

MI 使用提供的插補器物件執行多次插補。

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

使用鏈式方程式的多次插補。

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

包裝一個資料集,以允許使用 MICE 處理遺失的資料。

廣義估計方程式

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

使用廣義估計方程式的邊際迴歸模型。

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

使用 GEE 的名義反應邊際迴歸模型。

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

使用 GEE 的序數反應邊際迴歸模型

廣義線性模型

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

廣義線性模型

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

廣義加成模型 (GAM)

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

具有貝氏估計的廣義線性混合模型

PoissonBayesMixedGLM(endog, exog, exog_vc, ident)

具有貝氏估計的廣義線性混合模型

離散和計數模型

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

Logit 模型

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

Probit 模型

MNLogit(endog, exog[, check_rank])

多項式 Logit 模型

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

基於邏輯或常態分佈的序數模型

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

Poisson 模型

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

負二項式模型

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

廣義負二項式 (NB-P) 模型

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

廣義泊松模型

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

泊松零膨脹模型

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

零膨脹廣義負二項模型

ZeroInflatedGeneralizedPoisson(endog, exog)

零膨脹廣義泊松模型

ConditionalLogit(endog, exog[, missing])

將條件羅吉斯迴歸模型擬合到分組數據。

ConditionalMNLogit(endog, exog[, missing])

將條件多項羅吉斯模型擬合到分組數據。

ConditionalPoisson(endog, exog[, missing])

將條件泊松迴歸模型擬合到分組數據。

多變量模型

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

因素分析

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

多變量變異數分析

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

主成分分析

其他模型

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

線性混合效應模型

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

生存函數的估計與推論。

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

Cox 比例風險迴歸模型

QuantReg(endog, exog, **kwargs)

分位數迴歸

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

穩健線性模型

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

Beta 迴歸。

圖形

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

Q-Q 和 P-P 機率圖

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

繪製 QQ 圖的參考線。

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

繪製 x 的分位數與分布的分位數/ppf 的 Q-Q 圖。

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

繪製兩個樣本分位數的 Q-Q 圖。

統計

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

數據的擴展描述性統計資訊

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

數據的擴展描述性統計資訊

工具

test([extra_args, exit])

執行測試套件

add_constant(data[, prepend, has_constant])

在陣列中新增一列 1。

load_pickle(fname)

載入先前儲存的物件

show_versions([show_dirs])

列出 statsmodels 和任何已安裝相依性的版本

webdoc([func, stable])

開啟瀏覽器並顯示線上文件

statsmodels.tsa.api

統計與檢定

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

計算自相關函數。

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

估計自共變數。

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

擴增迪基-福勒單根檢定。

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

時間序列獨立性的 BDS 檢定統計量

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

交叉相關函數。

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

計算兩個序列之間的交叉共變異數。

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

檢定單變量方程式是否無共整合。

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

Kwiatkowski-Phillips-Schmidt-Shin 定態性檢定。

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

偏自相關估計。

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

通過 OLS 計算偏自相關。

pacf_yw(x[, nlags, method])

使用非遞迴 yule_walker 估計的偏自相關。

q_stat(x, nobs)

計算 Ljung-Box Q 統計量。

range_unit_root_test(x[, store])

定態性的範圍單位根檢定。

zivot_andrews

Zivot-Andrews 結構性斷裂單位根檢定。

單變量時間序列分析

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

自迴歸 AR-X(p) 模型

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

自迴歸分佈式滯後 (ARDL) 模型

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

自迴歸整合移動平均 (ARIMA) 模型及其擴展

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

帶有外生迴歸因子的季節性自迴歸整合移動平均模型

ardl_select_order(endog, maxlag, exog, maxorder)

ARDL 階數選擇

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

計算多個 ARMA 模型的資訊準則。

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

從 ARMA 模擬資料。

ArmaProcess([ar, ma, nobs])

指定滯後多項式的 ARMA 過程的理論特性。

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

無約束誤差相關模型 (UECM)

指數平滑

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

Holt Winter 的指數平滑法

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

Holt 的指數平滑法

SimpleExpSmoothing(endog[, ...])

簡單指數平滑法

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

線性指數平滑模型

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

ETS 模型。

多變量時間序列模型

DynamicFactor(endog, k_factors, factor_order)

動態因子模型

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

使用 EM 演算法的動態因子模型;每月/每季資料的選項。

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

擬合 VAR(p) 過程並進行滯後階數選擇

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

帶有外生迴歸因子的向量自迴歸移動平均模型

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

擬合 VAR,然後估計 A 和 B 的結構性成分,定義為

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

表示向量誤差校正模型 (VECM) 的類別。

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

單變量未觀察成分時間序列模型

濾波器和分解

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

使用移動平均進行季節分解。

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

使用 LOESS 進行季節趨勢分解。

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

使用 LOESS 進行多重季節性的季節趨勢分解。

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

使用 Baxter-King 帶通濾波器對時間序列進行濾波。

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

Christiano Fitzgerald 非對稱隨機遊走濾波器。

hpfilter(x[, lamb])

Hodrick-Prescott 濾波器。

馬可夫體制轉換模型

MarkovAutoregression(endog, k_regimes, order)

馬可夫轉換迴歸模型

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

一階 k 體制馬可夫轉換迴歸模型

預測

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

使用 STL 移除季節性的基於模型的預測

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

Assimakopoulos 和 Nikolopoulos (2000) 的 Theta 預測模型

時間序列工具

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

返回一個包含滯後的陣列。

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

向陣列添加趨勢和/或常數。

detrend(x[, order, axis])

沿軸 0 或 1 對指定階數的趨勢進行去趨勢處理。

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

建立滯後值的二維陣列。

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

為二維陣列產生滯後矩陣,欄按變數排列。

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

確定性項的容器類別。

X12/X13 介面

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

對每月或每季資料執行 x13-arima 分析。

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

使用 x12/x13 ARIMA 執行自動季節性 ARIMA 階數識別。

statsmodels.formula.api

模型

小寫名稱是對應模型類別的 from_formula 方法的別名。公式 API 中公開的方法的函式描述是通用的。有關詳細資訊,請參閱父模型的文件。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立比例風險迴歸模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

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

從公式和資料框架建立模型。

conditional_poisson(公式, 資料[, 子集, ...])

從公式和資料框架建立模型。


上次更新:2024年10月03日