Skip to content

Order of pair not preserved for one-sided MWU test #180

Description

@tuanpham96

I'm trying to plot the test of the one-sided MWU tests but it seems the order defined in pairs is not preserved.

I used one of the demo examples below to illustrate this:

First, two-sided MWU is as expected:

PAIRS = [(("Sat", tip_bucket_list[2]), ("Fri", tip_bucket_list[0]))]
TEST  = 'Mann-Whitney'
Details

Full code

df = sns.load_dataset("tips")
df['tip_bucket'] = pd.cut(df['tip'], 3)

tip_bucket_list = df['tip_bucket'].unique()

PAIRS = [(("Sat", tip_bucket_list[2]), ("Fri", tip_bucket_list[0]))]
TEST  = 'Mann-Whitney'

x = "day"
y = "total_bill"
hue = "tip_bucket"
data = df
ax = sns.boxplot(data=df, x=x, y=y, hue=hue, fliersize=0)

(annot
 .reset_configuration()
 .new_plot(
     ax, PAIRS, 
     data=df, x=x, y=y, hue=hue
 )
 .configure(test=TEST)
 .apply_test()
 .annotate())

plt.legend(loc='upper left', bbox_to_anchor=(1.03, 1))

gives:

Fri_(0.991, 4.0] vs. Sat_(7.0, 10.0]: Mann-Whitney-Wilcoxon test two-sided, P_val:8.114e-03 U_stat=0.000e+00
Image

Now, testing for Sat > Fri

PAIRS = [(("Sat", tip_bucket_list[2]), ("Fri", tip_bucket_list[0]))]
TEST  = 'Mann-Whitney-gt'

gives:

Fri_(0.991, 4.0] vs. Sat_(7.0, 10.0]: Mann-Whitney-Wilcoxon test greater, P_val:9.970e-01 U_stat=0.000e+00
Image

I assumed that specifying the order in PAIRS would perform test against the alternative H1: Sat > Fri but it seems that the order was resorted.

Only when I changed the test that it would turn to significant

PAIRS = [(("Sat", tip_bucket_list[2]), ("Fri", tip_bucket_list[0]))]
TEST  = 'Mann-Whitney-ls'  

gives

Fri_(0.991, 4.0] vs. Sat_(7.0, 10.0]: Mann-Whitney-Wilcoxon test smaller, P_val:4.057e-03 U_stat=0.000e+00
Image

Is this expected behavior? And is there a way to use the specified order in PAIRS for testing? This would matter for one-sided test only.

Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions