-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexical_experiment.html
285 lines (252 loc) · 10.6 KB
/
lexical_experiment.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
<!DOCTYPE html>
<html>
<head>
<title>My experiment</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>
<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>
/* Initialize jsPsych: any response made within 100ms is regarded as useless and the intertrial interval
is set to be 500ms */
var jsPsych = initJsPsych({
default_iti: 800,
minimum_valid_rt: 100,
on_finish: function () {
jsPsych.data.displayData();
}
}
)
/* create timeline array */
var timeline = [];
/* preload audio */
var preload = {
type: jsPsychPreload,
audio: ['audio/music_stimulus.mp3']
};
timeline.push(preload);
/* define welcome message trial */
var welcome = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "Welcome to the experiment. Press any key to begin."
};
timeline.push(welcome);
/* define instruction trial */
var instruction = {
type: jsPsychHtmlKeyboardResponse,
stimulus: `
<p>In this experiment, you will be asked to decide if the stimulus presented on the screen is a word.<p>
<p>Press <strong>"Y"</strong> if you think it is a word and press <strong>"N"</strong> if you think it is not a word.</p>
<p>Try to respond as <strong>fast</strong> as you can.</p>
<p>Before you begin, there are 5 practice trials to prepare you for the actual trials.</p>
<p>The experimenter will tell you what to do now, please remain seated and complete the tasks you're asked to do.</p>
<p>When you are done, press any key to continue.</p>
`
}
timeline.push(instruction);
/* define fixation trial */
var fixation = {
type: jsPsychHtmlKeyboardResponse,
stimulus: '<div style="font-size:60px;">+</div>',
choices: "NO_KEYS",
trial_duration: 650,
data: {
task: 'fixation'
}
};
/*
There are three categories of word stimuli: positive, negative, and neutral.
Each category has 8 words picked by the experimenter.
An equal number of nonwords are generated by modifying the order of internal letters.
If the stimulus is a real word, the response is expected to be Y; if the stimulus is a made-up word,
the response is expected to be N.
*/
var trial_stimuli = [
{ stimulus: "kind", correct_response: 'y' },
{ stimulus: "helpful", correct_response: 'y' },
{ stimulus: "pleasant", correct_response: 'y' },
{ stimulus: "considerate", correct_response: 'y' },
{ stimulus: "caring", correct_response: 'y' },
{ stimulus: "loving", correct_response: 'y' },
{ stimulus: "generous", correct_response: 'y' },
{ stimulus: "obligating", correct_response: 'y' },
{ stimulus: "kidn", correct_response: 'n' },
{ stimulus: "helpflu", correct_response: 'n' },
{ stimulus: "pleastan", correct_response: 'n' },
{ stimulus: "consideraet", correct_response: 'n' },
{ stimulus: "cargin", correct_response: 'n' },
{ stimulus: "inlogv", correct_response: 'n' },
{ stimulus: "geousren", correct_response: 'n' },
{ stimulus: "obliggatin", correct_response: 'n' },
{ stimulus: "rude", correct_response: 'y' },
{ stimulus: "cruel", correct_response: 'y' },
{ stimulus: "impolite", correct_response: 'y' },
{ stimulus: "ungrateful", correct_response: 'y' },
{ stimulus: "mean", correct_response: 'y' },
{ stimulus: "callous", correct_response: 'y' },
{ stimulus: "spiteful", correct_response: 'y' },
{ stimulus: "heartless", correct_response: 'y' },
{ stimulus: "rued", correct_response: 'n' },
{ stimulus: "cuerl", correct_response: 'n' },
{ stimulus: "mopilite", correct_response: 'n' },
{ stimulus: "ungretaful", correct_response: 'n' },
{ stimulus: "neam", correct_response: 'n' },
{ stimulus: "clalous", correct_response: 'n' },
{ stimulus: "fusilpite", correct_response: 'n' },
{ stimulus: "haertless", correct_response: 'n' },
{ stimulus: "firm", correct_response: 'y' },
{ stimulus: "proud", correct_response: 'y' },
{ stimulus: "solemn", correct_response: 'y' },
{ stimulus: "bashful", correct_response: 'y' },
{ stimulus: "ordinary", correct_response: 'y' },
{ stimulus: "cautious", correct_response: 'y' },
{ stimulus: "excitable", correct_response: 'y' },
{ stimulus: "changeable", correct_response: 'y' },
{ stimulus: "frim", correct_response: 'n' },
{ stimulus: "pourd", correct_response: 'n' },
{ stimulus: "someln", correct_response: 'n' },
{ stimulus: "bashflu", correct_response: 'n' },
{ stimulus: "nordiary", correct_response: 'n' },
{ stimulus: "cioustau", correct_response: 'n' },
{ stimulus: "excitabel", correct_response: 'n' },
{ stimulus: "changeabel", correct_response: 'n' }
]
/* define an array of stimuli that shuffles the above 48 stimuli */
var randomized_trial_stimuli = jsPsych.randomization.repeat(trial_stimuli, 1);
var neutral_stimuli = [
{ stimulus: "firm", correct_response: 'y' },
{ stimulus: "proud", correct_response: 'y' },
{ stimulus: "solemn", correct_response: 'y' },
{ stimulus: "bashful", correct_response: 'y' },
{ stimulus: "ordinary", correct_response: 'y' },
{ stimulus: "cautious", correct_response: 'y' },
{ stimulus: "excitable", correct_response: 'y' },
{ stimulus: "changeable", correct_response: 'y' },
{ stimulus: "frim", correct_response: 'n' },
{ stimulus: "pourd", correct_response: 'n' },
{ stimulus: "someln", correct_response: 'n' },
{ stimulus: "bashflu", correct_response: 'n' },
{ stimulus: "nordiary", correct_response: 'n' },
{ stimulus: "cioustau", correct_response: 'n' },
{ stimulus: "excitabel", correct_response: 'n' },
{ stimulus: "changeabel", correct_response: 'n' }
]
var test = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function () {
var stim = '<p style="font-size:80px;font-weight:bold;">' + jsPsych.timelineVariable('stimulus') + '</p>';
return stim
},
choices: ['y', 'n'],
trial_duration: 2000,
data: {
task: 'response',
correct_response: jsPsych.timelineVariable('correct_response')
},
on_finish: function (data) {
data.correct = jsPsych.pluginAPI.compareKeys(data.response, data.correct_response);
}
}
/* define practice trial */
var practice_trial = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function () {
var stim = '<p style="font-size:80px;font-weight:bold;">' + jsPsych.timelineVariable('stimulus') + '</p>';
return stim
},
choices: ['y', 'n'],
trial_duration: 2000,
data: {
task: 'practice'
}
}
var practice = {
timeline: [fixation, practice_trial],
timeline_variables: jsPsych.randomization.sampleWithoutReplacement(neutral_stimuli, 5)
}
timeline.push(practice);
var continued_instruction = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "You've completed the practice trials. Now follow the instructions of the experimenter and start the music when you're ready. Press any key to continue."
}
timeline.push(continued_instruction);
var mood_induction = {
type: jsPsychAudioButtonResponse,
stimulus: "audio/music_stimulus.mp3",
choices: ['Stop here', 'Continue to trials'],
prompt: "<p>If you feel extremely uncomfortable, press the stop button and let the experimenter know.</p>",
trial_duration: null,
response_ends_trial: true,
data: {
task: 'mood_induction'
},
on_finish: function (data) {
if (data.response == 0) {
jsPsych.pauseExperiment();
}
},
}
timeline.push(mood_induction);
var neutral_practice = {
timeline: [fixation, practice_trial],
timeline_variables: [
{ stimulus: 'firm' },
{ stimulus: 'nordiary' }
]
}
timeline.push(neutral_practice);
/* define a block of trials */
var block1 = {
timeline: [fixation, test],
timeline_variables: randomized_trial_stimuli.slice(0, 12)
};
timeline.push(block1);
var intermission = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "You've completed this block. Now follow the instructions of the experimenter. Press any key to start the music."
}
timeline.push(intermission);
timeline.push(mood_induction);
timeline.push(neutral_practice);
var block2 = {
timeline: [fixation, test],
timeline_variables: randomized_trial_stimuli.slice(12, 24)
};
timeline.push(block2);
timeline.push(intermission);
timeline.push(mood_induction);
timeline.push(neutral_practice);
var block3 = {
timeline: [fixation, test],
timeline_variables: randomized_trial_stimuli.slice(24, 36)
};
timeline.push(block3);
timeline.push(intermission);
timeline.push(mood_induction);
timeline.push(neutral_practice);
var block4 = {
timeline: [fixation, test],
timeline_variables: randomized_trial_stimuli.slice(36, 48)
};
timeline.push(block4);
/* define debrief */
var debrief_block = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function () {
var trials = jsPsych.data.get().filter({ task: 'response' });
var correct_trials = trials.filter({ correct: true });
var number_of_correct_trials = correct_trials.count();
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 ${number_of_correct_trials} of the trials, which is ${accuracy}% correct.</p>
<p>Your average response time was ${rt}ms.</p>
<p>Press any key to complete the experiment. Thank you!</p>`;
}
};
timeline.push(debrief_block);
jsPsych.run(timeline);
</script>
</html>