votes up 1

alternative should be 'less', 'greater' or 'two-sided'

Package:
scipy
github stars 8546
Exception Class:
ValueError

Raise code

lternative == "greater":
        pass
    elif alternative == "less":
        p = 1 - p
    elif alternative == "two-sided":
        p = 2 * np.min([p, 1-p])
    else:
        raise ValueError(
            "alternative should be 'less', 'greater' or 'two-sided'")

    return BrunnerMunzelResult(wbfn, p)
ūüė≤ Agile task management is now easier than calling a taxi. #Tracklify

Ways to fix

votes up 2 votes down

alternative should either of the following values.

['less', 'greater' 'two-sided']

Code to reproduce the exception:

import numpy as np
import scipy.stats.mstats as mstats
X = np.ma.masked_invalid([1, 2, 1, 1, 1, np.nan, 1, 1, 1, 1, 1, 2, 4, 1, 1, np.nan])
Y = np.ma.masked_invalid([3, 3, 4, 3, np.nan, 1, 2, 3, 1, 1, 5, 4])
significant = 14
u1, p1 = mstats.brunnermunzel(X,Y, alternative='les')

The error:

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-9-802a0d43529c> in <module>()  4 Y = np.ma.masked_invalid([3, 3, 4, 3, np.nan, 1, 2, 3, 1, 1, 5, 4])  5 significant = 14 ----> 6 u1, p1 = mstats.brunnermunzel(X,Y, alternative='les') 
/usr/local/lib/python3.7/dist-packages/scipy/stats/mstats_basic.py in brunnermunzel(x, y, alternative, distribution)  2973 else:  2974 raise ValueError( -> 2975 "alternative should be 'less', 'greater' or 'two-sided'")  2976   2977 return BrunnerMunzelResult(wbfn, p) 
ValueError: alternative should be 'less', 'greater' or 'two-sided'

The working (fixed) version of the code:

import numpy as np
import scipy.stats.mstats as mstats
X = np.ma.masked_invalid([1, 2, 1, 1, 1, np.nan, 1, 1, 1, 1, 1, 2, 4, 1, 1, np.nan])
Y = np.ma.masked_invalid([3, 3, 4, 3, np.nan, 1, 2, 3, 1, 1, 5, 4])
significant = 14
u1, p1 = mstats.brunnermunzel(X,Y, alternative='less')
Nov 24, 2021 kellemnegasi answer
kellemnegasi 18.3k

Add a possible fix

Please authorize to post fix