<jupyter_start><jupyter_text>Load cleaned file<jupyter_code>all_model_fits_cleaned = pd.read_csv(base_dir +
                 '/Data/Cleaned/all_model_fits_cleaned.csv', index_col = 0)
all_model_fits_cleaned.head()<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code>sns.set_context('paper')
fig,ax = plt.subplots(1,1,figsize = [6,4])
bar_order = ['Games', 'Game Types', 'All Motives', 'Best Motives']
xticklabels = ['\n'.join(a.split(' ')) for a in bar_order]

sns.barplot(data = all_model_fits_cleaned, x = 'model_descr', y = 'BIC', ax = ax, alpha = .5,
            order = bar_order, errcolor = 'k', capsize = .1, errwidth = 1)
sns.stripplot(data = all_model_fits_cleaned, x = 'model_descr', y = 'BIC', ax = ax, alpha = .5,
            order = bar_order)
# FigureTools.add_sig_markers(ax,relationships=[[2,3,0],[1,2,0]], distScale=.5, ystart = 30)
ax.set(ylabel = 'BIC', xlabel = 'Features in model',
      xticklabels = xticklabels);
# plt.savefig('/Users/jeroen/Desktop/modelcomp.pdf',transparent=True, bbox_inches = 'tight')<jupyter_output><empty_output><jupyter_text>Model comparison per subject - counts<jupyter_code>def load_model_fits(date_string, features,
                    niter = 10, gaze = False, model_string = 'FeatureRL', fit_to = 'joint'):
    
    print(date_string, features)
    
    if model_string == "FeatureRL":
        model_fits = pd.read_csv(base_dir + 
             '/Data/Modeled/' +
             '%s_%s_%s_fitto-%s_gaze-%s_niter-%i.csv'%(
                 model_string,features,date_string, fit_to, gaze, niter),
               index_col = None, dtype={'sub_ID':str, 'comb':str, 'fit_to':str, 'sub_ind':int})
    elif model_string == "BayesianIO":
        model_fits = pd.read_csv(base_dir + 
             '/Data/Modeled/' +
             '%s_%s_fitto-%s_gaze-%s_niter-%i.csv'%(
                 model_string,date_string, fit_to, gaze, niter),
               index_col = 0, dtype={'subID':str, 'comb':str, 'fit_to':str, 'sub_ind':int})
        cost_type = model_fits['costType'].unique()
        if len(cost_type) > 1:
            raise ValueError('Multiple cost types detected - write code to deal with that')
        else:
            model_fits = model_fits.rename(columns = {'costVal':cost_type[0]})
    display(model_fits.head())
    print(model_fits.shape)
    return model_fits
model_fits = load_model_fits('2020-03-24','CoGrRiNa')
bestPerSubject = pd.DataFrame()
results_model_structure_requirement = model_fits.copy()
n_subs = len(results_model_structure_requirement['sub_ID'].unique())
for sub_ID in results_model_structure_requirement['sub_ID'].unique():
    sub_dat = results_model_structure_requirement.query('sub_ID == @sub_ID').copy()
    sub_dat = sub_dat.sort_values(by=['BIC','SSE'], ascending=True)
    bestPerSubject = bestPerSubject.append(sub_dat.iloc[0])
bestPerSubject = bestPerSubject.reset_index(drop=True)
bestModelCounts = pd.DataFrame(pd.value_counts(bestPerSubject.comb)).reset_index()
bestModelCounts.columns = ['comb','count']
bestModelCounts = bestModelCounts.sort_values(by='count', ascending=False)
bestPerSubject['nDim'] = [sum([char=='1' for 
                   char in bestPerSubject.comb.values[i]]) for i in np.arange(len(bestPerSubject))]
