You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pairwise_tukeyhsd output table and meandiff confusing convention #8458
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.
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.
Activity
josef-pkt commentedon Oct 21, 2022
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.
josef-pkt commentedon Oct 21, 2022
one quick possibility would be to change column name "meandiff" to "meandiff (g2-g1)"
josef-pkt commentedon Oct 21, 2022
another consistency check
base LikelihoodModelResults.t_test_pairwise uses contrast_allpairs from sandbox multicomp
which also looks like it has group1 - group2 diff
josef-pkt commentedon Oct 21, 2022
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.
KforKuma commentedon Nov 12, 2025
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.