-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment.js
405 lines (381 loc) · 13.7 KB
/
experiment.js
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/* ************************************ */
/* Define helper functions */
/* ************************************ */
function evalAttentionChecks() {
var check_percent = 1
if (run_attention_checks) {
var attention_check_trials = jsPsych.data.getTrialsOfType('attention-check')
var checks_passed = 0
for (var i = 0; i < attention_check_trials.length; i++) {
if (attention_check_trials[i].correct === true) {
checks_passed += 1
}
}
check_percent = checks_passed / attention_check_trials.length
}
return check_percent
}
var randomDraw = function(lst) {
var index = Math.floor(Math.random() * (lst.length))
return lst[index]
}
var getInstructFeedback = function() {
return '<div class = centerbox><p class = center-block-text>' + feedback_instruct_text +
'</p></div>'
}
/* ************************************ */
/* Define experimental variables */
/* ************************************ */
// generic task variables
var run_attention_checks = false
var attention_check_thresh = 0.65
var sumInstructTime = 0 //ms
var instructTimeThresh = 0 ///in seconds
// task specific variables
var categories = ['animals', 'colors', 'countries', 'distances', 'metals', 'relatives']
var exemplars = {
'animals': ['fish', 'bird', 'snake', 'cow', 'whale'],
'colors': ['red', 'yellow', 'green', 'blue', 'brown'],
'countries': ['China', 'US', 'England', 'India', 'Brazil'],
'distances': ['mile', 'kilometer', 'meter', 'foot', 'inch'],
'metals': ['iron', 'titanium', 'aluminum', 'lead', 'brass'],
'relatives': ['mother', 'father', 'brother', 'sister', 'aunt']
}
var difficulty_order = jsPsych.randomization.shuffle([3, 4, 5])
var num_blocks = 3 //per difficulty level
var blocks = []
var targets = []
var practice_block = []
var practice_targets = []
var last_targets = {}
/* Draw 2 or 3 exemplars from each of six categories totalling 15 exemplars for each block. Start
with a practice block (difficulty = 3). Then present 3 test blocks for each difficulty level, where each difficulty level has a different number
of target categories (randomly drawn)
*/
var target_categories = jsPsych.randomization.repeat(categories, 1, false).slice(0, 3) //select the target categories
var block_exemplars = []
var cat_repeats = jsPsych.randomization.repeat([2, 2, 2, 3, 3, 3], 1, false) //determines how many exemplars from each category to select for this block
for (var cat = 0; cat < categories.length; cat++) {
var exemplars_to_add = jsPsych.randomization.repeat(exemplars[categories[cat]], 1, false).slice(0,
cat_repeats[cat])
var items = []
exemplars_to_add.forEach(function(entry) {
items.push([categories[cat]].concat(entry))
})
block_exemplars = block_exemplars.concat(items)
}
practice_block.push(jsPsych.randomization.repeat(block_exemplars, 1, false))
practice_targets.push(target_categories)
for (var i = 0; i < difficulty_order.length; i++) {
for (var b = 0; b < num_blocks; b++) {
var target_categories = jsPsych.randomization.repeat(categories, 1, false).slice(0,
difficulty_order[i]) //select the target categories
var block_exemplars = []
var cat_repeats = jsPsych.randomization.repeat([2, 2, 2, 3, 3, 3], 1, false) //determines how many exemplars from each category to select for this block
for (var cat = 0; cat < categories.length; cat++) {
var exemplars_to_add = jsPsych.randomization.repeat(exemplars[categories[cat]], 1, false).slice(
0, cat_repeats[cat])
var items = []
exemplars_to_add.forEach(function(entry) {
items.push([categories[cat]].concat(entry))
})
block_exemplars = block_exemplars.concat(items)
}
blocks.push(jsPsych.randomization.repeat(block_exemplars, 1, false))
targets.push(target_categories)
}
}
/* ************************************ */
/* Set up jsPsych blocks */
/* ************************************ */
// Set up attention check node
var attention_check_block = {
type: 'attention-check',
data: {
trial_id: 'attention_check'
},
timing_response: 180000,
response_ends_trial: true,
timing_post_trial: 200
}
var attention_node = {
timeline: [attention_check_block],
conditional_function: function() {
return run_attention_checks
}
}
//Set up post task questionnaire
var post_task_block = {
type: 'survey-text',
data: {
trial_id: "post task questions"
},
questions: ['<p class = center-block-text style = "font-size: 20px">Please summarize what you were asked to do in this task.</p>',
'<p class = center-block-text style = "font-size: 20px">Do you have any comments about this task?</p>'],
rows: [15, 15],
columns: [60,60]
};
/* define static blocks */
var category_instructions = '<ul class = list-text>' +
'<li><strong>animals</strong>: fish, bird, snake, cow, whale</li>' +
'<li><strong>colors</strong>: red, yellow, green, blue, brown</li>' +
'<li><strong>countries</strong>: China, US, England, India, Brazil</li>' +
'<li><strong>distances</strong>: mile, kilometer, meter, foot, inch</li>' +
'<li><strong>metals</strong>: iron, titanium, aluminum, lead, brass</li>' +
'<li><strong>relatives</strong>: mother, father, brother, sister, aunt</li>'
var feedback_instruct_text =
'Welcome to the experiment. This expeirment will take around 6 minutes. Press <strong>enter</strong> to begin.'
var feedback_instruct_block = {
type: 'poldrack-text',
cont_key: [13],
data: {
trial_id: 'instruction'
},
text: getInstructFeedback,
timing_post_trial: 0,
timing_response: 180000
};
/// This ensures that the subject does not read through the instructions too quickly. If they do it too quickly, then we will go over the loop again.
var instructions_block = {
type: 'poldrack-instructions',
data: {
trial_id: 'instruction'
},
pages: [
'<div class = centerbox><p class = block-text>In this experiment you will see a sequence of words presented one at time. These words will fall into one of six cateogries: animals, colors, countries, distances, metals and relatives.</p><p class = block-text>3 to 5 of these categories will be "target" categories presented on the screen. Your goal is to remember the <strong>last</strong> word shown from each of the target categories and type them at the end of the trial.</p></div>',
'<div class = centerbox><p class = block-text>To make sure there is no confusion about which word is in each category, the words in each category are presented below: ' +
category_instructions +
'</p><p class = block-text>Make sure you know which category each word belongs to.</p></div>',
'<div class = centerbox><p class = block-text>To summarize, a trial will start by presenting you with 3-5 target categories (e.g. "colors, animals, relatives"). You will then see a sequence of words from all six categories, one after the other.</p><p class = block-text>For instance, a trial may end with: "... dog"... "aunt"... "China"... "red"... "titanium"... "bird". You have to remember the last word in each of the target categories, which you will write down at the end of the trial.</p><p class = block-text>For the example sequence with the previously mentioned targets, you would respond "red, aunt, bird" as those were the last colors, relatives, and animals, respectively. The order that you write the categories down does not matter.</p><p class = block-text>After you end instructions you will complete a practice block of trials.</p></div>',
],
allow_keys: false,
show_clickable_nav: true,
timing_post_trial: 1000
};
var instruction_node = {
timeline: [feedback_instruct_block, instructions_block],
/* This function defines stopping criteria */
loop_function: function(data) {
for (i = 0; i < data.length; i++) {
if ((data[i].trial_type == 'poldrack-instructions') && (data[i].rt != -1)) {
rt = data[i].rt
sumInstructTime = sumInstructTime + rt
}
}
if (sumInstructTime <= instructTimeThresh * 1000) {
feedback_instruct_text =
'Read through instructions too quickly. Please take your time and make sure you understand the instructions. Press <strong>enter</strong> to continue.'
return true
} else if (sumInstructTime > instructTimeThresh * 1000) {
feedback_instruct_text = 'Done with instructions. Press <strong>enter</strong> to continue.'
return false
}
}
}
var end_block = {
type: 'poldrack-text',
timing_response: 180000,
data: {
trial_id: 'end',
exp_id: 'keep_track'
},
text: '<div class = centerbox><p class = center-block-text>Thanks for completing this task!</p><p class = center-block-text>Press <strong>enter</strong> to continue.</p></div>',
cont_key: [13],
timing_post_trial: 0
};
var end_practice_block = {
type: 'poldrack-text',
timing_response: 180000,
data: {
trial_id: 'practice_end'
},
text: '<div class = centerbox><p class = center-block-text>Finished with practice block. You will now complete 9 test blocks.</p><p class = center-block-text>Press <strong>enter</strong> to begin.</p></div>',
cont_key: [13],
timing_post_trial: 1000
};
var start_test_block = {
type: 'poldrack-text',
timing_response: 180000,
data: {
trial_id: 'test_intro'
},
text: '<div class = centerbox><p class = center-block-text>Starting a test block.</p><p class = center-block-text>Press <strong>enter</strong> to begin.</p></div>',
cont_key: [13],
timing_post_trial: 1000,
on_finish: function() {
last_targets = {}
}
};
//Set up experiment
var keep_track_experiment = []
keep_track_experiment.push(instruction_node);
// set up practice
block = practice_block[0]
target = practice_targets[0]
prompt = '<div class = promptbox><div class = prompt-text>Targets: ' + target.join(', ') +
'</div></div>'
data = {
trial_id: 'prompt',
exp_stage: "practice",
load: target.length,
targets: target
}
var prompt_block = {
type: 'poldrack-single-stim',
stimulus: '<div class = centerbox><p class = block-text>Below are the target categories. They will remain on the bottom of the screen during the trial. Press enter when you are sure you can remember them. </p></div>',
is_html: true,
choices: [13],
response_ends_trial: true,
data: data,
prompt: prompt,
timing_post_trial: 1000,
}
var wait_block = {
type: 'poldrack-single-stim',
stimulus: ' ',
is_html: true,
data: {
trial_id: 'wait',
exp_stage: 'practice'
},
choices: 'none',
prompt: prompt,
timing_stim: 500,
timing_response: 500,
timing_post_trial: 0,
}
keep_track_experiment.push(prompt_block)
keep_track_experiment.push(wait_block)
// set up practice blocks
for (i = 0; i < block.length; i++) {
stim = '<div class = centerbox><div class = keep-track-text>' + block[i][1] + '</div></div>'
data = {
trial_id: 'stim',
category: block[i][0],
exp_stage: "practice",
load: target.length,
targets: target,
stim: block[i][1]
}
var track_block = {
type: 'poldrack-single-stim',
stimulus: stim,
is_html: true,
choices: 'none',
data: data,
timing_response: 1500,
timing_stim: 1500,
prompt: prompt,
timing_post_trial: 0,
on_finish: function(data) {
if ($.inArray(data.category, data.targets) != -1) {
last_targets[data.category] = data.stim
}
}
}
keep_track_experiment.push(track_block)
}
var response_block = {
type: 'survey-text',
questions: [['<p class = center-block-text>What was the last word in each of the target categories? Please separate your words with a space</p>']
],
data: {
trial_id: 'response',
exp_stage: "practice",
load: target.length,
targets: target
},
on_finish: function() {
jsPsych.data.addDataToLastTrial({'correct_responses': last_targets})
}
}
keep_track_experiment.push(response_block)
keep_track_experiment.push(attention_node)
keep_track_experiment.push(end_practice_block)
// set up test blocks
for (b = 0; b < blocks.length; b++) {
keep_track_experiment.push(start_test_block)
block = blocks[b]
target = targets[b]
prompt = '<div class = promptbox><div class = prompt-text>Targets: ' + target.join(', ') +
'</div></div>'
data = {
trial_id: 'prompt',
exp_stage: "test",
load: target.length,
targets: target
}
var prompt_block = {
type: 'poldrack-single-stim',
stimulus: '<div class = centerbox><p class = block-text>Below are the target categories. They will remain on the bottom of the screen during the trial. Press enter when you are sure you can remember them. </p></div>',
is_html: true,
choices: [13],
data: data,
prompt: prompt,
timing_post_trial: 1000,
response_ends_trial: true
}
var wait_block = {
type: 'poldrack-single-stim',
stimulus: ' ',
is_html: true,
choices: 'none',
data: {
trial_id: 'wait',
exp_stage: 'test'
},
prompt: prompt,
timing_stim: 500,
timing_response: 500,
timing_post_trial: 0,
}
keep_track_experiment.push(prompt_block)
keep_track_experiment.push(wait_block)
for (i = 0; i < block.length; i++) {
stim = '<div class = centerbox><div class = keep-track-text>' + block[i][1]+ '</div></div>'
data = {
trial_id: 'stim',
category: block[i][0],
exp_stage: "test",
load: target.length,
targets: target,
stim: block[i][1]
}
var track_block = {
type: 'poldrack-single-stim',
stimulus: stim,
is_html: true,
choices: 'none',
data: data,
timing_response: 1500,
timing_stim: 1500,
prompt: prompt,
timing_post_trial: 0,
on_finish: function(data) {
if ($.inArray(data.category, data.targets) != -1) {
last_targets[data.category] = data.stim
}
}
}
keep_track_experiment.push(track_block)
}
var response_block = {
type: 'survey-text',
questions: [['<p class = center-block-text>What was the last word in each of the target categories? Please separate your words with a space</p>']],
data: {
trial_id: 'response',
exp_stage: 'test',
load: target.length,
targets: target
},
on_finish: function() {
jsPsych.data.addDataToLastTrial({'correct_responses': last_targets})
}
}
keep_track_experiment.push(response_block)
if ($.inArray(b, [0, 2]) != -1) {
keep_track_experiment.push(attention_node)
}
}
keep_track_experiment.push(post_task_block)
keep_track_experiment.push(end_block)