bestPerSubject['GatherS'] = bestPerSubject.feature_names.apply(lambda x: ('Risk' in x) | ('Nash' in x))
bestPerSubject['GatherT'] = bestPerSubject.feature_names.apply(lambda x: ('Greed' in x) | ('Nash' in x))
bestPerSubject['Complexity'] = bestPerSubject['GatherS'].astype(int) + bestPerSubject['GatherT'].astype(int)
bestModelnDimCounts = pd.DataFrame(pd.value_counts(bestPerSubject.nDim)).reset_index()
bestModelnDimCounts.columns = ['nDim','count']
bestModelComplexityCounts = pd.DataFrame(pd.value_counts(bestPerSubject.Complexity)).reset_index()
bestModelComplexityCounts.columns = ['Complexity','count']
bestModelComplexityCounts = bestModelComplexityCounts.sort_values(by='count', ascending=False)
display(bestModelComplexityCounts)
bestPerSubject.head()
label_list = ['Coop.','Greed','Risk','Nash']
bestModelCounts['comb_labels'] = bestModelCounts['comb'].apply(lambda x: 
                ',\n'.join(label_list[k] for k in [i.span()[0] for i in re.finditer('1',x)]))
bestModelCounts['pct'] = bestModelCounts['count']/n_subs*100
bestModelComplexityCounts['pct'] = bestModelComplexityCounts['count']/n_subs*100
bestModelnDimCounts['pct'] = bestModelnDimCounts['count']/n_subs*100
n_models_in_plot = 8
bestModelCounts_trunc = bestModelCounts.iloc[:n_models_in_plot,:]
bestModelCounts_trunc
bmc_other = pd.DataFrame(bestModelCounts.iloc[n_models_in_plot:,:].sum()
                        ).T[['count','comb_labels','pct']]
bmc_other.loc[0,'comb_labels'] = 'other'
bestModelCounts_aggTrunc = bestModelCounts.iloc[:n_models_in_plot,:].append(
    bmc_other, sort = False)
bestModelCounts_aggTrunc
bestModelnDimCounts
sns.set_context('talk')
fig, ax = plt.subplots(nrows = 1, ncols = 2, figsize = [14,6],
                       gridspec_kw = {'width_ratios':[2,1]});
sns.barplot(data = bestModelCounts_aggTrunc, x='comb_labels', y='pct',
            order = bestModelCounts_aggTrunc.comb_labels, ax = ax[0],
           palette = 'tab10')
ax[0].set(xlabel = 'Motives included in model', ylabel = 'Frequency (%)',
       title = 'Best model per subject');
ax[0].set_xticklabels(ax[0].get_xticklabels(),rotation=0)
sns.barplot(data = bestModelnDimCounts, x='nDim', y='pct', order = [1,2,3], ax = ax[1])
ax[1].set(xlabel = 'Number of motives considered', ylabel = 'Frequency (%)',
       title = 'Model complexity per subject');
plt.tight_layout()
sns.set_context('talk')
fig, ax = plt.subplots(nrows = 1, ncols = 2, figsize = [14,6], gridspec_kw = {'width_ratios':[2,1]});
sns.barplot(data = bestModelCounts_aggTrunc, x='comb_labels', y='pct',
            order = bestModelCounts_aggTrunc.comb_labels, ax = ax[0],
           palette = 'tab10')
ax[0].set(xlabel = 'Motives included in model', ylabel = 'Frequency (%)',
       title = 'Best model per subject');
ax[0].set_xticklabels(ax[0].get_xticklabels(),rotation=0)
sns.barplot(data = bestModelComplexityCounts, x='Complexity', y='pct', order = [0,1,2], ax = ax[1])
ax[1].set(xlabel = 'Number of information sources (S, T)\nconsidered', ylabel = 'Frequency (%)',
       title = 'Model complexity per subject');
plt.tight_layout()
bestPerSubject_features = bestPerSubject.copy()
label_list = ['Coop.','Greed','Risk','Nash']
bestPerSubject_features['comb_labels'] = bestPerSubject_features['comb'].apply(lambda x: 
                ',\n'.join(label_list[k] for k in [i.span()[0] for i in re.finditer('1',x)]))
for feature in label_list:
    bestPerSubject_features[feature] = bestPerSubject_features['comb_labels'].apply(lambda x: feature in x)
bestPerSubject_features.head()
featureCounts = pd.DataFrame(bestPerSubject_features[label_list].sum()).reset_index()
featureCounts.columns = ['Motive','Count']
featureCounts['pct'] = featureCounts['Count']/n_subs
featureCounts.sort_values(by='Count', ascending = False, inplace=True)
featureCounts
sns.set_context('talk')
fig, ax = plt.subplots(nrows = 1, ncols = 2, figsize = [14,6], gridspec_kw = {'width_ratios':[2,1]});
sns.barplot(data = bestModelCounts_aggTrunc, x='comb_labels', y='pct',
            order = bestModelCounts_aggTrunc.comb_labels, ax = ax[0],
           palette = 'tab10')
ax[0].set(xlabel = 'Motives included in model', ylabel = 'Frequency (%)',
       title = 'Best model per subject');
ax[0].set_xticklabels(ax[0].get_xticklabels(),rotation=0)
sns.barplot(data = featureCounts, x='Motive', y='pct', ax = ax[1])
ax[1].set(xlabel = 'Motive', ylabel = 'Frequency (%)',
       title = 'Popularity of considered motives');
ax[1].yaxis.set_major_formatter(mtick.PercentFormatter(xmax=1))
plt.tight_layout()
sns.set_context('poster')
fig, ax = plt.subplots(nrows = 1, ncols = 1, figsize = [5,2.5]);
sns.barplot(data = featureCounts, x='Motive', y='pct', ax = ax,
           palette = sns.color_palette('Greys',10)[6:2:-1])
ax.set(xlabel = 'Motive', ylabel = 'Percentage of\nparticipants',
       title = None, yticks = [0,.25,.5,.75]);
ax.yaxis.set_major_formatter(mtick.PercentFormatter(xmax=1))
sns.despine(top=True,right=True);<jupyter_output><empty_output><jupyter_text>Relationship between model features/complexity and performance<jupyter_code>blockDat = gameDat[['subID','Type_Total','Type','Variant','ConfidenceNum','ScoreNum']
                  ].groupby(['subID','Type_Total','Type','Variant'], as_index=False).mean()
blockDat = blockDat.rename(columns={'ConfidenceNum':'Confidence','ScoreNum':'Score'})
subIDs = blockDat['subID'].unique()
print(len(subIDs))
blockDat.head()
blockDat = blockDat.rename(columns={'subID':'sub_ID'})
blockDat = blockDat.merge(bestPerSubject[['sub_ID','Complexity','nDim','comb']],on='sub_ID')
blockDat.head()<jupyter_output><empty_output><jupyter_text>Merge data for overall performance<jupyter_code>totalDat = blockDat[['sub_ID','Confidence','Score']].groupby(['sub_ID']).mean().reset_index()
totalDat = totalDat.merge(bestPerSubject[['sub_ID','nDim','Complexity','comb']],on='sub_ID')
totalDat.head()<jupyter_output><empty_output><jupyter_text>Plot effect of n-dims:<jupyter_code>n_dims_list = [1,2,3]
panel_widths = [len(totalDat.query('nDim == @nDim')['comb'].unique()) for nDim in n_dims_list]
panel_widths.append(6)
fig, ax = plt.subplots(nrows = 1, ncols = len(n_dims_list)+1, figsize = [14,6], sharey=True,
                       gridspec_kw={'width_ratios':panel_widths});
nPast = 0
for ndi,nDim in enumerate(n_dims_list):
    nCombs = len(totalDat.query('nDim == @nDim')['comb'].unique())
    if nCombs > 1:
        means = totalDat.query('nDim == @nDim')[['comb','nDim','Score']].groupby(
            ['comb','nDim']).mean().sort_values(by='Score',ascending=False).reset_index()
        combOrder = list(means['comb'].values)
    else:
        combOrder = ['11100']
    sns.barplot(data = totalDat.query('nDim == @nDim'),
                y = 'Score', x='comb', ax=ax[ndi],
           alpha = .6, errwidth = 0, zorder = 0, order = combOrder,
           palette = sns.color_palette('tab20')[nPast:(nPast+nCombs)]);
    sns.stripplot(data = totalDat.query('nDim == @nDim'),
                  y = 'Score', x='comb', ax=ax[ndi],
           alpha = 1, zorder = 1, order = combOrder, size = 5, jitter = .2,
           palette = sns.color_palette('tab20')[nPast:(nPast+nCombs)]);
    sns.barplot(data = totalDat.query('nDim == @nDim'),
                y = 'Score', x='comb', ax=ax[ndi],
           alpha = 0, errwidth = 1, errcolor = 'k', capsize = .1, zorder = 2, order = combOrder,
           palette = sns.color_palette('tab20')[nPast:(nPast+nCombs)]);
    nPast = nPast + nCombs
    for tick in ax[ndi].get_xticklabels():
        tick.set_rotation(45)
ax[0].set(ylabel = 'Mean accuracy')
[ax[i].set(ylabel = '', xlabel = 'Features') for i in n_dims_list[::-1]]

sns.barplot(data = totalDat, x = 'nDim', y = 'Score', order = n_dims_list, ax = ax[len(n_dims_list)],
           alpha = .6, errwidth = 0, zorder = 0)
sns.stripplot(data = totalDat, x = 'nDim', y = 'Score', order = n_dims_list, ax = ax[len(n_dims_list)],
           alpha = 1, size = 5, jitter = .2, zorder = 1)
sns.barplot(data = totalDat, x = 'nDim', y = 'Score', order = n_dims_list, ax = ax[len(n_dims_list)],
           alpha = 0, errwidth = 1, errcolor = 'k', capsize = .2, zorder = 3)
[ax[i-1].set(title = '%i features'%((1+max(n_dims_list))-i)) for i in n_dims_list]
# ax[2].set(title = '1 feature')
ax[len(n_dims_list)].set(title = 'Aggregate', ylabel = '', xlabel = 'Number of features')

    
# Significant ranked trend?
spearman_results = scipy.stats.spearmanr(totalDat['nDim'],
                                         totalDat['Score'])
print(spearman_results)
print(scipy.stats.f_oneway(totalDat.query('nDim == 1')['Score'],
                     totalDat.query('nDim == 2')['Score'],
                    totalDat.query('nDim == 3')['Score']))

FigureTools.add_sig_markers(ax[len(n_dims_list)],relationships=[
    [0,len(n_dims_list)-1,spearman_results[1]]], caps = False, ystart = 1)
plt.tight_layout()<jupyter_output>SpearmanrResult(correlation=0.3498673320194501, pvalue=1.1405535790317253e-05)
F_onewayResult(statistic=10.519722233276298, pvalue=5.371532118317752e-05)<jupyter_text>Aggregate only<jupyter_code>sns.set_context('poster')
n_dims_list = [1,2,3]
barcolors = [sns.color_palette('Greys',5)[i] for i in [2,2]]
barcolors.append([0,0,0])
fig, ax = plt.subplots(nrows = 1, ncols = 1, figsize = [7,5]);
sns.barplot(data = totalDat, x = 'nDim', y = 'Score', order = n_dims_list, ax = ax,
           alpha = 1, errwidth = 0, zorder = 0,
            palette = barcolors)
sns.stripplot(data = totalDat, x = 'nDim', y = 'Score', order = n_dims_list, ax = ax,
           alpha = 1, size = 5, jitter = .1, zorder = 1,
              palette = [[1,1,1] for i in [2,2,2]], edgecolor = 'k', linewidth = 1)
sns.barplot(data = totalDat, x = 'nDim', y = 'Score', order = n_dims_list, ax = ax,
           alpha = 0, errwidth = 2, errcolor = 'k', capsize = .1, zorder = 3)


# Significant ranked trend?
spearman_results = scipy.stats.spearmanr(totalDat['nDim'],
                                         totalDat['Score'])
print(spearman_results)
print(scipy.stats.f_oneway(totalDat.query('nDim == 1')['Score'],
                     totalDat.query('nDim == 2')['Score'],
                    totalDat.query('nDim == 3')['Score']))
print('Group means +- sd:')
for ndim in [1,2,3]:
    m_sd = [fun(totalDat.query('nDim == %i'%ndim)['Score'].values) for fun in [np.mean,np.std]]
    print('%i dim: m = %.2f, sd %.2f'%(ndim, m_sd[0]*100, m_sd[1]*100))
ax.yaxis.set_major_formatter(mtick.PercentFormatter(xmax=1))

FigureTools.add_sig_markers(ax,relationships=[
    [0,len(n_dims_list)-1,spearman_results[1]]], caps = False, ystart = .95)

ax.set(xlabel = 'Number of motives considered', ylabel = 'Accuracy', title = None,
      ylim = [0.25,1])
sns.despine(top=True, right = True)

for i in [1,2,3]:
    ax.text(i-1,.35,'$n$=%i'%totalDat['nDim'].value_counts()[i],
           fontdict = {'horizontalalignment':'center','verticalalignment':'center',
                      'color':'white'})

plt.tight_layout()
def ttest_1samp(dat, popmean = .5, verbose = True):
    if verbose:
        print('SD: ',np.std(dat))
        print('Stats:')
    stats = scipy.stats.ttest_1samp(dat, popmean = popmean)
    if verbose:
        print(stats)
        print('Cohen d:')
    coh_d = (np.mean(dat) - popmean)/np.std(dat)
    if verbose:
        print(coh_d)
    return(stats, coh_d)

def ttest_2samp(dat1, dat2):
    print('SD dat 1: ',np.std(dat1))
    print('SD dat 2: ',np.std(dat2))
    print('Stats:')
    stats = scipy.stats.ttest_ind(dat1, dat2)
    print(stats)
    print('Cohen d:')
    nx = len(dat1)
    ny = len(dat2)
    dof = nx + ny - 2
    coh_d = ((np.mean(dat1) - np.mean(dat2)) /
             np.sqrt(((nx-1)*np.std(dat1, ddof=1) ** 2 + (ny-1)*np.std(dat2, ddof=1) ** 2) / dof))
    print(coh_d)
    return(stats, coh_d)
# Pairwise t-tests
ndim1 = 2; ndim2 = 1;
dat1 = totalDat.query('nDim == %i'%ndim1)['Score'];
dat2 = totalDat.query('nDim == %i'%ndim2)['Score'];
stats = ttest_2samp(dat1,dat2)
print(len(dat1)+len(dat2))
print(stats)

print('\n\n\n\n')

ndim1 = 3; ndim2 = 2;
dat1 = totalDat.query('nDim == %i'%ndim1)['Score'];
dat2 = totalDat.query('nDim == %i'%ndim2)['Score'];
stats = ttest_2samp(dat1,dat2)
print(len(dat1)+len(dat2))
print(stats)<jupyter_output>SD dat 1:  0.08777239347058706
SD dat 2:  0.06961437542226533
Stats:
Ttest_indResult(statistic=2.2421872379859473, pvalue=0.026817679416952206)
Cohen d:
0.4227908801786129
120
(Ttest_indResult(statistic=2.2421872379859473, pvalue=0.026817679416952206), 0.4227908801786129)





SD dat 1:  0.099128143778086
SD dat 2:  0.08777239347058706
Stats:
Ttest_indResult(statistic=2.933773726320993, pvalue=0.004128289853703749)
Cohen d:
0.6337675596029382
105
(Ttest_indResult(statistic=2.933773726320993, pvalue=0.004128289853703749), 0.6337675596029382)<jupyter_text>Relationship between model features/complexity and response time  Compute overall log response time<jupyter_code>RTchoices = ['RT_radio','RT_submit']
#
RTdat = gameDat[['subID','Type_Total','phase','RT_radio','RT_submit']
                   ].groupby(['subID']).mean().reset_index()
RTdat = RTdat.merge(bestPerSubject[['sub_ID','nDim','Complexity','comb']],
                    left_on='subID', right_on = 'sub_ID')
