<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Reinforcement Learning Models of Social Group Preferences
Bandit Experiments 1-7
Step1:  Experiment 1
Step2:  Experiment 2
Step3:  Experiment 2
Step4:  Experiment 3
Step5:  Experiment 3
Step6:  Experiment 4
Step7:  Experiment 4
Step8:  Experiment 5
Step9:  Experiment 6
Step10:  Experiment 6
Step11:  Experiment 7
Step12:  Experiment 7
<ASSISTANT_TASK:>
Python Code:
# imports / display plots in cell output
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as ss
import pandas as pd
import seaborn as sns
import statsmodels
Explanation: Reinforcement Learning Models of Social Group Preferences
Bandit Experiments 1-7
End of explanation
# Bayesian Model Selection (bor = .6240)
# Model 1: inverse temperature, stickiness, learning rate
# Model 2: inverse temperature, stickiness, positive learning rate, negative learning rate
models = ('Model 1', 'Model 2')
y_pos = np.arange(len(models))
pxp = [0.6880, 0.3120]
plt.bar(y_pos, pxp, align='center', alpha=0.5)
plt.xticks(y_pos, models)
plt.ylabel('protected exceedance probability')
plt.title('Bayesian model selection')
plt.show()
# import post-mfit b1 (bandit_either) summary data
#b1 = pd.read_csv('/Volumes/crisp/hinl/bandit/gems_vs_bomb/rez/b1_d100_table.csv')
b1 = pd.read_csv('~/Desktop/bandit/gems_vs_bomb/rez/b1_d100_table.csv')
b1 = b1.drop('subID', axis=1)
data = pd.DataFrame(b1)
data.describe()
# plot differences in payout
with sns.plotting_context('talk', font_scale=1.4):
     sns.set_style("darkgrid")
     ax = sns.pointplot(data=b1, x='condition', y='payout', palette = ['#FFD479','#D783FF'])
     ax.figure.get_axes()[0].set_xticklabels(['bomb','gems'])
     #ax.figure.savefig('b1_pointplot')
Explanation: Experiment 1: between subjects design
-participants randomly assigned to receive only 'gems' or 'bomb' type rewards
End of explanation
# Bayesian Model Selection (bor = .778e-21)
# Model 1: inverse temperature, stickiness, learning rate
# Model 2: inverse temperature, stickiness, gems learning rate, bomb learning rate
# Model 3: inverse temperature, stickiness, positive learning rate, negative learning rate
# Model 4: inverse temperature, stickiness, learning rate, gems preference
models = ('Model 1', 'Model 2', 'Model 3', 'Model 4')
y_pos = np.arange(len(models))
pxp = [1, 0, 0, 0]
plt.bar(y_pos, pxp, align='center', alpha=0.5)
plt.xticks(y_pos, models)
plt.ylabel('protected exceedance probability')
plt.title('Bayesian model selection')
plt.show()
# import post-mfit b2 (bandit_either) summary data
#b2 = pd.read_csv('/Volumes/crisp/hinl/bandit/gems_vs_bomb/rez/b2_d100_table.csv')
b2 = pd.read_csv('~/Desktop/bandit/gems_vs_bomb/rez/b2_d100_table.csv')
b2 = b2.drop('subID', axis=1)
data = pd.DataFrame(b2)
data.describe()
Explanation: Experiment 2: within subjects design
-participants receive either 'gems' or 'bomb' type reward on each trial
-reward type for each door determined by fixed probability [0.8 0.6 0.4 0.2]
End of explanation
# plot preference for gems in terms of door probability
pDoor = b2[['chose80','chose60','chose40','chose20']]
with sns.plotting_context('talk', font_scale=1.4):
    sns.set_style("darkgrid")
    ax = sns.pointplot(data=pDoor, palette = ['#3DDA60','#fde73f','#62afea','#EF5050'])
    ax.figure.get_axes()[0].set_xticklabels(['0.80','0.60','0.40','0.20'])
    #ax.figure.savefig('b2_pointplot')
