from IPython.core.display import HTML, Markdown, display

import numpy.random as npr
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import scipy.stats as stats
import statsmodels.formula.api as smf
import ipywidgets as widgets

import os

Lab 1: Mental Rotation#

As described in the reading, in the Shepard & Metzler (1971) experiments, the time it took people to decide if an object was the same (just rotated) or different (a mirror reflection) depended on the angle of rotation:

In other words, it would take you longer to decide if the 30 degree rotated version of your cup was the same as the upright version relative to the 15 degree rotated version. The idea is that in order to make the same/mirror judgement, people actually mentally rotate the object. Bigger angles require more time to “rotate” in your mind just as they would in the real world (see Figure below). As mentioned in class, Cooper (1976) performed an even more interesting followup which provided even stronger evidence that people rotate objects when doing the matching task. Thus, most people agree that people do seem to perform some kind of mental rotation.

# this is an example list comprehension which reads in the all the files.
# the f.startswith() part just gets rid of any junk files in that folder 
filenames=['lab1-data/'+f for f in os.listdir('lab1-data') if not f.startswith('.')]

This gives a list of all the unique subjects in our data frame

array(['todd', 'db12', 'MC24', 'iw44', 'SK36', 'nd24', 'si13', 'so30',
       'AB29', 'bk90', 'Monishee Matin', 'j98', 'kc10', 'ml98', 'vt15',
       'Cc01', 'de24', 'ek87', 'pr27', 'kd27', 'JL29'], dtype=object)

This selects only the data from the second subject (db12)

subs = all_df.participant.unique()
trialResp.keys trialResp.corr trialResp.rt loop.thisRepN loop.thisTrialN loop.thisN loop.thisIndex loop.ran loop.order imagefile corrAns angle participant session date expName psychopyVersion frameRate
0 s 1 2.970 1 0 100 36 1 99 i17_50.jpg s 50 db12 1 2019-10-16_10h07.25.323 MentalRotationFinal 3.1.2 60
1 s 1 5.654 1 0 100 11 1 99 i5_100.jpg s 100 db12 1 2019-10-16_10h07.25.323 MentalRotationFinal 3.1.2 60
2 d 1 7.175 1 0 100 93 1 99 i43_100_R.jpg d 100 db12 1 2019-10-16_10h07.25.323 MentalRotationFinal 3.1.2 60
3 s 1 2.922 1 0 100 77 1 99 i35_150.jpg s 150 db12 1 2019-10-16_10h07.25.323 MentalRotationFinal 3.1.2 60
4 d 1 4.004 1 0 100 96 1 99 i45_100_R.jpg d 100 db12 1 2019-10-16_10h07.25.323 MentalRotationFinal 3.1.2 60

This plot reaction time as a function of angle separately for the same and different trial for this one participant.

for i,s in enumerate(subs):
    part_df = all_df[all_df.participant==s]