Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Matplotlib ValueError: trying to find out indices of the combinations, that have p < 0.05 and >= 0.01

I was trying to get the output of the summary from the Tukey test or the model.tukeyhsd(). Based on the obtained table from this summary, I wanted first to get all groups (or the indices of these groups) where the p-value is greater or equal to 0.05 (The null hypothesis). I was able to do this by two means:

  1. I could divide the analyzed groups by filtering out the combinations if the null hypothesis is rejected or approved (< 0.05 and >= 0.05) model.tukeyhsd().reject==True (and reject==False).

  2. The other way to do this is to obtain the indices of the pvalues, higher (or lower) than 0.05.
    This is the code to do it:

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

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

However, I wanted additionally to be able to find the other groups: for 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.

So, I tried this code:

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

However, I received an error message:

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

What is the meaning of this message, and why am I receiving it in the first place?

As far as I know, a.any() and a.all() give confirmation if any (respectively all) elements of this group comply to the condition. But I don’t want that, I want to get array of these elements, not True or False.

Is it even possible to make the code do what I actually want?

>Solution :

For vectors you need to use numpy.logical_and. This should work:

print(np.where(np.logical_and(result.pvalues < 0.05, result.pvalues >= 0.01))[0])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading