命名慣例¶
檔案和目錄名稱¶
我們的目錄樹精簡後看起來像這樣
statsmodels/
__init__.py
api.py
discrete/
__init__.py
discrete_model.py
tests/
results/
tsa/
__init__.py
api.py
tsatools.py
stattools.py
arima_process.py
vector_ar/
__init__.py
var_model.py
tests/
results/
tests/
results/
stats/
__init__.py
api.py
stattools.py
tests/
tools/
__init__.py
tools.py
decorators.py
tests/
子模組按主題排列,discrete 用於離散選擇模型,或 tsa 用於時間序列分析。 可以導入大量程式碼的子模組包含一個空的 __init__.py,除了用於執行子模組測試的一些測試程式碼。 要導入的命名空間位於 api.py 中。 這樣,我們可以選擇性地導入,而不必導入我們不需要的大量程式碼。 輔助函數通常放在名為 tools.py 的檔案中,而統計函數(例如統計檢定)則放在 stattools.py 中。 每個東西都有一個用於 測試 的目錄。
endog & exog¶
我們對統計模型的定義是一個既定義了內生數據又定義了外生數據以及統計關係的對象。 在內生和外生數據的位置,通常可以替換為左側(LHS)和右側(RHS)、應變數和自變數、被解釋變數和解釋變數、結果和設計、反應變數和解釋變數等術語。 用法通常是特定領域的;但是,我們幾乎完全選擇使用 endog 和 exog,因為 statsmodels 的主要開發人員具有計量經濟學的背景,這感覺最自然。 這表示所有模型都是定義了 endog 和 exog 的物件,儘管在某些情況下,為了方便起見,exog 為 None(例如,對於自迴歸過程)。 每個物件也定義了一個 fit(或類似的)方法,該方法會傳回特定於模型的結果物件。 此外,還有一些函數,例如用於統計檢定或便利函數。
另請參閱 endog、exog,那是什麼? 中的相關說明。
變數名稱¶
我們所有的模型都假設資料以變數在欄中的方式排列。 因此,內部資料都是 2d 陣列。 依照慣例,我們會在表示在軸 1(欄)上移動的變數名稱前面加上 k_,並在表示在軸 0(列)上移動的變數名稱前面加上 n_。 底線的主要例外是 nobs 應表示觀察次數。 例如,在時間序列 ARMA 模型中,我們有
`k_ar` - The number of AR lags included in the RHS variables
`k_ma` - The number of MA lags included in the RHS variables
`k_trend` - The number of trend variables included in the RHS variables
`k_exog` - The number of exogenous variables included in the RHS variables excluding the trend terms
`n_totobs` - The total number of observations for the LHS variables including the pre-sample values
選項¶
我們在許多類別、方法和函數中使用相似的選項。 如果它們頻繁出現,則應遵循標準化的模式。
`missing` ['none', 'drop', 'raise'] define whether inputs are checked for
nans, and how they are treated
`alpha` (float in (0, 1)) significance level for hypothesis tests and
confidence intervals, e.g. `alpha=0.05`
模式
`return_xxx` : boolean to indicate optional or different returns
(not `ret_xxx`)