我正在使用 statsmodel 进行 OLS 回归。当我对标准错误进行聚类时,出现了一条警告消息,表明存在多重共线性问题。但是,如果我只是拟合没有聚集错误的模型,则不会出现此类警告。
mod = smf.ols(formula = var ~ treatment_r1 + block + has_multiple_treat', data = df)
mod_res = mod.fit(cov_type='cluster', cov_kwds={'groups': df['block']}, use_t=True)
ValueWarning: covariance of constraints does not have full rank. The number of constraints is 3, but rank is 1
'rank is %d' % (J, J_), ValueWarning)
Run Code Online (Sandbox Code Playgroud)
我在这篇文章《Capturing high multi-collinearity in statsmodels》之后检查了共线性,没有发现任何问题。
corr = np.corrcoef(df_new[["var", "has_multiple_treat", "treatment_r1", "block1"]], rowvar=0)
w, v = np.linalg.eig(corr)
w
np.linalg.det(corr)
Run Code Online (Sandbox Code Playgroud)
var可以是0或1变量或者连续变量;Treatment_r1、has_multiple_treat是 0 …