Explanation: Experiment 2: inferrential stats
paired t-test b/w gems & bombs: t = 1.86, p = 0.065
repeated measures ANOVA across doors: F = 6.17, p = 0.0004
End of explanation
# Bayesian Model Selection (bor = .7427)
# Model 1: inverse temperature, stickiness, learning rate
# Model 2: inverse temperature, stickiness, gems learning rate, bomb learning rate
# Model 3: inverse temperature, stickiness, positive learning rate, negative learning rate
# Model 4: inverse temperature, stickiness, learning rate, gems preference
models = ('Model 1', 'Model 2', 'Model 3', 'Model 4')
y_pos = np.arange(len(models))
pxp = [0.3497, 0.1857, 0.1857, 0.2789]
plt.bar(y_pos, pxp, align='center', alpha=0.5)
plt.xticks(y_pos, models)
plt.ylabel('protected exceedance probability')
plt.title('Bayesian model selection')
plt.show()
# import post-mfit b3 (bandit_either) summary data
#b3 = pd.read_csv('/Volumes/crisp/hinl/bandit/gems_vs_bomb/clean/b3_d100_table.csv')
b3 = pd.read_csv('~/Desktop/bandit/gems_vs_bomb/rez/b3_d100_table.csv')
b3 = b3.drop('subID', axis=1)
data = pd.DataFrame(b3)
data.describe()
Explanation: Experiment 3: narrative w/ low reward probability
-participants receive either 'gems' or 'bomb' type reward on each trial
-reward type for each door determined by fixed probability [0.8 0.6 0.4 0.2]
-intergroup bias computed by subtracting outgroup ID from ingroup ID
End of explanation
# plot preference for gems in terms of door probability
pDoor = b3[['chose80','chose60','chose40','chose20']]
with sns.plotting_context('talk', font_scale=1.4):
    sns.set_style("darkgrid")
    ax = sns.pointplot(data=pDoor, palette = ['#3DDA60','#fde73f','#62afea','#EF5050'])
    ax.figure.get_axes()[0].set_xticklabels(['0.80','0.60','0.40','0.20'])
    #ax.figure.savefig('b2_pointplot')
# regression of intergroup bias on model-based preference for gems
data = b3[['igbias','wGems']]
with sns.plotting_context('talk', font_scale=1.2):
    ax = (sns.jointplot(x='igbias', y='wGems', data=data, kind='reg', annot_kws=dict(stat='r'))
                       .set_axis_labels('intergroup bias', 'weight on gems parameter'))
    ax.savefig('b3_igbias_wGems')
# regression of intergroup bias on preference for gems
data = b3[['igbias','pGems']]
with sns.plotting_context('talk', font_scale=1.4):
    ax = (sns.jointplot(x='igbias', y='pGems', data=data, kind='reg', annot_kws=dict(stat='r'))
                       .set_axis_labels('intergroup bias', 'preference for gems'))
    #ax.savefig('b3_igbias_pGems')
