Matplotlib ValueError:试图找出 p < 0.05 and >= 0.01

问题描述 投票:0回答:1

我试图从 Tukey 测试或

model.tukeyhsd()
中获取摘要的输出。根据从该摘要中获得的表格,我首先想要获取 p 值大于或等于 0.05(原假设)的所有组(或这些组的索引)。我可以通过两种方式做到这一点:

  1. 如果原假设被拒绝或批准(< 0.05 and >= 0.05),我可以通过过滤掉组合来划分分析组

    model.tukeyhsd().reject==True
    (并且拒绝==False)。

  2. 另一种方法是获取高于(或低于)0.05 的 p 值指数。 这是执行此操作的代码:

print(np.where(result.pvalues >= 0.05)[0])

但是,我还希望能够找到其他组:对于 p < 0.01, and for p < 0.001. For this purpose I had to find out the pvalues between 0.05 and 0.01; lower that 0.05 but higher than 0.01.

所以,我尝试了这段代码:

print(np.where(result.pvalues < 0.05 and result.pvalues >= 0.01)[0])

但是,我收到一条错误消息:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

此消息的含义是什么,为什么我首先会收到它?

据我所知,a.any() 和 a.all() 会确认该组中的任何(分别是所有)元素是否符合条件。但我不希望这样,我想获取这些元素的数组,而不是 True 或 False。

是否有可能让代码做我真正想要的事情?

python matplotlib valueerror tukey
1个回答
0
投票

对于向量,您需要使用

numpy.logical_and
。这应该有效:

print(np.where(np.logical_and(result.pvalues < 0.05, result.pvalues >= 0.01))[0])
© www.soinside.com 2019 - 2024. All rights reserved.