假设我在statsmodels中安装了一个模型
mod = smf.ols('dependent ~ first_category + second_category + other', data=df).fit()
当我做mod.summary()
时,我可能会看到以下内容:
Warnings:
[1] The condition number is large, 1.59e+05. This might indicate that there are
strong multicollinearity or other numerical problems.
有时警告是不同的(例如,基于设计矩阵的特征值)。如何捕获变量中的高多重共线性条件?此警告是否存储在模型对象中的某个位置?
另外,在哪里可以找到summary()
中字段的描述?
可以通过检查相关矩阵的特征值来检测高多重共线性。很低的特征值表明数据是共线的,对应的特征向量显示哪些变量是共线的。
如果数据中不存在共线性,则期望特征值都不接近零:
但是,如果说
x[4] - 2 * x[0] - 3 * x[2] = 0
,那么其中一个特征值(这里是第一个)接近于零。对应的特征向量为:
忽略几乎为零的系数,上面基本上说
x[0]
,x[2]
和x[4]
是共线的(如预期)。如果将xs
值标准化并乘以该特征向量,结果将在0附近徘徊,且方差很小:注意
ys.var()
基本上是接近于零的本征值。因此,为了获得高的多线性度,可以考虑相关矩阵的特征值。
基于R的similar question,还有一些其他选项可以帮助人们。我在寻找一个能捕捉共线性的数字,选项包括相关矩阵的行列式和条件数。
根据其中一个R答案,相关矩阵的行列式将“从0(完全共线)到1(无共线)”。我发现有界范围很有用。
行列式的翻译示例:
同样地,协方差矩阵的条件数将以完全线性相关逼近无穷大。
相关问题 更多 >
编程相关推荐