Explanation: Experiment 3: inferrential stats
paired t-test b/w gems & bombs: t = 2.79, p = 0.006
repeated measures ANOVA across doors: F = 16.33, p < 0.0000
End of explanation
# Bayesian Model Selection (bor = 9.7058e-11)
# Model 1: inverse temperature, stickiness, learning rate
# Model 2: inverse temperature, stickiness, gems learning rate, bomb learning rate
# Model 3: inverse temperature, stickiness, positive learning rate, negative learning rate
# Model 4: inverse temperature, stickiness, learning rate, gems preference
models = ('Model 1', 'Model 2', 'Model 3', 'Model 4')
y_pos = np.arange(len(models))
pxp = [2.4264e-11, 2.4264e-11, 2.4264e-11, 1.0000]
plt.bar(y_pos, pxp, align='center', alpha=0.5)
plt.xticks(y_pos, models)
plt.ylabel('protected exceedance probability')
plt.title('Bayesian model selection')
plt.show()
# import post-mfit b4 (bandit_double) summary data
#b4 = pd.read_csv('/Volumes/crisp/hinl/bandit/gems_vs_bomb/rez/b4_d100_table.csv')
b4 = pd.read_csv('~/Desktop/bandit/gems_vs_bomb/rez/b4_best_table.csv')
b4 = b4.drop('subID', axis=1)
data = pd.DataFrame(b4)
data.describe()
Explanation: Experiment 4: narrative w/ multiple reward outcomes
-participants can receive either 'gems' and/or 'bomb' type reward on each trial
-reward type for each door determined by independent drifting probabilities for gems and bomb
-intergroup bias computed by subtracting outgroup ID from ingroup ID
End of explanation
# Bayesian Model Selection (bor = .0052)
# Model 1: inverse temperature, stickiness, learning rate
# Model 2: inverse temperature, stickiness, gems learning rate, bomb learning rate
# Model 3: inverse temperature, stickiness, positive learning rate, negative learning rate
# Model 4: inverse temperature, stickiness, learning rate, gems preference
models = ('Model 1', 'Model 2', 'Model 3', 'Model 4')
y_pos = np.arange(len(models))
pxp = [0.0013, 0.0013, 0.7480, 0.2494]
plt.bar(y_pos, pxp, align='center', alpha=0.5)
plt.xticks(y_pos, models)
plt.ylabel('protected exceedance probability')
plt.title('Bayesian model selection')
plt.show()
# import post-mfit b5 (bandit_either) summary data
#b5 = pd.read_csv('/Volumes/crisp/hinl/bandit/gems_vs_bomb/rez/b5_d100_table.csv')
b5 = pd.read_csv('~/Desktop/bandit/gems_vs_bomb/rez/b5_d100_table.csv')
data = pd.DataFrame(b5)
data.describe()
Explanation: Experiment 4: inferrential stats
paired t-test b/w gems & bombs: t = 2.69, p = 0.0079
Experiment 5: narrative w/ high reward probability
-participants receive either 'gems' or 'bomb' type reward on each trial
-reward type for each door determined by fixed probability [0.8 0.6 0.4 0.2]
-intergroup bias computed by subtracting outgroup ID from ingroup ID
-probability of reward twice as high as in Experiment 3
End of explanation
# plot preference for gems in terms of door probability
pDoor = b5[['chose80','chose60','chose40','chose20']]
with sns.plotting_context('talk', font_scale=1.4):
    sns.set_style("darkgrid")
    ax = sns.pointplot(data=pDoor, palette = ['#3DDA60','#fde73f','#62afea','#EF5050'])
    ax.figure.get_axes()[0].set_xticklabels(['0.80','0.60','0.40','0.20'])
    ax.figure.savefig('b5_pointplot')
# regression of intergroup bias on preference for gems
data = b5[['igbias','pGems']]
with sns.plotting_context('talk', font_scale=1.4):
    ax = (sns.jointplot(x='igbias', y='pGems', data=data, kind='reg', annot_kws=dict(stat='r'))
                       .set_axis_labels('intergroup bias', 'preference for gems'))
    ax.savefig('b5_igbias_pGems')
Explanation: Experiment 5: inferrential stats
paired t-test b/w gems & bombs: t = 4.28, p < 0.0000
repeated measures ANOVA across doors: F = 18.986, p < 0.0000
End of explanation
# Bayesian Model Selection (bor = 4.61e-37)
# Model 1: inverse temperature, stickiness, learning rate
# Model 2: inverse temperature, stickiness, gems learning rate, bomb learning rate
# Model 3: inverse temperature, stickiness, positive learning rate, negative learning rate
# Model 4: inverse temperature, stickiness, learning rate, gems preference
models = ('Model 1', 'Model 2', 'Model 3', 'Model 4')
y_pos = np.arange(len(models))
pxp = [1, 0, 0, 0]
plt.bar(y_pos, pxp, align='center', alpha=0.5)
plt.xticks(y_pos, models)
plt.ylabel('protected exceedance probability')
plt.title('Bayesian model selection')
plt.show()
# import post-mfit b6 (bandit_either) summary data
#b6 = pd.read_csv('/Volumes/crisp/hinl/bandit/gems_vs_bomb/rez/b6_d25_table.csv')
b6 = pd.read_csv('~/Desktop/bandit/gems_vs_bomb/rez/b6_model_4_table.csv')
data = pd.DataFrame(b6)
#data.describe()
Explanation: Experiment 6: political party w/ low reward probability
-participants receive either 'bill' or 'burning bill' type reward on each trial
-reward type for each door determined by fixed probability [0.8 0.6 0.4 0.2]
-intergroup bias computed by subtracting outgroup ID from ingroup ID
-probability of reward same as in Experiment 3 (mean = 0.25)
End of explanation
# plot preference for gems in terms of door probability
pDoor = b6[['chose80','chose60','chose40','chose20']]
with sns.plotting_context('talk', font_scale=1.4):
    sns.set_style("darkgrid")
    ax = sns.pointplot(data=pDoor, palette = ['#3DDA60','#fde73f','#62afea','#EF5050'])
    ax.figure.get_axes()[0].set_xticklabels(['0.80','0.60','0.40','0.20'])
    ax.figure.savefig('b6_pointplot')
