Skip to content

pairwise_tukeyhsd output table and meandiff confusing convention #8458

Open

Description

@seralouk

The meandiff column of the result's table reports the difference of means for group 2 vs group 1. However, the table construction suggests otherwise.

Why is that?

Let's consider the following code:

import numpy as np

np.random.seed(0)
x = np.random.choice(['A','B','C'], 50)
y = np.random.rand(50)

print(pairwise_tukeyhsd(y,x))


Multiple Comparison of Means - Tukey HSD, FWER=0.05
===================================================
group1 group2 meandiff p-adj   lower  upper  reject
---------------------------------------------------
     A      B   0.1506 0.2347   -0.07 0.3712  False
     A      C   0.1105 0.5064 -0.1278 0.3487  False
     B      C  -0.0401    0.9 -0.2865 0.2063  False
---------------------------------------------------

by looking at the above table, one would say that the difference of groupA and group2 means is 0.15. However, this is the difference of group2 - group1.

y[x=='A'].mean() -  y[x=='B'].mean()
-0.1505750775332967

Activity

  1. josef-pkt commented on Oct 21, 2022

    @josef-pkt
    Member

    I'm not sure what to do here.

    I was using mostly triu_indices (upper triangular) and comparison using groups 1 (the diagonal group) as reference looks nicer for direct comparisons.
    But it's less obvious, the new standard in two-sample is always diff = group1 - group2

    Also, based on a quick look at the code, both allpairstest and kruskal methods of MultiComparison use group1 - group2 as diff

    Changes for this will not be backwards compatible, but the plan is to get multicomp out of the sandbox for 0.15
    with design review and enhancements which might not be backwards compatible.

  2. added this to the 0.15 milestone on Oct 21, 2022
  3. josef-pkt commented on Oct 21, 2022

    @josef-pkt
    Member

    one quick possibility would be to change column name "meandiff" to "meandiff (g2-g1)"

  4. josef-pkt commented on Oct 21, 2022

    @josef-pkt
    Member

    another consistency check

    base LikelihoodModelResults.t_test_pairwise uses contrast_allpairs from sandbox multicomp
    which also looks like it has group1 - group2 diff

  5. josef-pkt commented on Oct 21, 2022

    @josef-pkt
    Member

    I guess what would be best would be tril_indices but sorted in Fortran order for display, or flipping group1 and group2 indices of triu_indices.

  6. KforKuma commented on Nov 12, 2025

    @KforKuma

    I encounter this problem today too. You are right! This really boggled me for a long while because I'm comparing tukey with another method.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions