How to let a block go on until participant reaches a certain percentage correct or a certain speed level, or a a percentage correct in each condition?
This is a somewhat more advanced topic. It is assumed that you already understand the basics of PsyToolkit experiment scripts (such as stimulus presentation, response measurement, and condition tables). |
Here you learn how to do this.
Background
In cognitive psychological experiments, participants typically need to do things they have not done before. This takes some training. Sometimes you want to let the training go on until people can do one of the following:
1) Can do a task for a certain number of trials in a row without making an error. 2) Have a certain percentage correct in general 3) Have a certain percentage correct in each of the different conditions.
Number 1) is really simple to do in PsyToolkit, you can just specify the number of correct people should be doing at least in the tasklist statement, as explained here.
Numbers 2) and 3) are slightly more complicated, but can easily be used. The trick is to keep track of people’s performance in the task section and use the end tasklist statement when people have reached a certain level of performance.
Example code 1 — running until percentage correct
In this example, the block runs until the following two conditions have been satisfied:
1) The participant has done at least 20 trials 2) The participant performs at 95% correct or better
First run the example below to see what happend. The actual performance level is presented on screen while doing the task.
And here is the explanation.
bitmaps
intro
left
right
fix
mistake
fonts
arial 18 (1)
table simontasktable # table with four rows, each trial one row is randomly chosen
#-name of condition--------------position--stimulus--response
"left leftresponse compatible 1" -200 left 1
"right leftresponse incompatible 2" 200 left 1
"right rightresponse compatible 1" 200 right 2
"left rightresponse incompatible 2" -200 right 2
task simon
table simontasktable
set &number_of_trials increase (2)
keys a l
draw off
show text "Percentage correct:" -200 -200 (3)
show text &task_perc_correct 0 -200
show text "Trial number:" -200 -150
show text &number_of_trials 0 -150
draw on
delay 300
show bitmap fix
delay 300
show bitmap @3 @2 0
readkey @4 5000
clear -1 -2
if STATUS == CORRECT
set &correct_count increase (4)
fi
set &task_perc_correct expression ( &correct_count / &number_of_trials ) * 100 (5)
draw off
clear 2
show text &task_perc_correct 0 -200
draw on
if STATUS != CORRECT
show bitmap mistake
delay 1000
clear -1
fi
if &number_of_trials > 19 && &task_perc_correct >= 95 (6)
end tasklist (7)
fi
delay 500
save BLOCKNAME @1 STATUS RT
block test
message intro
tasklist
simon 100 ## run task up to maximally 100 trials
end
1 | You use text in this experiment, therefore you need to specify a font (read more). |
2 | We use a 'global' variable to keep track of number of trials. Note, global variable names start with & sign. The increase function just increases the variable by one (read here more). |
3 | As part of this demo, we show how many trials done, etc. In real experiments, you would probably not do this. |
4 | We use another 'global' variable to keep track of the number correct trials so far |
5 | We calculate the current percentage correct (note PsyToolkit only works with whole numbers). Read more. |
6 | We check if the criterial have been fulfilled. We want that the participant has done at least 20 trials, no matter what, and second, we want that the percentage correct is over 95%. Note that && stands for "and" (logical and). Read more. |
7 | If the condition has been fulfilled, tell PsyToolkit to end the current tasklist (i.e., block). Read more. |
Example code 2 — running until percentage correct and speed level had been reached
In this example, the block runs until the following three conditions have been satisfied:
1) The participant has done at least 20 trials 2) The participant performs at 95% correct or better 3) The participant performs on average faster than 1000 ms (i.e., 1 second).
First run the example below to see what happens. The actual performance level is presented on screen while doing the task.
And here is the explanation.
bitmaps
intro
left
right
fix
mistake
fonts
arial 18
table simontasktable # table with four rows, each trial one row is randomly chosen
#-name of condition--------------position--stimulus--response
"left leftresponse compatible 1" -200 left 1
"right leftresponse incompatible 2" 200 left 1
"right rightresponse compatible 1" 200 right 2
"left rightresponse incompatible 2" -200 right 2
task simon
set &number_of_trials increase
table simontasktable
keys a l
draw off
show text "Percentage correct:" -200 -200
show text &task_perc_correct 0 -200
show text "Trial number:" -200 -150
show text &number_of_trials 0 -150
show text "Mean RT:" -200 -100
show text &mean_rt 0 -100
draw on
delay 300
show bitmap fix
delay 300
show bitmap @3 @2 0
readkey @4 5000
clear -1 -2
if STATUS == CORRECT
set &correct_count increase
set &sum_rt increase RT (1)
set &mean_rt expression &sum_rt / &correct_count
fi
set &task_perc_correct expression ( &correct_count / &number_of_trials ) * 100
draw off
clear 2 6
show text &task_perc_correct 0 -200
show text &mean_rt 0 -100
draw on
if STATUS != CORRECT
show bitmap mistake
delay 1000
clear -1
fi
if &number_of_trials > 19 && &task_perc_correct >= 95 && &mean_rt < 1000 (2)
end tasklist (3)
fi
delay 500
save BLOCKNAME @1 STATUS RT
block test
message intro
tasklist
simon 100 ## run task up to maximally 100 trials
end
1 | In addition to keep track of numbers correct, we also keep track of the average RT using global variables |
2 | We check if the criterion has been reached. Note that this if asks for 3 different things to check. |
3 | If criterion has been reached, finish tasklist (i.e., block) |
Example code 3 — running until percentage correct in each condition has been reached
In this example, the block runs until the following two conditions have been satisfied:
1) The participant has done at least 20 trials 2) The participant performs at 95% correct or better in each condition
Example 3 is just an extension of Example 1. Now we keep track of the numbers of trials in each condition.
First run the example below to see what happens. The actual performance level is presented on screen while doing the task.
And here is the explanation.
bitmaps
intro
left
right
fix
mistake
fonts
arial 18
table simontasktable # table with four rows, each trial one row is randomly chosen
#-name of condition--------------position--stimulus--response
"left leftresponse compatible 1" -200 left 1
"right leftresponse incompatible 2" 200 left 1
"right rightresponse compatible 1" 200 right 2
"left rightresponse incompatible 2" -200 right 2
task simon
table simontasktable
keys a l
set &number_of_trials increase
if TABLEROW == 1 (1)
set &number_of_trials_c1 increase
fi
if TABLEROW == 2
set &number_of_trials_c2 increase
fi
if TABLEROW == 3
set &number_of_trials_c3 increase
fi
if TABLEROW == 4
set &number_of_trials_c4 increase
fi
text align left
draw off
show text "Percentage correct in each condition:" -390 -200
show text &task_perc_correct_c1 50 -200
show text &task_perc_correct_c2 100 -200
show text &task_perc_correct_c3 150 -200
show text &task_perc_correct_c4 200 -200
show text "Trial number in each condition:" -390 -150
show text &number_of_trials_c1 50 -150
show text &number_of_trials_c2 100 -150
show text &number_of_trials_c3 150 -150
show text &number_of_trials_c4 200 -150
draw on
delay 300
show bitmap fix
delay 300
show bitmap @3 @2 0
readkey @4 5000
clear -1 -2
if STATUS == CORRECT
if TABLEROW == 1
set &correct_count_c1 increase
set &task_perc_correct_c1 expression ( &correct_count_c1 / &number_of_trials_c1 ) * 100
fi
if TABLEROW == 2
set &correct_count_c2 increase
set &task_perc_correct_c2 expression ( &correct_count_c2 / &number_of_trials_c2 ) * 100
fi
if TABLEROW == 3
set &correct_count_c3 increase
set &task_perc_correct_c3 expression ( &correct_count_c3 / &number_of_trials_c3 ) * 100
fi
if TABLEROW == 4
set &correct_count_c4 increase
set &task_perc_correct_c4 expression ( &correct_count_c4 / &number_of_trials_c4 ) * 100
fi
fi
draw off
clear 2 3 4 5
show text "Percentage correct in each condition:" -390 -200
show text &task_perc_correct_c1 50 -200
show text &task_perc_correct_c2 100 -200
show text &task_perc_correct_c3 150 -200
show text &task_perc_correct_c4 200 -200
draw on
if STATUS != CORRECT
show bitmap mistake
delay 1000
clear -1
fi
if &number_of_trials > 19 && &task_perc_correct_c1 >= 95 && &task_perc_correct_c2 >= 95 && &task_perc_correct_c3 >= 95 && &task_perc_correct_c4 >= 95
end tasklist
fi
delay 500
save BLOCKNAME @1 STATUS RT
block test
message intro
tasklist
simon 100 ## run task up to maximally 100 trials
end
1 | The TABLEROW is the table row chosen from the table with the 4 conditions. Thus, when TABLEROW is 1, it means the computer has currently chosen the first row of the table. The standard way of doing things is that PsyToolkit randomly choses a row, although this can be changed as well (read hear how to). |