statannot
statannot copied to clipboard
ValueError: The samples x and y must have the same length. Wilcoxon Test
I find a ValueError when using the Wilcoxon Test like saying that the samples don't have the equal length.
add_stat_annotation(ax, data=df_plot, x='Features', y='Values', hue='Condition', box_pairs=[(('Valence', 'Pre'), ('Valence', 'Post')),
(('Arousal', 'Pre'), ('Arousal', 'Post'))], test='Wilcoxon', loc='inside', verbose=0)
Out: raise ValueError('The samples x and y must have the same length.') ValueError: The samples x and y must have the same length.
However, when I check I can see that they should have the same equal length, actually I can do the comparisons using the wilcoxon test by myself:
x = df_plot.loc[(df_plot['Features']=='Arousal') & (df_plot['Condition'] == 'Pre'), 'Values']
y = df_plot.loc[(df_plot['Features']=='Arousal') & (df_plot['Condition'] == 'Post'), 'Values']
wilcoxon(x,y, nan_policy='omit')
Out: WilcoxonResult(statistic=107.0, pvalue=0.1353498838175801)
By the way, the wilcoxon test also work perfectly for the (('Valence', 'Pre'), ('Valence', 'Post')) comparison. Each with the same number of samples.
The code also works perfectly if the test is "Mann-Whitney"
Thank you very much in advance!
Ángel