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 pingouin as pg

import ipywidgets as widgets

# Enable plots inside the Jupyter Notebook
%matplotlib inline

Signal detection: Part 2

Authored by Todd Gureckis.

In the previous lab you learned some of the basis analysis steps involved in signal detection analysis. In particular, we learned how to compute a statistic we called d' (dprime) and c (bias/criterion). These variables are commonly used in studies of perception to understand the performance of a subject on a task independent of their response bias (here meaning tendency to give a particular response).

In the second part of the lab we will analyze data from a simple detection experiment you will have just conducted on yourselves. You will get to put your python knowledge into practice by reading in the data analyzing it.

Experiment design

In the experiment, you saw a number of trials where a small fixation cross appeared for 500 ms. Next, a relatively low contrast gabor patch appeared someplace at a constant distance from the fixation for another 500ms. This was set so that the stimulus was far enough away that you could only really barely detect it using your peripheral vision. Your task was to indicate if it was a "stimulus present" trial or a "stimulus absent" trial. The computer recorded your response and your reaction time.

An overview of the situation is shown here:

The things we didn't measure but did control!

You have to look closely to see the tiny gabor patch! On each trial the gabor patch's location was chosen at random but to keep things roughly the same difficulty it always appeared on the edge of the circle with a given radius. The term eccentricity is sometimes used to talk about the distance of a stimulus from a central fixation point and it is often measured in various units of the degrees of the angle of a triangle formed between the observer's eye, the central fixation point, and the location of the stimulus (usually its center). However, this measure is only really meaningful if all observers view the stimulus on the same size monitor and with a fixed viewing distance from the screen. Since we did this a little more informally (using your own laptops) we have much less information about the visual angle of the eccentricity and so we will ignore it for now.

The things we manipulated!

There were actually two different gabor pathes shown on any given "stimulus present" trial. One was a low contrast stimulus:

and the other a high contrast stimulus:

This should obviously influence the detection of the stimulus making it harder to see the stimulus in the low contrast condition compared to the high contrast condition.

In total there were 50 high contrast stimulus present trials, 50 low contrast stimulus present trials, and 100 stimulus absent trial. The purpose of this was so that a perfect subject with robot-quality vision would say "yes" half the time in the experiment so there is no overall bias toward one response.

In this lab we are interested in analyzing the effect of stimulus contrast on the two signal detection variables we learned about in the previous lecture and lab.

Analysis Steps

Remember from the previous lab that our model for signal detection looks something like this:

and we showed how we can compute $d'$ and $c$ by computing only the number of false alarms and hits and subjecting those to a particular mathematical transformation. In this case we actually have two stimulus conditions (high/low contrast). So our goal will be to compute the hits and false alarms separately for the two different types of stimuli. This will mean that each person in our experiment will be described by four numbers:

  • A d' (d-prime) under high contrast conditions
  • A d' (d-prime) under low contrast conditions
  • A c under high contrast conditions
  • A c under low contrast conditions

Once we have this we want to perform a simple hypothesis test. Is performance, measured by d' higher in the high contrast condition. We have strong reason to suspect this is the case but it'll be a nice check of our understanding if we can related the abstract calculation we performed in the previous lab to answer this simple quesiton.

Answering this question will push our skills at using pandas to organize our data, and using pingouin to compute a t-test.

As a reminder the following show a simple for loop (called a list comprehension) that lets you get the filenames for the lab data set. You can use this to find the file names that you need to read in with pd.read_csv(). If you need a reminder refer back to your mental rotation lab which should be on your Jupyterhub node still!

# 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=['sdt1-data/'+f for f in os.listdir('sdt1-data') if not f.startswith('.')]