for rci, RTchoice in enumerate(RTchoices):
    RTuse = 'log_%s'%RTchoice
    RTdat[RTuse] = np.log(RTdat[RTchoice] / 1000)
display(RTdat.head())
#
RTdat_splitPhase = gameDat[['subID','Type_Total','phase','RT_radio','RT_submit']
                   ].groupby(['subID','phase']).mean().reset_index()
RTdat_splitPhase = RTdat_splitPhase.merge(bestPerSubject[['sub_ID','nDim','Complexity','comb']],
                    left_on='subID', right_on = 'sub_ID')
for rci, RTchoice in enumerate(RTchoices):
    RTuse = 'log_%s'%RTchoice
    RTdat_splitPhase[RTuse] = np.log(RTdat_splitPhase[RTchoice] / 1000)
display(RTdat_splitPhase.head())<jupyter_output><empty_output><jupyter_text>First test early-late RT diff<jupyter_code>rt_phase_diff = RTdat_splitPhase.pivot('subID', 'phase', 'log_RT_radio').reset_index()
rt_phase_diff['diff'] = rt_phase_diff['late'] - rt_phase_diff['early']
plt.hist(rt_phase_diff['diff'])
scipy.stats.normaltest(rt_phase_diff['diff'])
scipy.stats.wilcoxon(rt_phase_diff['diff'])
ttest_1samp(rt_phase_diff['diff'], 0)<jupyter_output>SD:  0.42639946372104104
Stats:
Ttest_1sampResult(statistic=-8.237211337988368, pvalue=8.299819559676345e-14)
Cohen d:
-0.6748186464141427<jupyter_text>Plot<jupyter_code>fig, ax = plt.subplots(1,2,figsize=[14,6])
x_name = 'Complexity'
x_list = RTdat[x_name].unique().tolist()
x_list.sort()
hue_name = 'phase'
if hue_name == 'phase':
    plot_dat = RTdat_splitPhase
else:
    plot_dat = RTdat

for rci, RTchoice in enumerate(RTchoices):
    RTuse = 'log_%s'%RTchoice
    sns.barplot(data = plot_dat,
                ax = ax[rci],
           hue = hue_name, 
                y = RTuse, x = x_name, order = x_list,
           hue_order = ['early','late'],
           capsize=.1, errwidth = 0, errcolor = 'k', alpha = .6, zorder = 0)
    sns.stripplot(data = plot_dat,
                ax = ax[rci],
           hue = hue_name, 
                  y = RTuse, x = x_name, order = x_list,
           hue_order = ['early','late'],
           dodge=True, edgecolor = 'k', linewidth=.5, alpha = .8, zorder = 1)
    sns.barplot(data = plot_dat,
                ax = ax[rci],
           hue = hue_name, 
                y = RTuse, x = x_name, order = x_list,
           hue_order = ['early','late'],
           capsize=.1, errwidth = 1, errcolor = 'k', alpha = 0, zorder = 2)
    if hue_name is None:
        print(scipy.stats.f_oneway(*[plot_dat.query('%s == @i'%x_name)[RTchoice] for i in x_list]))
    else:
        if rci == 0:
            [hand,lab] = ax[rci].get_legend_handles_labels()
ax[0].set(ylabel = 'Log RT', ylim = [0,3.2],
         xlabel = x_name, title = 'Prediction button')
plt.tight_layout()<jupyter_output><empty_output><jupyter_text>RT radio button only:<jupyter_code>x_name = 'Complexity'
x_list = RTdat[x_name].unique().tolist()
x_list.sort()
RTchoice = 'RT_radio'
RTuse = 'log_%s'%RTchoice
fig, ax = plt.subplots(1,2,figsize=[14,6])

# Plot log mean RT per subject
sns.barplot(data = RTdat, ax = ax[0],
            y = RTuse, x = x_name, order = x_list,
            capsize=.1, errwidth = 0, errcolor = 'k', alpha = .5, zorder = 0)
