-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathdigit_span_task.html
237 lines (211 loc) · 8.94 KB
/
digit_span_task.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<html>
<head>
<title>WM Digit Span</title>
<script src="jspsych-6.0.4/jspsych.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-digit-span-recall.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-survey-text.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-instructions.js"></script>
<script src="jspsych-6.0.4/plugins/jspsych-fullscreen.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jstat@latest/dist/jstat.min.js"></script>
<link href="jspsych-6.0.4/css/jspsych_digitspan.css" rel="stylesheet" type="text/css"></link>
</head>
<body></body>
<script>
/*
This is a web-based digit span working memory test.
It is modelled after the forward digit span test described in Woods et al (2011) [https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2978794/].
However, users can easily customize this test for their own purposes.
Easily customizable variables have been listed below. For further changes to the test, knowledge of JavaScipt may be required.
For smooth functioning of the test, make sure all the associated github files within the repository have been downloaded (especially the folder named 'jspsych-6.0.4').
Results from this test will be automatically downloaded into the downloads folder of your desktop.
For further details, please refer to the README.
*/
//----- CUSTOMIZABLE VARIABLES -----------------------------------------
nTrials = 14 // number of trials in the test
minSetSize = 3 // starting digit length
stimuli_duration = 1000 // number of miliseconds to display each digit
recall_duration = null // number of miliseconds to allow recall. If null, there is no time limit.
file_name = null // file name for data file. if null, a default name consisting of the participant ID and a unique number is chosen.
local = true // save the data file locally.
// If this test is being run online (e.g., on MTurk), true will cause the file to be downloaded to the participant's computer.
// If this test is on a server, and you wish to save the data file to that server, change this to false.
// If changed to false, ensure that the php file (its in the directory!) and the empty "data" folder has also been appropriately uploaded to the server.
// Incase of problems, feel free to contact me :)
//----------------------------------------------------------------------
possibleNumbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] //possible digits participants can get
var selection = jsPsych.randomization.sampleWithoutReplacement(possibleNumbers, minSetSize) //chooses random digits
var selection_id = -1
// keeps track of participant's scores:
var nError = 0
var highest_span_score = 0
var consec_error_score = 0
// first page. identifies participant for data storage
var p_details = {
type:"survey-text",
questions: [{prompt: "Enter participant number, name, or ID"}],
on_finish:function(){
partN = jsPsych.data.get().last(1).values()[0].partNum
partN = partN.replace(/['"]+/g,'')
// console.log(partN[0])
}
}
// instruction page
var instructions = {
type: 'instructions',
pages: function(){
pageOne = "<div style='font-size:20px;'><b>INSTRUCTIONS</b><br><br>This is the digit span task.<br><br>In this task, you will have to remember a sequence of numbers presented on the screen one after the other.<br>At the end of each trial, enter all the numbers into the onscreen number-pad in their correct order.<br><br><u>Example:</u> if the sequence is '7 4 5 1', enter '7 4 5 1' in this exact order.<br><br>You will now be given practice trials to help you understand the task.<br>Press 'Next' to start the practice trials.<br><br></div>"
return [pageOne]
},
allow_backward: false,
button_label_next: "Next",
show_clickable_nav: true
}
var instructions_node = {
type: 'instructions',
pages: function(){
pageOne = "<div style='font-size:20px;'>You have completed the practice trials. <br><br> If you have further questions about the task, ask the researcher now.<br> If you are clear about the task, click 'Next' to proceed to the main trials.<br><br></div>"
return [pageOne]
},
allow_backward: false,
button_label_next: "Next",
show_clickable_nav: true,
on_finish: function(){
minSetSize = 3
selection = jsPsych.randomization.sampleWithoutReplacement(possibleNumbers, minSetSize)
}
}
var test_stimuli = {
type: 'html-keyboard-response',
stimulus: function(){
selection_id+=1
return '<div style="font-size:70px;">'+selection[selection_id]+'</div>'
},
choices: jsPsych.NO_KEYS,
trial_duration: stimuli_duration,
on_finish: function(){
if (selection_id + 1 >=selection.length){
jsPsych.endCurrentTimeline()
}
}
}
var recall = {
type: 'digit-span-recall',
correct_order: function(){
return selection
},
trial_duration: recall_duration,
on_finish: function(){
acc = jsPsych.data.get().last(1).values()[0].accuracy;
if (acc==1){
if (highest_span_score < minSetSize){
highest_span_score = minSetSize
}
minSetSize+=1
nError = 0
} else if (nError < 1) { // checks for number of consecutive errors
nError += 1
} else {
if (consec_error_score < minSetSize){
consec_error_score = minSetSize
}
minSetSize = Math.max( 3, minSetSize-1)
}
if (minSetSize<=8){ // bottom code prevents immediate repition of digits
selection = jsPsych.randomization.sampleWithoutReplacement(possibleNumbers, minSetSize)
} else {
selection = jsPsych.randomization.sampleWithoutReplacement(possibleNumbers, 8)
var extra = minSetSize-8
var id = possibleNumbers.indexOf(selection[7])
possibleNumbers.splice(id, 1);
var extraNumbers= jsPsych.randomization.sampleWithoutReplacement(possibleNumbers, extra)
selection = selection.concat(extraNumbers)
possibleNumbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
}
selection_id = -1
}
}
var feedback = {
type: 'html-keyboard-response',
stimulus: function(){
var text = ""
var accuracy = jsPsych.data.get().last(1).values()[0].accuracy
if (accuracy==1){
text += '<div style="font-size:35px; color:rgb(0 220 0)"><b>Correct</div>'
} else {
text += '<div style="font-size:35px; color:rgb(240 0 0)"><b>Incorrect</div>'
}
//text += '<div style="font-size:30px; color:rgb(0 0 0)"><br><br>New trial starting now.</div>'
return text
},
choices: jsPsych.NO_KEYS,
trial_duration: 1000
}
var conclusion = {
type: 'html-keyboard-response',
stimulus: function(){
return '<div style="font-size:20px;">You have completed the task.<br>Thank you for your participation in this task.<br><br>Maximum number of digits recalled correctly was ' + highest_span_score +'.<br><br>Maximum number of digits reached before making two consecutive errors was ' +consec_error_score+'.<br><br>Please tell the Research Assistant you have completed the task.</div>'
},
choices: jsPsych.NO_KEYS
// trial_duration:1000
}
var test_stack = {
timeline: [test_stimuli],
repetitions: 17
}
var test_procedure = {
timeline: [test_stack, recall, feedback],
repetitions: nTrials
}
var demo_procedure = {
timeline: [test_stack, recall, feedback],
repetitions: 3
}
function saveData(filename, filedata){
$.ajax({
type:'post',
cache: false,
url: 'save_data.php', // this is the path to the above PHP script
data: {filename: filename, filedata: filedata}
});
};
var IDsub = Date.now()
var dataLog = {
type: 'html-keyboard-response',
stimulus: " ",
trial_duration: 100,
on_finish: function(data) {
var data = jsPsych.data.get().filter({trial_type: 'digit-span-recall'});
if (file_name == null){
file_name = "WM_digit_span_"+partN+"_"+IDsub.toString()+".csv"}
else{
file_name += ".csv"
}
if (local){
data.localSave('csv', file_name )
} else {
saveData(file_name, data.csv());
}
}
}
timeline = [p_details]
timeline.push({
type: 'fullscreen',
fullscreen_mode: true
});
timeline = timeline.concat([instructions, demo_procedure, instructions_node, test_procedure])
timeline.push({
type: 'fullscreen',
fullscreen_mode: false
});
timeline.push(dataLog)
timeline.push(conclusion)
jsPsych.init({
timeline: timeline,
on_finish: function() {
jsPsych.data.displayData(); // comment out if you do not want to display results at the end of task
}
});
</script>
</html>