Background

The Simon effect is a well know effect in cognitive experimental psychology. There are many papers about this effect and it can be implemented in slightly different ways.

In this example, we have two stimuli that participants have to respond to, and these two stimuli can each appear in two different positions on the screen, which leads to four different experimental conditions:

  1. Left pointing arrow and positioned left of fixation point (compatible)

  2. Right pointing arrow and positioned right of fixation point (compatible)

  3. Left pointing arrow and positioned right of fixation point (incompatible)

  4. Right pointing arrow and positioned left fixation point (incompatible)

In this task, people need to respond with a left button press (the A on regular keyboard) to left-pointing arrows, no matter if these arrows appear left or right from the fixation point.

In this task, people need to respond with a right button press (the L on regular keyboard) to right-pointing arrows, no matter if these arrows appear left or right from the fixation point.

Conditions 1 and 2 are called "compatible", because there is a straightforward correspondence between the pointing of the arrow and the location.

We know that people respond more slowly and less accurately in incompatible conditions.

Preparation

For this experiment, you need a number of stimuli. Each of these can be made with Inkscape, and the example file with these stimuli can be downloaded from here.

  1. Two arrows (left and right pointing)

  2. Fixation point (for example a plus symbol)

  3. Instructions (as bitmaps)

Code

Complete Simon task
options
  fullscreen
  resolution 1200 800

bitmaps
  instruction
  leftarrow
  rightarrow
  fixpoint1
  fixpoint2
  fixpoint3
  errorleft
  errorright
  fingers
  countdown0
  countdown1
  countdown2
  countdown3 countdown3.jpg

fonts
  arial 18

table simontasktable
  "L_pos L_arrow" -200 1 leftarrow   1
  "R_pos R_arrow"  200 2 rightarrow  2
  "R_pos L_arrow"  200 3 leftarrow   1
  "L_pos R_arrow" -200 4 rightarrow  2

task simon
  table simontasktable
  keys a l
  show bitmap fixpoint1 #1
  delay 60
  show bitmap fixpoint2 #2
  delay 60
  show bitmap fixpoint3 #3
  delay 60
  clear 3
  delay 60
  clear 2
  delay 60
  clear 1
  delay 60
  show bitmap @4 @2 0
  readkey @5 2000
  clear -1
  if STATUS != CORRECT
    if @5 == 1
      show bitmap errorleft
    fi
    if @5 == 2
      show bitmap errorright
    fi
    delay 5000
    clear -1
  fi
  delay 500
  save BLOCKNAME @1 @3 TABLEROW KEY STATUS RT

message instruction

block trainingblock
  bitmap fingers
  delay 4000
  bitmap countdown0
  delay 700
  bitmap countdown1
  delay 700
  bitmap countdown2
  delay 700
  bitmap countdown3
  delay 700
  clear screen
  delay 700
  tasklist
    simon 20
  end
  feedback
    label 0 -250  "Error percentage and response times in training block"
    label 0 -200  "(in ms = milliseconds = there are 1000 ms in one second)"
    text  0 -150  perc 20 ; prefix "Percentage errors (should really be below 10%):" ; postfix "%" ; select c7 != 1
    text  0 -100  mean c8 ; prefix "Average speed of ALL CORRECT RESPONSES:" ; postfix "ms" ; select c7 == 1
    label 0  200  "This was just training. Now press space bar of your keyboard"
    label 0  250  "with the REAL data collection (will take about 5 minutes)"
  end
  wait_for_key

block mainblock
  bitmap countdown0
  delay 700
  bitmap countdown1
  delay 700
  bitmap countdown2
  delay 700
  bitmap countdown3
  delay 700
  clear screen
  delay 700
  tasklist
    simon 102
  end
  feedback
    label 0 -250  "Error percentage and response times"
    label 0 -200  "(in ms = milliseconds = there are 1000 ms in one second)"
    text  0 -150  perc 100 ; prefix "Percentage errors (can easily be below 10%):" ; postfix "%" ; select c7 != 1
    text  0 -100  mean c8 ; prefix "Average speed of ALL CORRECT RESPONSES:" ; postfix "ms" ; select c7 == 1
    text  0 -50   mean c8 ; prefix "LEFT pointing arrow on LEFT side:" ; postfix "ms" ; select c7 == 1 && c4 == 1
    text  0 -0    mean c8 ; prefix "RIGHT pointing arrow on RIGHT side:" ; postfix "ms" ; select c7 == 1 && c4 == 2
    text  0  50   mean c8 ; prefix "LEFT pointing arrow on RIGHT side:" ; postfix "ms" ; select c7 == 1 && c4 == 3
    text  0  100  mean c8 ; prefix "RIGHT pointing arrow on LEFT side:" ; postfix "ms" ; select c7 == 1 && c4 == 4
    label 0  250  "Now continue, click continue button below black
  area with mouse."
  end

The code explained

Sections

