Reaction times

christophe@pallier.org

Sept. 2013

  1. Write a program, using pygame, that starts with an empty black screen and after one second, displays a small white dot at the center of the screen for 1 second, waits for another second and then quits (tip: use the function pygame.time.delay to wait for a given amount of time)
#include <simple-rt1.py>
  1. Start the following program, move the mouse into the pygame window and clik on it several times, press keys, … close the window to quit.
import pygame

pygame.init()
screen = pygame.display.set_mode((640, 400))

while True:
    event = pygame.event.wait()
    if event.type == pygame.QUIT:
        break
    print(pygame.event.event_name(event.type))

pygame.quit()

(you can skim through the tutorial at http://lorenzod8n.wordpress.com/2007/05/30/pygame-tutorial-3-mouse-events/ ) to understand pygame’s mouse events. Now, modify the previous code so that the dot remains on the screen until you press a mouse button.

#include <simple-rt2.py>
  1. Look at the documentation of the function pygame.time.get_ticks() and add code to measure and print the reaction-times, that is the time between the onset of the dot’s display and the mouse button press.
#include <simple-rt2b.py>
  1. Modify the previous program to repeat the process for 32 trials, and:
#include <simple-rt3.py>
  1. Look at your reaction time data. If you know to do it, plot histograms with a spreadsheet program or R (or any other software)

Launch spyder. Go to the console window, in the options, set the working directory to the directory that contains reaction-times.csv. Type the following commands:

f = open('reaction-times.csv')
l = []
for line in f:
    l.append(int(line))
l
plot(l)
hist(l)
mean(l)
median(l)
  1. Back to the reaction time program, write a function that removes the 25% extreme data points in a list and returns the mean and standard errors of the remaining data points (not using numpy).
#include <simple-rt4.py>
  1. Change the size of the dot so that it is 10 times bigger than previously. Rerun the experiment. How is your reaction times affected?

  2. Now, change the contrast of the dot with the background (make it grey rather than white). How is your reaction times affected?

  3. Modify the previous program so that the color of target is randomly chosen between blue and red (with equal probability) at each trial. You still use only one response button.

  4. The task is to now to take a decision: one mouse button is assigned to blue and another one to red (if you only have one mouse button, use 2 keys and the KEYDOWN event). In the results file, save both the button pressed and the reaction times (on row per trial). Compare decision times to simple reaction times.

  5. Modify the program so that the dot can appear (randomly) at one of two locations far on the left or far on the right of the center. How is your reaction time affected?

  6. (advanced): Modify the simple detection program so that the contrast can be modified at each trial. Write the program to find the threshold of detection of the do.