<jupyter_start><jupyter_text>comment:I guess errorbar would be just fine, but in here it is easier to plot box plot. It is the same thing I showed you before.  I did a Kruskal-Wallis 1-way ANOVA with Dunn's multiple comparison test, which is the same as I did in MatlabThe difference is only significant between hummed tones and Wang's complex vowels.<jupyter_code>diff[:4,:].shape
a,b,c,d,e=kw_dunn(diff,to_compare=[(0,1),(0,2),(0,3),(0,4),(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)])
print([(0,1),(0,2),(0,3),(0,4),(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)],d)
print(a,b,c,d,e)<jupyter_output>10.5774100055 0.0317472289336 [ 0.73030578  0.92105729  1.40611113  3.07382433  0.19075151  0.67580535
  2.34351855  0.48505384  2.15276704  1.6677132 ] [ 1.          1.          1.          0.02113338  1.          1.
  0.19102812  1.          0.31336992  0.95372673] [False False False  True False False False False False False]<jupyter_text>I also did a 1-way ANOVA, which is not significant<jupyter_code>stats.f_oneway(diff[0,:],diff[1,:],diff[2,:],diff[3,:],diff[4,:])
import statsmodels.api as sm
from statsmodels.formula.api import ols
df['group'] = df.Group.map({1:'hum',2:'simple vowel',3:'non word',4:'real word',5:'comple vowel'})
mod = ols('LI ~ group',
                data=df).fit()
                
aov_table = sm.stats.anova_lm(mod, typ=2)
aov_table
from statsmodels.stats.multicomp import pairwise_tukeyhsd
from statsmodels.stats.multicomp import MultiComparison<jupyter_output><empty_output><jupyter_text>So the multiple comparison after the ANOVA is not significant<jupyter_code>mc = MultiComparison(df['LI'], df['Group'])
result = mc.tukeyhsd()
 
print(result)
print(mc.groupsunique)<jupyter_output>Multiple Comparison of Means - Tukey HSD,FWER=0.05
============================================
group1 group2 meandiff  lower  upper  reject
--------------------------------------------
  1      2    -0.0206  -0.1817 0.1405 False 
  1      3    -0.0708  -0.2319 0.0903 False 
  1      4    -0.1009   -0.262 0.0602 False 
  1      5    -0.1569   -0.318 0.0042 False 
  2      3    -0.0502  -0.2113 0.1109 False 
  2      4    -0.0803  -0.2414 0.0808 False 
  2      5    -0.1363  -0.2974 0.0248 False 
  3      4    -0.0301  -0.1912 0.131  False 
  3      5    -0.0861  -0.2472 0.075  False 
  4      5     -0.056  -0.2171 0.1051 False 
--------------------------------------------
[1 2 3 4 5]<jupyter_text>I try what Xing said about two way ANOVA based on ears (left vs right) and tasks (4 in experiment 2 and Wang paper)<jupyter_code>ears = loadmat('ears.mat')
grand_leftcol = ears['grand_leftCol']
grand_rightcol = ears['grand_rightCol']
from statsmodels.graphics.factorplots import interaction_plot
P = ['Hummed Tones ','Simple Lexical Tones /i/','Pseudo words /gi/','Real words /di/\n',
                   'Wang et al., 2001,\n complex vowel /fan/']
df = pd.DataFrame({'data':np.concatenate((grand_leftcol.flatten(),grand_rightcol.flatten())),
                   'group':np.concatenate((np.repeat(np.arange(0,5),20),np.repeat(np.arange(0,5),20))),
                  'ear':np.concatenate((np.zeros(len(grand_leftcol.flatten())),np.ones(len(grand_leftcol.flatten()))))})
df.ear = df.ear.map({0:'left',1:'right'})

fig,ax = plt.subplots(figsize=(16,8))
fig = interaction_plot(df.group, df.ear, df.data,
             colors=['black','black'], markers=['D','^'], ms=10,ax=ax,
                     xlabel='Tasks',ylabel='Correct Rate')
ax.errorbar([1,2,3,4,5],df[df.ear=='left'].groupby('group').mean().values,
            df[df.ear=='left'].groupby('group').std().values/np.sqrt(20),color='black')
ax.errorbar([1,2,3,4,5],df[df.ear=='right'].groupby('group').mean().values,
            df[df.ear=='right'].groupby('group').std().values/np.sqrt(20),color='black')
ax.set(title='Experiment 2 and Wang et al. (2001)\n N = 20,20,20,20,20',xticks=[1,2,3,4,5],
      xticklabels=['Hummed Tones ','Simple Lexical Tones /i/','Pseudo words /gi/','Real words /di/\n',
                   'Wang et al., 2001,\n complex vowel /fan/'],
      )

ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
fig.savefig('2 way anova.png')<jupyter_output><empty_output><jupyter_text>Comment on figure: I feel this figure is telling the same story as the box plot but it is clearer that that is an interaction.  so I did a 2-way ANOVA, and it has a main effect on tasks and an interaction<jupyter_code>from statsmodels.formula.api import ols
from statsmodels.stats.anova import anova_lm
df.group = df.group.map({ii:name for ii,name in enumerate(P)})
formula = 'data ~ group + ear + group:ear'
model = ols(formula,df).fit()
aov_table = anova_lm(model, typ=2)
def eta_squared(aov):
    aov['eta_sq'] = 'NaN'
    aov['eta_sq'] = aov[:-1]['sum_sq']/sum(aov['sum_sq'])
    return aov
 