First of all, note that there are different sections:

  1. options

  2. bitmaps

  3. fonts

  4. table

  5. task

  6. message

  7. block

Sections are separated from one another by an empty line!

The options explained

options
  fullscreen
  resolution 1200 800

Note that you do not need options. They are optional. They can activate special features. For example, in the web based version of PsyToolkit, you can specify that you want to run your experiment in fullscreen mode (this is the default in the Desktop/Linux version, and there you do not need to specify it). Further, you can specify how large the draw-able area on the screen is (the resolution). You need to specify this in width and height. The default resolution in PsyToolkit experiments is 800 by 600 pixels. There was a time that 800 by 600 screens were quite common. For comparison, today’s High Definition television has a resolution of 1280 by 720 pixels. Modern computer screens are 1920 by 1080 pixels.

If you want to make sure that an experiment can be shown on most computers, you better do not make it too large. 800 by 600 is typically large enough.

The bitmaps section explained

Every experiment has stimuli, and they need to be "loaded". For example, you can load "images". In PsyToolkit images are always called bitmaps, and they can be provided in any bitmap format (for example, png, jpeg, bmp, gif). The default format is png, and you do not need to specify the filename. However, for other formats, you need to specify the filename as well (as an example, this is done for the final bitmap name "countdown3". Each file in the example lines below imply that there is a png file. Thus, there will be a file "instruction.png", "leftarrow.png", etc.

bitmaps
  instruction
  leftarrow
  rightarrow
  fixpoint1
  fixpoint2
  fixpoint3
  errorleft
  errorright
  fingers
  countdown0
  countdown1
  countdown2
  countdown3 countdown3.jpg
File names are not allowed to have spaces!

The fonts section explained

Occasionally, you want to use fonts. A font is a computer file that contains information on how to display text. This file contains information on how to display each letter. A common format for fonts is the TrueType format (and there are many free TrueType files online).

In the example, we tell the computer to use font arial, which is very common.

fonts
  arial arial.ttf 18
Fonts are handled slightly differently on the Desktop and Web-based versions of PsyToolkit. For the Desktop/Linux version, you must provide the TrueType file. However, for the webbased PsyToolkit version, the built-in fonts of the browser will be used, and the actual file will be ignored.

The table section explained

The table helps you do specify the parameters for the different conditions. For example, in this Simon experiment, each trial has the same timing, but there are four different conditions.

The table used here has a name "simontasktable" and four lines
table simontasktable
  "L_pos L_arrow" -200 1 leftarrow   1
  "R_pos R_arrow"  200 2 rightarrow  2
  "R_pos L_arrow"  200 3 leftarrow   1
  "L_pos R_arrow" -200 4 rightarrow  2

There are the following important points to make about tables:

  • A table must have a name. Here it is "simontasktable"

  • Each line on a table must have the same number of items, here there are 5

  • You can use strings and words in quotes (like the first item of each line here)

Further, you can refer to exactly one table in a task

  • If you use a table in a task, you must specify that (see below)

  • In a task, a random line of the table will be selected each time the the task is carried out

  • In a task, you use the "@" sign to refer to the nth elemement on a table row (see below)

  • You can refer to bitmaps. Make sure you do not put the bitmap names in quotes

The task section explained

Below, different parts of the task will be explained one by one.

The first lines just tell computer about details, but do not really do anything. The "table" line tells the computer which table to use (even if there is only one table, you still need to specify it.

The keys command tells the computer which keys of the keyboard are being used in this experiment.

  table simontasktable
  keys a l
There are a whole bunch of special keys, such as "space", "slash", "period".

Next, we ask the computer to show a bitmap, in this case the bitmap "fixpoint1". Note that the corresponding bitmap file is actually called "fixpoint1.png". Also note that the # sign at the end of the line starts the comment just for humans, the computer ignores this. In this case, it is the number of the visual stimulus (this being the first visual stimulus).

  show bitmap fixpoint1 #1
  delay 60

p Next, we show the second and third fixpoints. Now 60 milliseconds is really short. What I am doing here is really creating an animation. Fixpoint 2 is slightly larger than fixpoint 1, and fixpoint 3 is slightly larger than fixpoint 2. That way, this "growing" and then "decreasing" fixpoint really captures the attention.

  show bitmap fixpoint2 #2
  delay 60
  show bitmap fixpoint3 #3
  delay 60

Now we remove the bitmaps 1, 2, 3 one by one, this causes the decreasing fixpoint animation effect.

  clear 3
  delay 60
  clear 2
  delay 60
  clear 1
  delay 60

Now we show the critical stimulus on screen. @4 is the stimulus (the bitmap), @2 the horizontal X position and 0 is the vertical Y position (which remains the same throughout the experiment). The latter is 0, because 0,0 is the original of the screen center.

  show bitmap @4 @2 0

Next, we wait 2000 ms to read a key. We tell the computer that the number in the fifth column of the table is the correct key (@5). Those numbers are based on the keys line. If we say "keys a l", we mean that "a" corresponds to key number 1 and "l" to key number two.

  readkey @5 2000

If we want to remove the previously shown stimulus, we could use that number (here we could use number 4, but it is easier to use "-1", which just means, remove whatever stimulus was show previously. You can also use "-2", etc.

  clear -1

Next, we carry out some code only conditionally. Everything between a line starting with "if" and "fi" ("if" written in opposite direction, as in some computer languages). In this case, we use the "readkey" STATUS variable, which can have 3 different values, namely, CORRECT, WRONG, or TIMEOUT. These just correspond to 1, 2, and 3, which you could use instead.

  if STATUS != CORRECT

Next, within the "if" block, we have another "if". Yes that is possible like in any programming language. In this case, we check if the current row of the table (note, each time the task runs, only one row is selected, in this case at random). If the fifth item of the current row has the value 1, the bitmap errorleft is being shown.

    if @5 == 1
      show bitmap errorleft
    fi

Next, we check if possibly the fifth item on the current tablerow is 2.

    if @5 == 2
      show bitmap errorright
    fi
    delay 5000
    clear -1
  fi

At the end, we wait another 500 ms. You typically want some time between trials (the so called "intertrial interval, or ITI". The we use the important "save" command to save the variables of the trial to the datafile that we will later analyze. In this case, we save the name of the block we are in (each block has a name). It saves the first and third items of the current table row, the TABLEROW number, the key being used (in Javascript, this corresponds to the ascii code of the key pressed, for example, the space key has value 32). We also save the STATUS of the "readkey" command (1=correct,2=wrong,3=too slow) and the response time.

  delay 500
  save BLOCKNAME @1 @3 TABLEROW KEY STATUS RT
There are a number of variables in capitals that are common and important, these are BLOCKNAME, TABLEROW, KEY, and RT.

The message section explained

A message just shows a bitmap and waits for a key press. This is handy at the beginning and end of an experiment, for example, to welcome a participant or to give an instruction.

message instruction

The block sections explained

The block is essentially a way to instruct a participant to do a number of trials. It usually starts with an instruction, and it can end with some feedback about the performance in the block (as is the case in this experiment). This block is fairly sophisticated, and much simpler blocks are possible.

As with "task", a "block" needs to have a name. In the "save" statement, you can save the current block’s name with BLOCKNAME.

block trainingblock

In this specific example, we show a couple of bitmaps of the screen and have a countdown 3, 2, 1 (actually the filenames have the opposite order, but that is just because the way I named them here). Note that this is fairly similar to "task", but here there is no "show" in front of a bitmap. This is for special reasons. Within a block section, showing a bitmap is really for instructional reasons, they are not the type of stimuli within a task.

  bitmap fingers
  delay 4000
  bitmap countdown0
  delay 700
  bitmap countdown1
  delay 700
  bitmap countdown2
  delay 700
  bitmap countdown3
  delay 700
  clear screen
  delay 700

Each block must at least have one tasklist. A tasklist tells the computer which tasks to carry out and how often. For example, in this example, the task "simon" is called twenty times. There are a whole bunch of special options (such as requesting that the task goes on until the participant has done at least 10 times correct without making an error, or selecting each condition once before repeating).

  tasklist
    simon 20
  end
Make sure you have the "end" after you specify each task. Typically, you have only one task, but there are situations in which you have different tasks within one block, for example in task-switching experiments.

You can add feedback. Minimal requirement is that you have specified at least one font (which we have done, namely "arial"). Each line of the feedback statement puts some text online and an analysis of the response times and accuracy. Feedback is fairly complex, and it is explained in detail elsewhere in this documentation. You do not need it, and it is something for advanced users. Note that the feedback ends with an "end" line, similar to the "tasklist".

  feedback
    label 0 -250  "Error percentage and response times in training block"
    label 0 -200  "(in ms = milliseconds = there are 1000 ms in one second)"
    text  0 -150  perc 20 ; prefix "Percentage errors (should really be below 10%):" ; postfix "%" ; select c7 != 1
    text  0 -100  mean c8 ; prefix "Average speed of ALL CORRECT RESPONSES:" ; postfix "ms" ; select c7 == 1
    label 0  200  "This was just training. Now press space bar of your keyboard"
    label 0  250  "with the REAL data collection (will take about 5 minutes)"
  end
The "feedback" is really only for advanced PsyToolkit users".

At the end of the block, we keep the feedback on the screen until any key is being pressed. "wait_for_key" just does what is on the tin.

  wait_for_key
In this experiment we have two blocks, but there are almost the same. Typically, we have different blocks so that participants get some time between blocks.

Data analysis

If you run your experiment in the browser, you can show the data and copy it into a text file and then save to your local computer drive for later analysis.

The data files can be imported into R using the read.table command, but, of course, you can analyze your data with any statistical software.

See it in action

This experiment can be viewed in action here: http://psytoolkit.gla.ac.uk/simon