Introduction

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.

In a typical experiment, you see that letters are presented for 500 ms followed by a 2500 black period. This timing seems to be used in lots of N-back studies (e.g., Kane & Conway, 2007).

In total, people get 3 seconds (500 ms + 2500 ms) to respond if the letter matches the letter N trials ago.

If there is no match, people do not need to respond.

There are different types of response (or lack thereof):

Name of response Type Meaning

Match

Correct

Participant correctly pressed the m key because the letter matches the letter of 2 trials ago

False Alarm

Error

Participant pressed m key wrongly, because the letter 2 trials ago was a different one

Miss

Error

Participant did not press m key, but they should have because the letter 2 trials ago was the same

In the following, a matching trial is one in the letter matches the letter of two trials ago and the participant should press the m key.

About this implementation

Key features of this implementation:

  • This is a 2-back task

  • The total stimulus set is 15 stimuli (letters)

  • Each stimulus is presented for 500 milliseconds

  • People get 3 seconds to respond

  • A new stimulus is presented every 3000 milliseconds

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

There are 3 blocks of each 25 trials.

Detailed feedback is given.

Run the demo

You need to press the m if the stimulus is the same as 2 trials ago. Otherwise withhold. The m key was chosen because the work memory starts with an "m".

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 (the number of the block, there are 3 blocks)

2

Trial number (the number of the trial)

3

Type of trial (1=a matching stimulus ; 0=a non-matching stimulus)

4

Score (1 means correct, 0 means incorrect)

5

Match (1 means participants matched correctly, 0 otherwise; only meaningful on match trials)

6

Miss (1 means participants missed, 0 otherwise; only meaningful on non-matching trials)

7

False Alarm (1 means participants wrongly pressed button, 0 otherwise; only meaningful on non-matching trials)

8

Reaction Time

9

Memory (a variable used internally)

10

Current letter (the current letter, a number between 1 and 15, representing letterA, etc)

11

nback1 (the letter 1 trial ago, a number between 1 and 15, representing with letterA, etc)

12

nback2 (the letter 2 trials ago, a number between 1 and 15, representing with letterA, etc)

PsyToolkit code

Click to expand the PsyToolkit script code (part of zip file below)
## Copyright: see http://www.psytoolkit.org/copyright.html
##
## this is a two back task
##
## the total time window during which people can give a response is
## the intertrial interval + the stimulus display time
## the 500 + 2500 is a commonly used timing of events in nback tasks

options
  bitmapdir stimuli
  set &stimulus_display_time 500 # stimulus presentation
  set &iti 2500  # intertrial interval
  set &choosechance 3 # 1 in "choosechance" are matching. The higher the number, the fewer matches
  
fonts
  arial 18

bitmaps
  letterA ## 15 letters
  letterB
  letterC
  letterD
  letterE
  letterH
  letterI
  letterK
  letterL
  letterM
  letterO
  letterP
  letterR
  letterS
  letterT
  overlay
  error_feedback
  correct_feedback
  grey_feedback
  instruction1
  instruction2
  realblock1
  realblock2
  
part myfeedback
  feedback
    text align left
    set &Total1 count ; select c3 == 1 && c1 == BLOCKNUMBER ## number of trials where there was a 2back item
    set &Total2 count ; select c3 == 0 && c1 == BLOCKNUMBER ## number of trials where there was NOT a 3back item
    set &Matches count     ; select c5 == 1 && c1 == BLOCKNUMBER ## number of matches
    set &Misses count      ; select c6 == 1 && c1 == BLOCKNUMBER ## number of misses
    set &FalseAlarms count ; select c7 == 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 "Press button Q to continue"
    wait_for_key q
  end

## the "part" below is a piece of code used several times in the code.
## this is just a placeholder which is used in the last later on.
## see the PsyToolkit documentation on how "part" works in detail

part check_response
  if $requiredresponse == 0 and STATUS == TIMEOUT
    set $score 1  ## so far so good
  fi
  if $requiredresponse == 0 and STATUS != TIMEOUT
    set $score 0  ## wrongly pressed during letter presentation.
    set $false_alarm 1
    show bitmap error_feedback  ## red rectangle below and over letter
  fi
  if $requiredresponse == 1 and STATUS != TIMEOUT
    set $score 1  ## correctly pressed during letter presentation.
    set $match 1
    show bitmap correct_feedback  ## green rectangle below and over letter
  fi

task twoback
  keys m
  set &trialcount increase
  set $currentletter random 1 15 ## choose random letter out of the 15 options
  ############################################################################
  ## is this condition a yes condition?
  set $memory random 1 &choosechance ## random number for choosing condition
  ## if a 2back trial
  if $memory == 1 and &trialcount > 2
    set $currentletter &nback2
    set $requiredresponse 1 ## the m key needs to be pressed later, m=stands for Memory
    set $typeoftrial 1
  fi
  ## if a NON n-back trial
  if $memory != 1 or &trialcount <= 2 ## chose a letter but not that of 3 trials ago
    set $currentletter random 1 15
    while $currentletter == &nback2 ## choose anything but NOT that of 3 back
      set $currentletter random 1 15
    while-end
    set $requiredresponse 0 ## no key should be pressed
    set $typeoftrial 0
  fi
  ############################################################################
  draw off
    show bitmap $currentletter ## stimulus 1
    show bitmap grey_feedback  ## stimulus 2
  draw on
  readkey 1 &stimulus_display_time
  set $extrawait expression &stimulus_display_time - RT ## how much time is left between max RT and now?
  ##############################################################
  ## determine whether error was made during letter presentation
  ## people can only make mistake if pressing now when they should not
  ##############################################################
  set $score 0 ## this is the default, assume error
  part check_response
  set $my_rt RT
  ###########
  ## now wait remaining time if needed
  ###########
  delay $extrawait ## wait until letter has been on screen total of 760 ms, note this only happens if people already pressed
  clear 1 ## clear the letter from screen
  ###########
  ## now show nothing but allow response during ITI
  ###########
  if STATUS == TIMEOUT ## means people did not respond yet
    readkey 1 &iti
    set $my_rt expression RT + &stimulus_display_time
  fi
  part check_response
  ## if you pressed, then some time will be left; during that time, no need to further check keys anymore
  set $extrawait expression &iti - RT ## how much time is left between iti RT and now?
  ## now check if people missed
  if $requiredresponse == 1 and $score == 0
    set $miss 1
  fi
  delay $extrawait
  ### now save the letter for next trial
  set &nback2 &nback1
  set &nback1 $currentletter
  ### save the data
  save BLOCKNUMBER &trialcount $typeoftrial $score $match $miss $false_alarm $my_rt $memory $currentletter &nback1 &nback2

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

block nback_real1
  set &trialcount 0 # make sure you use this again if you have another block
  message realblock1
  tasklist
    twoback 25
  end
  part myfeedback

block nback_real2
  set &trialcount 0 # make sure you use this again if you have another block
  message realblock2
  tasklist
    twoback 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.

  • Kane, M.J. & Conway, A. (2007). Working memory, attention control, and the N-back task: A question of construct validity. Journal of Experimental Psychology: Learning, Memory, and Cognition, 33(3), 615-622.