Issue
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:
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).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:
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])
Answered By - bona_rivers
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.