我正尝试使用以下帖子中的说明对每个组进行多元回归:How to apply OLS from statsmodels to groupby。我的代码段如下:
for coins in df_raw.symbol.unique():
tempdf = df_raw[df_raw.symbol == coins]
y = (df_raw['Lagged return']).astype(float)
x1 = (df_raw['Excess daily return']).astype(float)
x2 = (df_raw['Excess weekly return']).astype(float)
x3 = (df_raw['Excess monthly return']).astype(float)
x4 = (df_raw['Trading vol / mkt cap']).astype(float)
x5 = (df_raw['Std dev']).astype(float)
x6 = (df_raw['Residual risk']).astype(float)
result = smf.ols(formula='y ~ x1 + x2 + x3 + x4 + x5 + x6', data=df_raw).fit()
print(result.params)
print(result.summary())
但是,当我运行回归时,我对数据帧中的每个组重复获得完全相同的回归结果(尽管基础数据不同)。
Intercept 0.010033
x1 -0.000214
x2 -0.000014
x3 -0.000094
x4 -0.001902
x5 -0.000009
x6 -0.000006
有人能告诉我我要去哪里哪里吗?预先感谢!