sns.stripplot(data = RTdat, ax = ax[0],
            y = RTuse, x = x_name, order = x_list,
            dodge=True, edgecolor = 'k', linewidth=0, alpha = .5, zorder = 1)
sns.barplot(data = RTdat, ax = ax[0],
            y = RTuse, x = x_name, order = x_list,
            capsize=.1, errwidth = 1, errcolor = 'k', alpha = 0, zorder = 2)
# F-test
f_result = scipy.stats.f_oneway(*[plot_dat.query('%s == @i'%x_name)[RTchoice] for i in x_list])
print(f_result)
FigureTools.add_sig_markers(ax[0], relationships=[[0,2,f_result[1]]],
                           caps = False, ystart = 3.4)
# Axes
ax[0].set(ylabel = 'Log RT', ylim = [0,4], xlabel = 'Information sources',
         xticklabels = ['—','S / T','S & T'])

# Plot log mean RT per subject
sns.barplot(data = RTdat_splitPhase, ax = ax[1],
            hue = 'phase',
            y = RTuse, x = x_name, order = x_list,
            capsize=.1, errwidth = 0, errcolor = 'k', alpha = .5, zorder = 0)
[hand,lab] = ax[1].get_legend_handles_labels()
sns.stripplot(data = RTdat_splitPhase, ax = ax[1],
              hue = 'phase',
            y = RTuse, x = x_name, order = x_list,
            dodge=True, edgecolor = 'k', linewidth=0, alpha = .5, zorder = 1)
sns.barplot(data = RTdat_splitPhase, ax = ax[1],
            y = RTuse, x = x_name, order = x_list,
            hue = 'phase',
            capsize=.1, errwidth = 1, errcolor = 'k', alpha = 0, zorder = 2)
# T-test
comp2_late_v_early = (RTdat_splitPhase.query('Complexity == 2 and phase == "late"').log_RT_radio.values
            - RTdat_splitPhase.query('Complexity == 2 and phase == "early"').log_RT_radio.values)
comp1_late_v_early = (RTdat_splitPhase.query('Complexity == 1 and phase == "late"').log_RT_radio.values
            - RTdat_splitPhase.query('Complexity == 1 and phase == "early"').log_RT_radio.values)
ttest_result_diff_scores_comp2_vs_comp1 = scipy.stats.ttest_ind(
    comp1_late_v_early, comp2_late_v_early)
print(ttest_result_diff_scores_comp2_vs_comp1)

FigureTools.add_sig_markers(ax[1],
            relationships=[[1,2,ttest_result_diff_scores_comp2_vs_comp1[1]]],
           caps = 0.2, ystart = 3.4)
# Axes
ax[1].set(ylabel = 'Log RT', ylim = [0,4], xlabel = 'Information sources',
         xticklabels = ['—','S / T','S & T'])
plt.legend(hand,['1-8','9-16'],loc='upper left', title = 'Trial nr')
plt.tight_layout()
ttest_2samp(comp1_late_v_early, comp2_late_v_early)
f_dat = [RTdat_splitPhase.query('phase == "early" and Complexity == @i')[RTuse].values for i in [0,1,2]]
len(f_dat[1])+len(f_dat[2])
scipy.stats.f_oneway(*f_dat)
print(scipy.stats.normaltest(f_dat[1]))
print(scipy.stats.normaltest(f_dat[2]))
print(scipy.stats.mannwhitneyu(f_dat[0],f_dat[1]))
print(scipy.stats.mannwhitneyu(f_dat[1],f_dat[2]))
RT_LMER_dat = RTdat_splitPhase.copy()
RT_LMER_dat.head()<jupyter_output><empty_output><jupyter_text>Plot split only<jupyter_code>fig, ax = plt.subplots(1,1,figsize=[6,4])

sns.barplot(data = RTdat_splitPhase, ax = ax,
            hue = 'phase', y = RTuse, x = x_name, order = x_list,
            capsize=.1, errwidth = 0, errcolor = 'k', alpha = .6, zorder = 0,
           palette = [sns.color_palette('Greys',6)[i] for i in [2,5]])
