Summary

  • This is an essential lesson for anyone learning PsyToolkit experiment setup

  • This lesson about how to use tables to tell PsyToolkit what your different experimental conditions in your experiment look like.

  • An experimental condition refers to what what happens in a trial (more detailed explanation here).

Introduction

In experiments, you often have exactly the same sequence of events (the things that happen in one trial).

For example, in the Stroop task, you have the same sequence of events:

  • Show a colored word (for example, the word RED)

  • Wait for a key press from keyboard (for example, the key R to indicated red)

  • Tell the participant if the response was correct or not with an on-screen message

  • Store the stimulus, the response time and which key was pressed

You run this sequence over and over again (for example 50 times) with slightly different conditions. Instead of the word RED, you might show the word RED or BLUE and so on.

Some beginnners make the mistake to write a different task for each condition. That works, but it is no efficient. Here you learn how to do it better.

The way to correctly code this in PsyToolkit is as follows:

1) You have a task to carry out the sequence of events

2) You have a table that tells Psytoolkit which words are correct and which keys have to be pressed. These are the conditions of your experiment.

Basic example of the task

Basically, if you would have just one condition in a Stroop task, you could write the task as follows.

In our example, people need to press the R key when the word is in red ink (i.e., font color), the B key when the word is in blue ink, the G key if the word is in green ink, and the Y key if the ink is in yellow ink.
Example that works, but that is not very efficient
task stroop_red_word
  keys r g b y
  show text "RED" 0 0 red
  readkey 1
  save RT KEY

This works, but you would need to write the same code for blue, yellow, green, and yellow words as well as for congruent and incongruent stimuli. That is HIGHLY INEFFICIENT.

Instead, you want to use a table to describe all conditions and use those in your one and only Stroop task. You use the instruction table for this as well as the @ sign to use one of the parts of the table.

in the next section how table work and how to use them for this Stroop paradigm

How tables work

In PsyToolkit, a table can be used to describe stimuli. In the case of Stroop, we want to describe for each condition the word, the color, the expected keyboard key, and if the condition is a congruent or an incongruent condition.

There are different ways to do it. For the color, we will use a number, 1 for red, 2 for green, 3 for blue, and 4 for yellow. We let the task sort out the details of the color. First let’s create the table:

table MyStroopTable
  "RED"     1  "congruent"
  "GREEN"   2  "congruent"
  "BLUE"    3  "congruent"
  "YELLOW"  4  "congruent"
  "RED"     2  "incongruent"
  "GREEN"   1  "incongruent"
  "BLUE"    4  "incongruent"
  "YELLOW"  3  "incongruent"

On each line, now have three pieced of information, namely the word (in quotes), the color (not in quotes, because it is a number to be used by PsyToolkit) and the condition (in quotes, PsyToollkit only uses this for the output data storage file as a human readable word).

In a real experiment, you might add more incongruent conditions, but here we have just four of them. For example, we only have RED printed in green color, but ideally it should also be presented in blue and yellow. For simplicity, we use a short table here.

The main point here is that the table contains the necessary information for eight different conditions. There are eight lines and each of them has a different condition.

How to use the table in a task

How do you use the above example table in your task? That is explained here.

If there is only one table, your task will automatically use the table. If you have more than one table, you can have a line specifying which table to use, but for now, we assume there is just one table.

Let’s assume your script has a task called stroop. The task will be repeated 10x. That means that the participant will be given a colored word and has to respond to it 10x. That is how most cognitive psychological experiments work.

Each time a task is being repeated, it will randomly select one of the rows of your table. It is as simple as that.

Within your task, you can pick the information out of the table using the @ symbol. Just look at the example below. Actually, we use the color information from the table. We use little "if".."fi" blocks. It is really simple.

Imagine that PsyToolkit chooses the first line of the table for the current trial. It will start with checking if the second column of that first line is a 1 (if @2 == 1) and if that is the case, it will do a "show text @1 0 0 red", that is, it will show the text, as provided in the first column of the table at screen position 0 0 (which is screen center) in the color red.

task stroop
   keys r g b y
   if @2 == 1
     show text @1 0 0 red
   fi
   if @2 == 2
     show text @1 0 0 green
   fi
   if @2 == 3
     show text @1 0 0 blue
   fi
   if @2 == 4
     show text @1 0 0 yellow
   fi

That is all! Now the rest is just for checking that the correct button is being pressed ans saving the information, let’s add first the waiting for a keypress. We wait for 5000 milliseconds (or 5 seconds) for the second column of the table to be pressed. If the first row of the table is being used by PsyToolkit, for example, it means that the key should be 1 (which corresponds to the "r" from the keys line)

   readkey @2 5000

Let’s check if the response if correct or wrong, again with some if statements. Everything between if and fi is only done if the if line is true. The == symbol means "is equal" (you can also use just one = symbol). The else line shows if the status was not correct. It should be straightforward to follow; the logic is as follows:

if something is true do something else do something else fi

The word fi is just the opposite of if and tells PsyToolkit when the if statement ends.
   if STATUS == CORRECT
     show text "Well done" 0  100
   else
     show text "Wrong response" 0 1000
   fi
   delay 2000
   clear screen

Finally, save the information to the output file for later analysis. The information from the third and first column is just useful when analyising

   save @3 @1 RT STATUS

It might in the data output file look like this:

   incongruent RED 1425 1

For each trial you will thus get this information. Analysing data is not part of this lesson, but there is good documentation about that.

Run the demo

This is the complete experiment

Complete code

For an explanation of this code, watch this short video tutorial taking you over all the lines of the code: https://youtu.be/YDFcE3eJOBg.
Copy and paste this code to your PsyToolkit account (as an experiment)
table MyStroopTable
  "RED"     1  "congruent"
  "GREEN"   2  "congruent"
  "BLUE"    3  "congruent"
  "YELLOW"  4  "congruent"
  "RED"     2  "incongruent"
  "GREEN"   1  "incongruent"
  "BLUE"    4  "incongruent"
  "YELLOW"  3  "incongruent"

fonts
   arial 40

task stroop
   keys r g b y
   if @2 == 1
     show text @1 0 0 red
   fi
   if @2 == 2
     show text @1 0 0 green
   fi
   if @2 == 3
     show text @1 0 0 lightblue
   fi
   if @2 == 4
     show text @1 0 0 yellow
   fi
   readkey @2 5000
   clear -1 # remove word stimulus directly after key press
   if STATUS == CORRECT
     show text "Well done" 0  100
   else
     show text "Wrong response" 0 100
   fi
   delay 2000
   clear screen
   save @3 @1 RT STATUS

block teststroop
   tasklist
     stroop 5
   end