命名约定¶
文件和目录名称¶
我们的目录树简化后看起来像这样:
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 中。所有内容都有用于 测试 的目录。
内生变量 & 外生变量¶
我们对统计模型的定义是一个既定义了内生数据和外生数据,又定义了统计关系的对象。在内生和外生这两个术语中,通常可以用左侧(LHS)和右侧(RHS)、因变量和自变量、被回归量和回归量、结果和设计、响应变量和解释变量来替代。使用这些术语通常是领域特定的;然而,我们几乎只使用内生和外生,因为statsmodels的主要开发者有计量经济学的背景,这感觉最自然。这意味着所有的模型都是定义了内生和外生的对象,尽管在某些情况下,为了方便起见,外生是None(例如,在自回归过程中)。每个对象还定义了一个拟合(或类似)方法,该方法返回特定于模型的结果对象。此外,还有一些函数,例如用于统计测试或便利函数。
另请参阅内生变量, 外生变量, 这是什么?中的相关解释。
变量名¶
我们所有的模型都假设数据是按列排列的变量。因此,内部数据都是二维数组。按照惯例,我们将在表示沿轴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`)
Last update:
Oct 16, 2024