[hand,lab] = ax.get_legend_handles_labels()
sns.stripplot(data = RTdat_splitPhase, ax = ax,
              hue = 'phase', y = RTuse, x = x_name, order = x_list,
            dodge=True, edgecolor = 'k', linewidth=0, alpha = .6, zorder = 1,
             palette = [sns.color_palette('Greys',6)[i] for i in [2,5]], size = 5)
sns.barplot(data = RTdat_splitPhase, ax = ax,
            y = RTuse, x = x_name, order = x_list,
            hue = 'phase', capsize=.1, errwidth = 2, errcolor = 'k', alpha = 0, zorder = 2)
FigureTools.add_sig_markers(ax,
            relationships=[[1,2,ttest_result_diff_scores_comp2_vs_comp1[1]]],
           caps = 0.2, ystart = 3.4)
# Axes
ax.set(ylabel = 'Log RT', ylim = [0,4], xlabel = 'Information sources',
         xticklabels = ['—','S / T','S & T'])
plt.legend(hand,['1-8','9-16'],loc='upper left', title = 'Trial nr',
          frameon=False)

sns.despine(top=True, right = True)
linedat = RTdat_splitPhase.groupby(['Complexity','phase']).mean()[RTuse]
fig, ax = plt.subplots(1,1,figsize=[6,4])
barcolors = [[1,1,1],sns.color_palette('Greys',5)[2]]
# barcolors.append([0,0,0])

# sns.barplot(data = RTdat_splitPhase, ax = ax,
#             hue = 'phase', y = RTuse, x = x_name, order = x_list,
#             capsize=.1, errwidth = 0, errcolor = 'k', alpha = 0, zorder = 0,
#            palette = barcolors)
# [hand,lab] = ax.get_legend_handles_labels()
sns.stripplot(data = RTdat_splitPhase, ax = ax,
              hue = 'phase', y = RTuse, x = x_name, order = x_list,
            dodge=True, edgecolor = 'k', linewidth=1, alpha = 1, zorder = 1,
             palette = barcolors, size = 5)
[hand,lab] = ax.get_legend_handles_labels()
sns.barplot(data = RTdat_splitPhase, ax = ax,
            y = RTuse, x = x_name, order = x_list,
            hue = 'phase', capsize=.1, errwidth = 2, errcolor = 'k', alpha = 0, zorder = 2)
FigureTools.add_sig_markers(ax,
            relationships=[[1,2,ttest_result_diff_scores_comp2_vs_comp1[1]]],
            ystart = 3.6, distScale = .5, interact_caps=True)
linedat = RTdat_splitPhase.groupby(['Complexity','phase']).mean()[RTuse]
for comp in [0,1,2]:
    ax.plot([comp-.2,comp+.2],linedat[comp].values,'k-')
    
# Axes
ax.set(ylabel = 'Log RT', ylim = [0,4], xlim = [-.5,2.5], xlabel = 'Information sources',
         xticklabels = ['No S or T','S or T','S and T'])
ax.get_legend().remove()
scat1 = ax.scatter([5],[3], 50, [barcolors[0]], edgecolors = 'k', linewidths = 2)
scat2 = ax.scatter([5],[3], 50, [barcolors[1]], edgecolors = 'k', linewidths = 2)

plt.legend((scat1,scat2), ['1-8','9-16'],handletextpad=0,
           loc='upper left', title = 'Trial nr.',
          frameon=False)

sns.despine(top=True, right = True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17150624482880894, 'fraction_numerical': 0.03723257554863874, 'mean_word_length': 4.07944766860116, 'pattern_counts': {'":': 2, '<': 46, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '591556', 'license': 'MIT', 'n_tokens_mistral': 10183, 'n_tokens_neox': 9583, 'n_words': 1695, 'path': 'Study1_MTurk/Analysis_scripts/2.Modeling/2.Speed-accuracy_trade-off.ipynb', 'repo_name': 'jeroenvanbaar/NHB_motives_structure', 'size': '25381'}