def omega_squared(aov):
    mse = aov['sum_sq'][-1]/aov['df'][-1]
    aov['omega_sq'] = 'NaN'
    aov['omega_sq'] = (aov[:-1]['sum_sq']-(aov[:-1]['df']*mse))/(sum(aov['sum_sq'])+mse)
    return aov
eta_squared(aov_table)
omega_squared(aov_table)
print(aov_table)
res = model.resid 
fig = sm.qqplot(res, line='s')
fig.savefig('residual.png')
import pyvttbl as pt
from collections import namedtuple
diff.shape
Sub = namedtuple('Sub',['Sub_id','diff','tasks'])
df = pt.DataFrame()
P = ['Hummed Tones ','Simple Lexical Tones /i/','Pseudo words /gi/','Real words /di/\n']#,
                   #'Wang et al., 2001,\n complex vowel /fan/']
df = pt.DataFrame({'Laterality_Index':diff[:4].flatten(),'Tasks':np.repeat(P,20),
 'Sub_id':np.vstack((np.arange(1,21),np.arange(1,21),np.arange(1,21),np.arange(1,21))).flatten()})
#df['condition'] = df['Group'].apply(map({ii:name for ii,name in enumerate(P)}))
aov=df.anova('Laterality_Index',sub='Sub_id',wfactors=['Tasks'])<jupyter_output>c:\Anaconda2\lib\site-packages\pyvttbl\stats\_anova.py:1240: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  return list(array(list(zeros((p-len(b))))+b)+1.)<jupyter_text>Sort of repeated measure ANOVA on laterality Index<jupyter_code>print(aov)<jupyter_output>Laterality_Index ~ Tasks

TESTS OF WITHIN SUBJECTS EFFECTS

Measure: Laterality_Index
   Source                           Type III    eps      df      MS       F     Sig.    et2_G   Obs.    SE     95% CI   lambda   Obs.  
                                       SS                                                                                        Power 
======================================================================================================================================
Tasks          Sphericity Assumed      0.127       -        3   0.042   1.229   0.308   0.043     20   0.042    0.083    1.293   0.131 
               Greenhouse-Geisser      0.127   0.817    2.451   0.052   1.229   0.307   0.043     20   0.042    0.083    1.293   0.122 
               Huynh-Feldt             0.127   0.817    2.451   0.052   1.229   0.307   0.043     20   0.042    0.083    1.293   0.122 
               Box                     0.127   0.333        1   0.127   1.229   0.281   0.043     2[...]<jupyter_text>sort of repeated measure ANOVA on ear effects<jupyter_code>k = np.vstack((np.arange(1,21),np.arange(1,21),np.arange(1,21),np.arange(1,21))).flatten()
df = pt.DataFrame({'data':np.concatenate((grand_leftcol[:4,:].flatten(),grand_rightcol[:4,:].flatten())),
                   'group':np.concatenate((np.repeat(P,20),np.repeat(P,20))),
                  'ear':np.concatenate((np.repeat(['Left'],len(grand_leftcol[:4,:].flatten())),
                                        np.repeat(['Right'],len(grand_leftcol[:4,:].flatten())))),
'Sub_id':np.concatenate((k, k))})
df.box_plot('data',factors=['ear','group'])
aov = df.anova('data',sub='Sub_id',wfactors=['ear','group'])
print(aov)<jupyter_output>data ~ ear * group

TESTS OF WITHIN SUBJECTS EFFECTS

Measure: data
   Source                           Type III     eps      df        MS         F     Sig.      et2_G     Obs.      SE        95% CI     lambda   Obs.  
                                       SS                                                                                                        Power 
======================================================================================================================================================
ear            Sphericity Assumed       0.142       -        1       0.142   5.556   0.029       0.097     80       0.019       0.037   23.394   0.996 
               Greenhouse-Geisser       0.142       1        1       0.142   5.556   0.029       0.097     80       0.019       0.037   23.394   0.996 
               Huynh-Feldt              0.142       1        1       0.142   5.556   0.029       0.097     80       0.019       0.037   23.394   0.996 
               Box   [...]
{'fraction_non_alphanumeric': 0.19603201442903845, 'fraction_numerical': 0.08826513358133244, 'mean_word_length': 2.553063676411694, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '249631', 'license': 'MIT', 'n_tokens_mistral': 3556, 'n_tokens_neox': 3058, 'n_words': 643, 'path': 'data/result2/ANOVA LI.ipynb', 'repo_name': 'nmningmei/dichotic-listening-of-tones-is-influenced-by-the-content-of-speech', 'size': '8871'}