Psych 45: Semantic memory demo stats

In [1]:
%matplotlib inline
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import scipy as sp
sns.set(style='ticks', context='poster', font_scale=1)
In [2]:
data = pd.read_csv('Semantic_demo.csv',
                  index_col=[0],header = [0,1],skipinitialspace=True)
data.head()
Out[2]:
Timestamp Fruit Sport Bird Vehicle Crime Vegetable
fig apple strawberry hockey football wrestling Wren ostrich robin tricycle boat car murder embezzling vagrancy carrot parsley onion
5/5/20 22:02 6 2 3 3 2 5 5 6 3 3 1 1 2 3 4 1 1 1
5/6/20 9:45 7 1 1 4 1 1 7 7 1 6 1 1 1 1 5 1 6 4
5/6/20 10:35 6 1 1 1 1 2 2 3 1 3 5 1 1 2 5 3 3 3
5/6/20 11:58 6 1 4 2 6 6 6 1 1 6 5 1 1 1 7 1 6 1
5/6/20 12:01 6 1 4 3 6 2 7 1 1 6 6 1 1 1 7 1 5 1
In [3]:
print('We currently have data from ' + str(data.count()[0]) + ' students.')
We currently have data from 183 students.
In [4]:
df = data.unstack().reset_index(name='rating')
df.rename(columns={'Timestamp': 'category', 'level_1': 'item','level_2':'timestamp'}, inplace=True)
df = df[np.isfinite(df['rating'])]
df.head()
Out[4]:
category item timestamp rating
0 Fruit fig 5/5/20 22:02 6
1 Fruit fig 5/6/20 9:45 7
2 Fruit fig 5/6/20 10:35 6
3 Fruit fig 5/6/20 11:58 6
4 Fruit fig 5/6/20 12:01 6
In [6]:
temp = df.item[df.category=='Vegetable']
temp.unique()
Out[6]:
array(['carrot', 'parsley ', 'onion'], dtype=object)
In [7]:
category_list = df.category.unique()
#category_list =(['fruit', 'sport', 'bird', 'vehicle', 'crime', 'vegetable'])
category_list
Out[7]:
array(['Fruit', 'Sport', 'Bird', 'Vehicle', 'Crime', 'Vegetable'],
      dtype=object)
In [ ]:
 
In [8]:
f, axes = plt.subplots(ncols=len(category_list), figsize=(15, 3), sharey=True)
plt.locator_params(nbins=5)
first = True

for ax, category in zip(axes, category_list):
    ax.hlines(y=1, xmin=-1, xmax=4, linestyles='dashed', colors='green')
    g = sns.pointplot(x='item', y='rating', ax=ax, jitter=True, alpha=.4, 
                      ci=95, palette=['darkgray'],
                      data=df.loc[df.category == category])
    g.set_title(category)
    g.set_ylabel('')
    g.set_xlabel('')
    g.set_xticklabels(df.loc[df.category == category].item.unique(), rotation=90)
    
f.text(0.07, 0.1, 'Rating', va='center', rotation='vertical', fontsize='xx-large')
sns.despine()
In [9]:
f, ax = plt.subplots(ncols=1, figsize=(10, 4), sharey=True)
g = sns.stripplot(x='item', y='rating', jitter=True, alpha=.1, size=12, linewidth=1,
                  data=df.loc[df.category == 'Fruit'], 
                  order=['apple', 'strawberry', 'fig'],
                  palette=['limegreen', 'hotpink', 'mediumpurple'], ax=ax)
g.set_xlabel('')
Out[9]:
Text(0.5, 0, '')
In [10]:
f, ax = plt.subplots(ncols=1, figsize=(10, 4), sharey=True)
g = sns.stripplot(x='item', y='rating', jitter=True, alpha=.1, size=12, linewidth=1,
                  data=df.loc[df.category == 'Sport'], 
                  order=['football', 'hockey', 'wrestling'],
                  palette=['peru', 'black', 'blue'], ax=ax)
g.set_xlabel('')
Out[10]:
Text(0.5, 0, '')
In [ ]:
 
In [ ]: