Psych 45: N-back stats 2018


In [1]:
%matplotlib inline

import pandas as pd
import seaborn as sns
sns.set(style='ticks', context='poster', font_scale=1.5)

Import data file


In [2]:
data = pd.read_csv('https://raw.githubusercontent.com/sgagnon/Psych45/master/WWW/demos/Psych45-nback_stats_2018.csv')

# filter RT column so just a number (ms and comma not included)
data.avg_rt = data.avg_rt.str.strip(' ms').str.replace(',', '').astype(float)

data.percent_correct = data.percent_correct.astype(float)
data.combined = data.combined.str.replace(',', '').astype(float)

# task_list = ['2-back', '3-back', '4-back', '5-back', '6-back', '7-back', '8-back']
task_list = ['2-back', '3-back', '4-back', '5-back']
task_list_subset = ['2-back', '3-back', '4-back']

In [3]:
data.head()


Out[3]:
task percent_correct avg_rt combined when
0 2-back 73.33 651.12 887.88 14 hours ago
1 2-back 66.67 640.53 960.80 14 hours ago
2 2-back 40.00 787.44 1968.61 14 hours ago
3 2-back 80.00 848.13 1060.16 17 hours ago
4 2-back 86.67 809.40 933.92 17 hours ago

Analyses

Number of data points:


In [4]:
data.groupby(['task']).count().when


Out[4]:
task
2-back    178
3-back    127
4-back     52
5-back     32
Name: when, dtype: int64

Mean accuracy and response time:


In [5]:
data.groupby(['task']).mean().reset_index()


Out[5]:
task percent_correct avg_rt combined
0 2-back 69.942472 891.442865 1901.678876
1 3-back 56.290866 956.276850 1985.452913
2 4-back 54.309423 915.449808 1962.284423
3 5-back 62.312187 838.333437 1524.368125

How does task affect percent of trials correct?


In [6]:
g = sns.factorplot(x='task', y='percent_correct', 
                   order=task_list,
                   data=data, 
                   ci=95, 
                   aspect=2.3,
                   palette=sns.color_palette("Blues_r", 
                                             n_colors=len(task_list)))
g.set_xlabels('')
g.set_ylabels('% correct')
g.set_xticklabels(rotation=30)
sns.despine(trim=True)



In [7]:
g = sns.factorplot(x='task', y='percent_correct', 
                   order=task_list_subset,
                   data=data, 
                   palette=sns.color_palette("Blues_r", 
                                             n_colors=len(task_list_subset)), 
                   ci=95, 
                   aspect=1.3)
g.set_ylabels('% correct')
g.set_xlabels('')
g.set_xticklabels(rotation=30)
sns.despine(trim=True)


How does task affect average response time on correct trials?


In [8]:
g = sns.factorplot(x='task', y='avg_rt', 
                   order=task_list,
                   data=data, 
                   palette=sns.color_palette("Blues_r", 
                                             n_colors=len(task_list)), 
                   ci=95, 
                   aspect=2.3)
g.set_ylabels('avg RT (ms)')
g.set_xlabels('')
g.set_xticklabels(rotation=30)
sns.despine(trim=True)



In [9]:
g = sns.factorplot(x='task', y='avg_rt', 
                   order=task_list_subset,
                   data=data, 
                   palette=sns.color_palette("Blues_r", 
                                             n_colors=len(task_list_subset)), 
                   ci=95, 
                   aspect=1.3)
g.set_ylabels('avg RT (ms)')
g.set_xlabels('')
g.set_xticklabels(rotation=30)
sns.despine(trim=True)


What about combined (correct and incorrect trials) RT?


In [10]:
g = sns.factorplot(x='task', y='combined', 
                   order=task_list,
                   data=data, 
                   palette=sns.color_palette("Blues_r", 
                                             n_colors=len(task_list)), 
                   ci=95, 
                   aspect=2.3)
g.set_ylabels('combined RT (ms)')
g.set_xlabels('')
g.set_xticklabels(rotation=30)
sns.despine(trim=True)