-
Notifications
You must be signed in to change notification settings - Fork 3
/
experiment.js
278 lines (259 loc) · 8.32 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
/* ************************************ */
/* 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 getChar = function() {
return '<div class = centerbox><p class = AX_text>' + chars[Math.floor(Math.random() * 22)] +
'</p></div>'
}
var getInstructFeedback = function() {
return '<div class = centerbox><p class = center-block-text>' + feedback_instruct_text +
'</p></div>'
}
/* ************************************ */
/* Define experimental variables */
/* ************************************ */
// generic task variables
var sumInstructTime = 0 //ms
var instructTimeThresh = 0 ///in seconds
// task specific variables
var possible_responses = [
["M key", 77],
["Z key", 90]
]
var chars = 'BCDEFGHIJLMNOPQRSTUVWZ'
var trial_proportions = ["AX", "AX", "AX", "AX", "AX", "AX", "AX", "BX", "AY", "BY"]
var block1_list = jsPsych.randomization.repeat(trial_proportions, 4)
var block2_list = jsPsych.randomization.repeat(trial_proportions, 4)
var block3_list = jsPsych.randomization.repeat(trial_proportions, 4)
var blocks = [block1_list, block2_list, block3_list]
/* ************************************ */
/* 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]
};
// generic task variables
var run_attention_checks = false
var attention_check_thresh = 0.65
// task specific variables
/* define static blocks */
var end_block = {
type: 'poldrack-text',
timing_response: 180000,
data: {
exp_id: "ax_cpt",
trial_id: "end"
},
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 feedback_instruct_text =
'Welcome to the experiment. Press <strong>enter</strong> to begin.'
var feedback_instruct_block = {
type: 'poldrack-text',
cont_key: [13],
text: getInstructFeedback,
data: {
trial_id: 'instruction'
},
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',
pages: [
'<div class = centerbox><p class = block-text>In this task, on each trial you will see a letter presented for a short time, followed by the presentation of another letter. For instance you may see "A", which would then disappear to be replaced by "F".</p><p class = block-text>Your job is to respond by pressing an arrow key during the presentation of the <strong>second</strong> letter. If the first letter was an "A" <strong>AND</strong> the second letter was an "X", press the ' +
possible_responses[0][0] + '. Otherwise press the ' + possible_responses[1][0] +
'.</p></div>',
'<div class = centerbox><p class = block-text>We will now start the experiment. Remember, press the left arrow key after you see "A" followed by an "X", and the down arrow key for all other combinations.</p></div>'
],
allow_keys: false,
data: {
exp_id: "ax_cpt",
trial_id: 'instruction'
},
show_clickable_nav: true,
timing_post_trial: 01000
};
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 rest_block = {
type: 'poldrack-text',
timing_response: 180000,
data: {
trial_id: "rest"
},
text: '<div class = centerbox><p class = block-text>Take a break! Press any key to continue.</p></div>',
timing_post_trial: 1000
};
var wait_block = {
type: 'poldrack-single-stim',
stimulus: '<div class = centerbox><div class = AX_feedback>Trial over, get ready for the next one.</div></div>',
is_html: true,
choices: 'none',
data: {
trial_id: "wait"
},
timing_post_trial: 500,
timing_stim: 1000,
timing_response: 1000
}
/* define test block cues and probes*/
var A_cue = {
type: 'poldrack-single-stim',
stimulus: '<div class = centerbox><div class = AX_text>A</div></div>',
is_html: true,
choices: 'none',
data: {
trial_id: "cue",
exp_stage: "test"
},
timing_stim: 300,
timing_response: 5200,
response_ends_trial: false,
timing_post_trial: 0
};
var other_cue = {
type: 'poldrack-single-stim',
stimulus: getChar,
is_html: true,
choices: 'none',
data: {
trial_id: "cue",
exp_stage: "test"
},
timing_stim: 300,
timing_response: 5200,
response_ends_trial: false,
timing_post_trial: 0
};
var X_probe = {
type: 'poldrack-single-stim',
stimulus: '<div class = centerbox><div class = AX_text>X</div></div>',
is_html: true,
choices: [possible_responses[0][1], possible_responses[1][1]],
data: {
trial_id: "probe",
exp_stage: "test"
},
timing_stim: 300,
timing_response: 1300,
response_ends_trial: false,
timing_post_trial: 0
};
var other_probe = {
type: 'poldrack-single-stim',
stimulus: getChar,
is_html: true,
choices: [possible_responses[0][1], possible_responses[1][1]],
data: {
trial_id: "probe",
exp_stage: "test"
},
timing_stim: 300,
timing_response: 1300,
response_ends_trial: false,
timing_post_trial: 0
};
/* ************************************ */
/* Set up experiment */
/* ************************************ */
var ax_cpt_experiment = []
ax_cpt_experiment.push(instruction_node);
for (b = 0; b < blocks.length; b++) {
var block = blocks[b]
for (i = 0; i < block.length; i++) {
switch (block[i]) {
case "AX":
cue = jQuery.extend(true, {}, A_cue)
probe = jQuery.extend(true, {}, X_probe)
cue.data.condition = "AX"
probe.data.condition = "AX"
break;
case "BX":
cue = jQuery.extend(true, {}, other_cue)
probe = jQuery.extend(true, {}, X_probe)
cue.data.condition = "BX"
probe.data.condition = "BX"
break;
case "AY":
cue = jQuery.extend(true, {}, A_cue)
probe = jQuery.extend(true, {}, other_probe)
cue.data.condition = "AY"
probe.data.condition = "AY"
break;
case "BY":
cue = jQuery.extend(true, {}, other_cue)
probe = jQuery.extend(true, {}, other_probe)
cue.data.condition = "BY"
probe.data.condition = "BY"
break;
}
ax_cpt_experiment.push(cue)
ax_cpt_experiment.push(probe)
ax_cpt_experiment.push(wait_block)
}
ax_cpt_experiment.push(attention_node)
ax_cpt_experiment.push(rest_block)
}
ax_cpt_experiment.push(post_task_block)
ax_cpt_experiment.push(end_block)