# regression of behavioral 'preference for burn' on intergroup bias
data = b6[['pEarn','igbias']]
with sns.plotting_context('talk', font_scale=1.2):
    ax = (sns.jointplot(x='igbias', y='pEarn', data=data, kind='reg', annot_kws=dict(stat='r'))
                       .set_axis_labels('intergroup bias', 'preference for earning'))
    ax.savefig('b6_pEarn_x_igbias')
    
# regression of 'preference for earn' parameter on intergroup bias
data = b6[['wEarn','igbias']]
with sns.plotting_context('talk', font_scale=1.2):
    ax = (sns.jointplot(x='igbias', y='wEarn', data=data, kind='reg', annot_kws=dict(stat='r'))
                       .set_axis_labels('intergroup bias', 'weight on earning parameter'))
    ax.savefig('b6_wEarn_x_igbias')
Explanation: Experiment 6: inferrential stats
paired t-test b/w earn & burn: t = 0.0449, p = 0.96
repeated measures ANOVA across doors: F = 0.126, p = 0.94
End of explanation
# Bayesian Model Selection (bor = 1.410e-7)
# Model 1: inverse temperature, stickiness, learning rate
# Model 2: inverse temperature, stickiness, gems learning rate, bomb learning rate
# Model 3: inverse temperature, stickiness, positive learning rate, negative learning rate
# Model 4: inverse temperature, stickiness, learning rate, gems preference
models = ('Model 1', 'Model 2', 'Model 3', 'Model 4')
y_pos = np.arange(len(models))
pxp = [0.000001, 0.000001, 0.99999, 0.000001]
plt.bar(y_pos, pxp, align='center', alpha=0.5)
plt.xticks(y_pos, models)
plt.ylabel('protected exceedance probability')
plt.title('Bayesian model selection')
plt.show()
# import post-mfit b5 (bandit_either) summary data
#b7 = pd.read_csv('/Volumes/crisp/hinl/bandit/gems_vs_bomb/rez/b7_d25_table.csv')
b7 = pd.read_csv('~/Desktop/bandit/gems_vs_bomb/rez/b7_model_4_table.csv')
data = pd.DataFrame(b7)
data.describe()
Explanation: Experiment 7: political parties w/ high reward probability
-participants receive either 'bill' or 'burning bill' type reward on each trial
-reward type for each door determined by fixed probability [0.8 0.6 0.4 0.2]
-intergroup bias computed by subtracting outgroup ID from ingroup ID
-probability of reward same as in Experiment 5 (mean = 0.5)
End of explanation
# plot preference for gems in terms of door probability
pDoor = b7[['chose80','chose60','chose40','chose20']]
with sns.plotting_context('talk', font_scale=1.4):
    sns.set_style("darkgrid")
    ax = sns.pointplot(data=pDoor, palette = ['#3DDA60','#fde73f','#62afea','#EF5050'])
    ax.figure.get_axes()[0].set_xticklabels(['0.80','0.60','0.40','0.20'])
    ax.figure.savefig('b7_pointplot')
# regression of behavioral 'preference for burn' on intergroup bias
data = b7[['pEarn','igbias']]
with sns.plotting_context('talk', font_scale=1.2):
    ax = (sns.jointplot(x='igbias', y='pEarn', data=data, kind='reg', annot_kws=dict(stat='r'))
                       .set_axis_labels('intergroup bias', 'preference for earning'))
    ax.savefig('b7_pEarn_x_igbias')
# regression of 'preference for earn' parameter on intergroup bias
data = b7[['wEarn','igbias']]
with sns.plotting_context('talk', font_scale=1.2):
    ax = (sns.jointplot(x='igbias', y='wEarn', data=data, kind='reg', annot_kws=dict(stat='r'))
                       .set_axis_labels('intergroup bias', 'weight on earning parameter'))
    ax.savefig('b7_wEarn_x_igbias')
!pwd
Explanation: Experiment 7: inferrential stats
paired t-test b/w earn & burn: t = 1.7, p = 0.091
repeated measures ANOVA across doors: F = 2.50, p = 0.059
End of explanation
<END_TASK>