-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexical-task.html
358 lines (330 loc) · 10.2 KB
/
lexical-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
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
<!DOCTYPE html>
<html>
<head>
<title>Lexical Decision Task</title>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<script src="https://unpkg.com/@jspsych/[email protected]"></script>
<link
href="https://unpkg.com/[email protected]/css/jspsych.css"
rel="stylesheet"
type="text/css" />
</head>
<body></body>
<script>
/** High level description/sanity check:
* Test if syntacticaly similarity/familiarity of words makes it harder to differentiate them,
* or if it makes participant more vigilant about their differences
*
* Input: 4 categories
* - 10 randomly generated real + common words (repeated once)
* - 10 randomly generated real + rare words (repeated once)
* - 10 Phonetically sound non-words that look and sound a lot like each of the real + common words
* - 10 Phonetically sound non-words that look and sound a lot like each of the real + rare words
* - 10 Scrambled versions of the real + common words (not phonentically sound)
* - 10 Scrambled versions of the real + rare words (not phonentically sound)
* - 10 Jibberish
* Randomize all of them and have participant choose between f for word and j for non-word
*
* Data collection:
* - Whether each decision was correct
* - Reaction time
/* initialize jsPsych */
var jsPsych = initJsPsych({
on_finish: function () {
jsPsych.data.displayData();
},
});
/* global vars */
var timeline = [];
var trial_number = 1;
/* helper functions */
function wordScramble(word) {
var wordArray = word.split(""),
n = wordArray.length;
for (var i = n - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var tmp = wordArray[i];
wordArray[i] = wordArray[j];
wordArray[j] = tmp;
}
if (wordArray.join("") === word) {
wordScramble(word);
} else {
return wordArray.join("");
}
}
function wordArrayScramble(array) {
for (var i = 0; i < array.length; i++) {
array[i] = wordScramble(array[i]);
}
return array;
}
function commonScrambleStimuliGen(word_list) {
var arr = [];
wordArrayScramble(word_list);
for (var i = 0; i < 10; i++) {
arr[i] = {
stimulus: word_list[i],
correct_response: "j",
stimulus_type: "common_scramble",
};
}
return arr;
}
function rareScrambleStimuliGen(word_list) {
var arr = [];
wordArrayScramble(word_list);
for (var i = 0; i < 10; i++) {
arr[i] = {
stimulus: word_list[i],
correct_response: "j",
stimulus_type: "rare_scramble",
};
}
return arr;
}
//ok this could generate a valid word whoops
function jibberishGen() {
var jibLength = Math.floor(Math.random() * 8 + 4);
var wordArray = [];
for (var i = 0; i < jibLength; i++) {
wordArray[i] = String.fromCharCode(Math.floor(Math.random() * 26 + 97));
}
return wordArray.join("");
}
function jibArrayGen(num) {
jibArray = [];
for (var i = 0; i < num; i++) {
jibArray[i] = {
stimulus: jibberishGen(),
correct_response: "j",
stimulus_type: "jibberish",
};
}
return jibArray;
}
//but why doesn't concat work...
function arrConcat(ogArr, newArr) {
for (var i = 0; i < newArr.length; i++) {
ogArr.push(newArr[i]);
}
}
/* define trial stimuli array for timeline variables */
var common_word_list = [
"depend",
"winner",
"drink",
"tight",
"sofa",
"torn",
"neutral",
"drag",
"plot",
"disorder",
];
var rare_word_list = [
"comedogenic",
"retrophilia",
"poultice",
"motley",
"aperture",
"xylem",
"sophomorous",
"palladium",
"soliloquy",
"rhubarb",
];
var common_word_10 = [
{stimulus: "depend", correct_response: "f", stimulus_type: "common_real"},
{stimulus: "winner", correct_response: "f", stimulus_type: "common_real"},
{stimulus: "drink", correct_response: "f", stimulus_type: "common_real"},
{stimulus: "tight", correct_response: "f", stimulus_type: "common_real"},
{stimulus: "sofa", correct_response: "f", stimulus_type: "common_real"},
{stimulus: "torn", correct_response: "f", stimulus_type: "common_real"},
{
stimulus: "neutral",
correct_response: "f",
stimulus_type: "common_real",
},
{stimulus: "drag", correct_response: "f", stimulus_type: "common_real"},
{stimulus: "plot", correct_response: "f", stimulus_type: "common_real"},
{
stimulus: "disorder",
correct_response: "f",
stimulus_type: "common_real",
},
];
var rare_word_10 = [
{
stimulus: "comedogenic",
correct_response: "f",
stimulus_type: "rare_real",
},
{
stimulus: "retrophilia",
correct_response: "f",
stimulus_type: "rare_real",
},
{stimulus: "poultice", correct_response: "f", stimulus_type: "rare_real"},
{stimulus: "motley", correct_response: "f", stimulus_type: "rare_real"},
{stimulus: "aperture", correct_response: "f", stimulus_type: "rare_real"},
{stimulus: "xylem", correct_response: "f", stimulus_type: "rare_real"},
{
stimulus: "sophomorous",
correct_response: "f",
stimulus_type: "rare_real",
},
{
stimulus: "palladium",
correct_response: "f",
stimulus_type: "rare_real",
},
{
stimulus: "soliloquy",
correct_response: "f",
stimulus_type: "rare_real",
},
{stimulus: "rhubarb", correct_response: "f", stimulus_type: "rare_real"},
];
var common_word_dupe_10 = [
{stimulus: "pedenp", correct_response: "j", stimulus_type: "common_dupe"},
{stimulus: "wanner", correct_response: "j", stimulus_type: "common_dupe"},
{stimulus: "frink", correct_response: "j", stimulus_type: "common_dupe"},
{stimulus: "tigher", correct_response: "j", stimulus_type: "common_dupe"},
{stimulus: "siba", correct_response: "j", stimulus_type: "common_dupe"},
{stimulus: "thern", correct_response: "j", stimulus_type: "common_dupe"},
{
stimulus: "nuetral",
correct_response: "j",
stimulus_type: "common_dupe",
},
{stimulus: "drep", correct_response: "j", stimulus_type: "common_dupe"},
{stimulus: "floch", correct_response: "j", stimulus_type: "common_dupe"},
{
stimulus: "disorrdir",
correct_response: "j",
stimulus_type: "common_dupe",
},
];
var rare_word_dupe_10 = [
{
stimulus: "comadogenic",
correct_response: "j",
stimulus_type: "rare_dupe",
},
{
stimulus: "letterobilia",
correct_response: "j",
stimulus_type: "rare_dupe",
},
{stimulus: "poletish", correct_response: "j", stimulus_type: "rare_dupe"},
{stimulus: "cotley", correct_response: "j", stimulus_type: "rare_dupe"},
{
stimulus: "apercunture",
correct_response: "j",
stimulus_type: "rare_dupe",
},
{stimulus: "milex", correct_response: "j", stimulus_type: "rare_dupe"},
{
stimulus: "sapromorous",
correct_response: "j",
stimulus_type: "rare_dupe",
},
{
stimulus: "paradeium",
correct_response: "j",
stimulus_type: "rare_dupe",
},
{stimulus: "sorolite", correct_response: "j", stimulus_type: "rare_dupe"},
{stimulus: "bluerab", correct_response: "j", stimulus_type: "rare_dupe"},
];
var common_scramble_10 = commonScrambleStimuliGen(common_word_list);
var rare_scramble_10 = rareScrambleStimuliGen(rare_word_list);
var jibberish_10 = jibArrayGen(10);
var finalArray = [];
arrConcat(finalArray, common_word_10);
arrConcat(finalArray, common_word_10);
arrConcat(finalArray, rare_word_10);
arrConcat(finalArray, rare_word_10);
//after test trial found out it's really hard if there's a disproportionate amount of non-words
//so concat real word arrays twice each to balance out
arrConcat(finalArray, common_word_dupe_10);
arrConcat(finalArray, rare_word_dupe_10);
arrConcat(finalArray, common_scramble_10);
arrConcat(finalArray, rare_scramble_10);
arrConcat(finalArray, jibberish_10);
/* test stimuli */
var test_stimuli = finalArray;
/* welcome message trial */
var welcome = {
type: jsPsychHtmlKeyboardResponse,
stimulus: `
<p>Welcome to the lexical decision experiment!</p>
<br>
<p>Starting from the next slide, you will see either a word or a non-word appear on the center of the screen.</p>
<p>Press "<strong>f</strong>" if you see a word, or "<strong>j</strong>" on your keyboard as fast as you can if you see a non-word.</p>
<p>There will be 90 rounds in total. Good luck!</p>
<br>
<p>Press any key to begin.</p>
`,
};
/* trial */
var trial = {
type: jsPsychHtmlKeyboardResponse,
stimulus: jsPsych.timelineVariable("stimulus"),
choices: ["f", "j"],
data: {
task: "response",
stimulus_type: jsPsych.timelineVariable("stimulus_type"),
correct_response: jsPsych.timelineVariable("correct_response"),
},
on_finish: function (data) {
data.correct = jsPsych.pluginAPI.compareKeys(
data.response,
data.correct_response
);
},
};
var fixation = {
type: jsPsychHtmlKeyboardResponse,
stimulus: '<div style="font-size:60px;">+</div>',
choices: "NO_KEYS",
trial_duration: function () {
return jsPsych.randomization.sampleWithoutReplacement(
[250, 500, 750, 1000, 1250, 1500, 1750, 2000],
1
)[0];
},
data: {task: "fixation"},
};
/* test procedure */
var test_procedure = {
timeline: [fixation, trial],
timeline_variables: test_stimuli,
randomize_order: true,
};
/* results */
var debrief_block = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function () {
var trials = jsPsych.data.get().filter({task: "response"});
var correct_trials = trials.filter({correct: true});
var accuracy = Math.round(
(correct_trials.count() / trials.count()) * 100
);
var rt = Math.round(correct_trials.select("rt").mean());
return `
<p>You responded correctly on ${accuracy}% of the trials.</p>
<p>Your average response time was ${rt}ms.</p>
<p>Press any key to complete the experiment. Thank you!</p>`;
},
};
/* push everything to timeline */
timeline.push(welcome);
timeline.push(test_procedure);
timeline.push(debrief_block);
/* start the experiment */
jsPsych.run(timeline);
</script>
</html>