Introduction

This is a touchscreen and mouse friendly version of the Simon task.

The N-Back task goes back more than half a century, developed in the 1950s by Kirchner, as you can read in more detail on wikipedia.

In short, in the N-Back task, participants are presented a sequence of stimuli one-by-one. For each stimulus, they need to decide if the current stimulus is the same as the one presented N trials ago. The N can be 1 trials, 2 trials, 3 trials, etc. The higher the number, the more difficult the task. The factors that seem to influence the performance are not only the N, but also the speed of presentation and the size of the set of stimuli.

About this implementation

Key features of this implementation:

  • This is a 2-back task

  • The total stimulus set contains 15 stimuli (letters)

  • Each stimulus is presented for maximally 760 milliseconds

  • The intertrial interval is 2000 ms

  • A new stimulus is presented every 2760 milliseconds

The letters A,B,C,D,E,H,I,K,L,M,O,P,R,S, and T are being used.

There are 25 trials in each of the three blocks.

In this n-back task, the first training block shows the previous two stimuli, which helps the participant to learn the task.

Run the demo

You need the mouse and sound

Data output file

In PsyToolkit, the data output file is simply a textfile. The save line of the PsyToolkit experiment script determines what is being saved in the data output file. Typically, for each experimental trial, you would have exactly one line in your text file, and each number/word on that line gives you the information you need for your data analysis, such as the condition, response speed, and whether an error was made.

Meaning of the columns in the output datafile. You need this information for your data analysis.

Colum Meaning

1

BLOCKNUMBER

2

trial counter

3

the score of current trial (1=correct,0=wrong)

4

whether the response given was a correct match (1=participant correctly matched 2-back trial)

5

whether the response given was a miss (1=participant failed to respond)

6

whether the response given was a false alarm (1=participant clicked even though it was a non-match)

7

reaction time in milliseconds

8

computer determined this to be a matching trial (1: match, except for first two trials)

9

current stimulus number (between 1 and 15)

10

stimulus previous trial (n-1)

11

stimulus two trials ago (n-2)

PsyToolkit code

Click to expand the PsyToolkit script code (part of zip file below)
options
  bitmapdir stimuli
  sounddir stimuli
  set &maxrt 760 # stimulus presentation
  set &iti 2000  # intertrial interval
  set &choosechance 3 # 1 in 4 are matching
  mouse on
  
sounds
  sound_good good.mp3
  sound_bad  wrong.mp3

fonts
  arial 18

bitmaps
  letterA ## 15 letters
  letterB
  letterC
  letterD
  letterE
  letterH
  letterI
  letterK
  letterL
  letterM
  letterO
  letterP
  letterR
  letterS
  letterT
  overlay
  instruction1
  instruction2
  instruction3

## a part is a reusable piece of code. In this case, it gives for the
## 3 blocks the feedback

part myfeedback
  feedback
    text align left
    set &Total1 count ; select c8 == 1 && c1 == BLOCKNUMBER ## number of trials where there was a 2back item
    set &Total2 count ; select c8 > 1 && c1 == BLOCKNUMBER ## number of trials where there was NOT a 3back item
    set &Matches count     ; select c4 == 1 && c1 == BLOCKNUMBER ## number of matches
    set &Misses count      ; select c5 == 1 && c1 == BLOCKNUMBER ## number of misses
    set &FalseAlarms count ; select c6 == 1 && c1 == BLOCKNUMBER ## number of false alarms
    set &MatchesPerc      expression &Matches     / &Total1 * 100.0
    set &MissesPerc       expression &Misses      / &Total1 * 100.0
    set &FalseAlarmsPerc  expression &FalseAlarms / &Total2 * 100.0
    text -250 -200 "There were 25 trials in total in this block"
    text -250 -150 &Total1 ; prefix "Total trials that had a match:"
    text -250 -100 &Total2 ; prefix "Total trials that had no match:"
    text -250 -50 &Matches ; prefix "Number of correctly matched items:"
    text -250 -0 &Misses ; prefix "Number of missed items:"
    text -250  50 &FalseAlarms ; prefix "Number of false alarms:"
    text -250 100 &MatchesPerc ; prefix "Percentage correct matches:" ; postfix " %"
    text -250 150 &MissesPerc  ; prefix "Percentage missed items:" ; postfix " %"
    text -250 200 &FalseAlarmsPerc ; prefix "Percentage false alarms:" ; postfix " %"
    text -250 250 "Click mouse to continue and show data"
    wait_for_key mouse
  end

