Statsmodels MANOVA:IndexError:索引1超出了大小为1的轴0的范围 [英] Statsmodels MANOVA : IndexError: index 1 is out of bounds for axis 0 with size 1
本文介绍了Statsmodels MANOVA:IndexError:索引1超出了大小为1的轴0的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我花了数小时试图使statsmodels不能成功执行MANOVA. 这是代码:
I have spent hours trying to make statsmodels do my MANOVA without success. Here is the code:
from statsmodels.multivariate.manova import MANOVA
df = data
feats_list = ['col1', 'col2', 'col3' ... 'col4']
var_list = ['col5', 'col6']
endog, exog = np.asarray(df[feats_list]), np.asarray(df[var_list])
manov = MANOVA(endog, exog)
manov.mv_test()
提供:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-16-c3fc1d1f16f6> in <module>()
1 manov = MANOVA(endog, exog)
----> 2 manov.mv_test()
~\Anaconda3\lib\site-packages\statsmodels\multivariate\manova.py in mv_test(self, hypotheses)
68 name = 'x%d' % (i)
69 L = np.zeros([1, self.exog.shape[1]])
---> 70 L[i] = 1
71 hypotheses.append([name, L, None])
72
IndexError: index 1 is out of bounds for axis 0 with size
1
我也尝试自己提出假设,并且总是收到SingularMatrixError,所以我想我没有正确使用该类.
I tried also to put the hypotheses by myself and I always get a SingularMatrixError so I suppose that I am not using the class correctly.
预先感谢您的帮助.
推荐答案
基于问题4903 在上述评论中引用了约瑟夫(Josef),以下方法将起作用
Based on issue 4903 referenced by Josef in the comments above, the following would work
from statsmodels.multivariate.manova import MANOVA
feats_list = ['col1', 'col2', 'col3', 'col4']
var_list = ['col5', 'col6']
df = pd.DataFrame(
np.random.random_sample(size=(100,6)),
columns=feats_list + var_list
)
endog, exog = np.asarray(df[feats_list]), np.asarray(df[var_list])
mod = MANOVA.from_formula('col1 + col2 + col3 + col4 ~ col5 + col6', data=df)
r = mod.mv_test()
print(r)
Multivariate linear model
============================================================
------------------------------------------------------------
Intercept Value Num DF Den DF F Value Pr > F
------------------------------------------------------------
Wilks' lambda 0.3420 4.0000 94.0000 45.2047 0.0000
Pillai's trace 0.6580 4.0000 94.0000 45.2047 0.0000
Hotelling-Lawley trace 1.9236 4.0000 94.0000 45.2047 0.0000
Roy's greatest root 1.9236 4.0000 94.0000 45.2047 0.0000
------------------------------------------------------------
------------------------------------------------------------
col5 Value Num DF Den DF F Value Pr > F
------------------------------------------------------------
Wilks' lambda 0.9297 4.0000 94.0000 1.7775 0.1399
Pillai's trace 0.0703 4.0000 94.0000 1.7775 0.1399
Hotelling-Lawley trace 0.0756 4.0000 94.0000 1.7775 0.1399
Roy's greatest root 0.0756 4.0000 94.0000 1.7775 0.1399
------------------------------------------------------------
------------------------------------------------------------
col6 Value Num DF Den DF F Value Pr > F
------------------------------------------------------------
Wilks' lambda 0.9891 4.0000 94.0000 0.2590 0.9035
Pillai's trace 0.0109 4.0000 94.0000 0.2590 0.9035
Hotelling-Lawley trace 0.0110 4.0000 94.0000 0.2590 0.9035
Roy's greatest root 0.0110 4.0000 94.0000 0.2590 0.9035
============================================================
这篇关于Statsmodels MANOVA:IndexError:索引1超出了大小为1的轴0的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文