python - 统计模型多元方差分析 : IndexError: index 1 is out of bounds for axis 0 with size 1

标签 python statsmodels manova

我花了几个小时试图让 statsmodels 进行多元方差分析,但没有成功。 这是代码:

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 所以我想我没有正确使用该类。

预先感谢您的帮助。

最佳答案

基于issue 4903约瑟夫在上面的评论中提到,以下内容可行

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
============================================================

关于python - 统计模型多元方差分析 : IndexError: index 1 is out of bounds for axis 0 with size 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51840604/

相关文章:

python - 高效合并大量pyspark DataFrame

python - 使用 Python winreg 更改注册表项未生效,但不会抛出错误

Python 与 MATLAB : ARIMA Model with Known Parameter Values

r - 基于 R 中 beta分散() 多元分散体标记 PCoA 的质心

python - 错误 : 'conda' can only be installed into the root environment

python - 将估计器重置为先前的值 scikit learn

python - 导入错误 : No module named statsmodels. 接口(interface)

python - 使用 python 中 statsmodels 的 ExponentialSmoothing 通过三重指数平滑进行预测

r - 通过汽车包获得的 MANOVA 对象的 xtable

python - 如何从 statsmodels 多元方差分析中获取 pvalue?