task nback_learning
  set &trialcount increase
  set $currentletter random 1 15 ## choose randomw letter, might be overridden
  ############################################################################
  ## is this condition a yes condition?
  set $memory random 1 &choosechance ## 1 in &choosechance trials will be matching trial
  ## if a 2back trial (there must have been at least 2 trials before for this to be possible)
  if $memory == 1 && &trialcount > 2
    set $currentletter &nback2
    set $requiredresponse 1 ## this is a MATCH, so response is required
  fi
  ## if a NON 2back trial
  if $memory != 1 || &trialcount <= 2 ## chose a letter but not that of 2 trials ago
    set $currentletter random 1 15
    while $currentletter == &nback2 ## choose anything but NOT that of 2 back
      set $currentletter random 1 15
    while-end
    set $requiredresponse 2 ## this is a NON-match, so people need to withhold
  fi
  ############################################################################
  ## this part is the only part that is different between learning and non-learning
  draw off
    show bitmap $currentletter ## stimulus 1
    ## now show previous trials
    if &trialcount > 1
      show bitmap &nback1 -100 0     # show 1-back left of stimulus
      show bitmap overlay -100 0  # greyed out
    fi
    if &trialcount > 2
      show bitmap &nback2 -200 0     # show 2-back left of stimulus
      show bitmap overlay -200 0  # greyed out
    fi
  draw on
  ######################################################################
  readmouse l 1 &maxrt ## click the first bitmap in this task
  ############################################################################
  ## the different possible response outcomes
  ##
  if $requiredresponse == 1 and STATUS != TIMEOUT
    set $score 1 ## means good
    set $match 1
    sound sound_good
  fi
  if $requiredresponse == 1 and STATUS == TIMEOUT
    set $score 0 ## means wrong -- miss
    set $miss 1
    sound sound_bad
  fi
  if $requiredresponse == 2 and STATUS == TIMEOUT
    set $score 1 ## means good
  fi
  if $requiredresponse == 2 and STATUS != TIMEOUT
    set $score 0 ## means wrong
    set $false_alarm 1
    sound sound_bad
  fi
  #
  ######################################################################
  #
  set $extrawait expression &maxrt - RT ## how much time is left between max RT and now?
  delay $extrawait ## wait until letter has been on screen total of 2000 ms
  clear screen
  delay 2000 ## wait 2000 ms
  #
  ### now save the letter for next trial
  #
  set &nback2 &nback1
  set &nback1 $currentletter
  ### save the data
  save BLOCKNUMBER &trialcount $score $match $miss $false_alarm RT $memory $currentletter &nback1 &nback2

task nback_normal
  set &trialcount increase
  set $currentletter random 1 15 ## choose randomw letter, might be overridden
  ############################################################################
  ## is this condition a yes condition?
  set $memory random 1 &choosechance ## 1 in &choosechance trials will be matching trial
  ## if a 2back trial (there must have been at least 2 trials before for this to be possible)
  if $memory == 1 && &trialcount > 2
    set $currentletter &nback2
    set $requiredresponse 1 ## this is a MATCH, so response is required
  fi
  ## if a NON 2back trial
  if $memory != 1 || &trialcount <= 2 ## chose a letter but not that of 2 trials ago
    set $currentletter random 1 15
    while $currentletter == &nback2 ## choose anything but NOT that of 2 back
      set $currentletter random 1 15
    while-end
    set $requiredresponse 2 ## this is a NON-match, so people need to withhold
  fi
  ############################################################################
  ## this part is the only part that is different between learning and non-learning
  draw off
    show bitmap $currentletter ## stimulus 1
  draw on
  ######################################################################
  readmouse l 1 &maxrt ## click the first bitmap in this task
  ############################################################################
  ## the different possible response outcomes
  ##
  if $requiredresponse == 1 and STATUS != TIMEOUT
    set $score 1 ## means good
    set $match 1
    sound sound_good
  fi
  if $requiredresponse == 1 and STATUS == TIMEOUT
    set $score 0 ## means wrong -- miss
    set $miss 1
    sound sound_bad
  fi
  if $requiredresponse == 2 and STATUS == TIMEOUT
    set $score 1 ## means good
  fi
  if $requiredresponse == 2 and STATUS != TIMEOUT
    set $score 0 ## means wrong
    set $false_alarm 1
    sound sound_bad
  fi
  #
  ######################################################################
  #
  set $extrawait expression &maxrt - RT ## how much time is left between max RT and now?
  delay $extrawait ## wait until letter has been on screen total of 2000 ms
  clear screen
  delay 2000 ## wait 2000 ms
  #
  ### now save the letter for next trial
  #
  set &nback2 &nback1
  set &nback1 $currentletter
  ### save the data
  save BLOCKNUMBER &trialcount $score $match $miss $false_alarm RT $memory $currentletter &nback1 &nback2

block training
  set &trialcount 0 # make sure you use this again if you have another block
  message instruction1 mouse
  message instruction2 mouse
  tasklist
    nback_learning 25
  end
  part myfeedback

block normal1
  set &trialcount 0 # make sure you use this again if you have another block
  message instruction3 mouse
  tasklist
    nback_normal 25
  end
  part myfeedback

block normal2
  set &trialcount 0 # make sure you use this again if you have another block
  message instruction3 mouse
  tasklist
    nback_normal 25
  end
  part myfeedback

Download

If you have a PsyToolkit account, you can upload the zipfile directly to your PsyToolkit account. Watch a video on how to do that. If you want to upload the zipfile into your PsyToolkit account, make sure the file is not automatically uncompressed (some browsers, especially Mac Safari, by default uncompress zip files). Read here how to easily deal with this.

Further reading

  • Kirchner, W. K. (1958). Age differences in short-term retention of rapidly changing information. Journal of Experimental Psychology, 55, 352-358.

  • Jaeggi, S.M., Buschkuehl, M., Perrig, W.J., & Meier, B. (2010). The concurrent validity of the N-back task as a working memory measure. Memory, 18, , 394–412.