<jupyter_start><jupyter_text>Load data<jupyter_code>baseDir = os.path.realpath('../..')
print(baseDir)
sys.path.append('/'.join(os.path.realpath('..').split('/')[:4]) + '/Python')
import FigureTools
gameDat = pd.read_csv(baseDir+'/Data/gameDat_study2.csv',index_col=0)
gameDat = gameDat.rename(columns = {'ConfidenceNum':'Confidence','ScoreNum':'Score'})
gameDat.head()
print('%i participants found'%len(gameDat['subID'].unique()))
firstType = gameDat.loc[(gameDat['Trial']==0) & (gameDat['Block']==0), ['subID','Type_Total']].reset_index(drop=True)
firstType.columns = ['subID','FirstType']
thirdType = gameDat.loc[(gameDat['Trial']==0) & (gameDat['Block']==2), ['subID','Type_Total']].reset_index(drop=True)
thirdType.columns = ['subID','ThirdType']
gameDat = gameDat.merge(firstType,on='subID').merge(thirdType,on='subID')
gameDat.head()
gtOrder = ['HG','SG','SH','PD']
roundOrder = range(4)
ptOrder = ['opt_nat','pess_nat','opt_inv','pess_inv']
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)<jupyter_output><empty_output><jupyter_text>Supplemental Results 6 part 1: replicating the behavioral effects in study 2  Overall performance against chance<jupyter_code>gameDat.groupby('subID',as_index=False).mean()['Score'].mean()
ttest_1samp(gameDat.groupby('subID',as_index=False).mean()['Score'], .5)<jupyter_output>SD:  0.09250527856560403
Stats:
Ttest_1sampResult(statistic=9.624450775191141, pvalue=7.061977943310414e-13)
Cohen d:
1.37492153931302<jupyter_text>Overall performance by player type<jupyter_code>gameDat.columns
sns.set_context('poster')
blockDat = gameDat[['subID','Type_Total','Type','Variant','Confidence','Score']
                  ].groupby(['subID','Variant']).mean().reset_index()
fig, ax = plt.subplots(1,1,figsize=[6,5])
sns.barplot(data=blockDat,x='Variant',y='Score', ax=ax, errwidth = 3, capsize=.1,
            order=['nat','inv'],alpha=0)
sns.swarmplot(data=blockDat,x='Variant',y='Score', ax=ax,
            order=['nat','inv'], alpha=.3, color = 'k')
ax.plot([-5,5],[.5,.5], 'k--', lw=2)
ax.set(ylim = [0,1.1], xlim = [-.5,1.5], xlabel = None, yticks = [0,.25,.5,.75,1],
       title = 'Performance by strategy type',
       xticklabels = ['Human\nStrategies', 'Artificial\nStrategies'], ylabel = 'Accuracy     ');
dat1 = blockDat.loc[blockDat['Variant']=='nat','Score'].values
dat2 = blockDat.loc[blockDat['Variant']=='inv','Score'].values
stats = scipy.stats.ttest_rel(dat2,dat1)
FigureTools.add_sig_markers(ax, relationships=[[0,1,stats[1]]])
sns.despine(top=True,right=True)
ax.spines['left'].set_bounds(0,1)
ax.set_ylim([0,1.4])
print(np.std(dat1), np.std(dat2))
ttest_1samp(dat2-dat1, 0)<jupyter_output>0.09045026257562773 0.16851372347675428
SD:  0.15955994171470483
Stats:
Ttest_1sampResult(statistic=-16.945042539776924, pvalue=3.9594312009069757e-22)
Cohen d:
-2.420720362825275
StarcoderdataJupyterStructuredCleanDedup