-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomnessExp.html
367 lines (323 loc) · 24.1 KB
/
RandomnessExp.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
359
360
361
362
363
364
365
366
367
<!DOCTYPE html>
<html>
<head>
<script src="jspsych-6.3.1/jspsych.js"></script>
<script src="jspsych-6.3.1/plugins/jspsych-survey-likert.js"></script>
<script src="jspsych-6.3.1/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6.3.1/plugins/jspsych-survey-text.js"></script>
<script src="jspsych-6.3.1/plugins/jspsych-survey-html-form.js"></script>
<script src="jspsych-6.3.1/plugins/jspsych-survey-multi-choice.js"></script>
<link rel="stylesheet" href="jspsych-6.3.1/css/jspsych.css">
</head>
<body>
<script>
/* experiment parameters */
var FIXATION_DURATION = 500;
var string_num = 1;
var NUM_TRIALS = string_num*4;
/*create a subject ID*/
var subjectID = 'SUBJ_' + Date.now() + '_' + Math.floor(Math.random() * 1000);
/*create demographic questions*/
var demographicQuestions = {
type: 'survey-html-form',
preamble: '<p>Please provide the following information:</p>',
html: `
<div>
<label for="gender">Gender:</label>
<select name="gender" id="gender">
<option value="male">Male</option>
<option value="female">Female</option>
<option value="nonbinary">Nonbinary</option>
</select>
</div>
<div>
<label for="age">Age:</label>
<input type="number" name="age" id="age" placeholder="Enter your age here">
</div>
<div>
<label for="race">Race:</label>
<select name="race" id="race">
<option value="american first nations">American First Nations</option>
<option value="asian">Asian</option>
<option value="black">Black</option>
<option value="more than one">More than one</option>
<option value="pacific islander">Pacific Islander</option>
<option value="prefer not to say">Prefer not to say</option>
<option value="south asian">South Asian</option>
<option value="white">White</option>
</select>
</div>
<div>
<label for="education">Education:</label>
<select name="education" id="education">
<option value="high school">High School</option>
<option value="some college">Some College</option>
<option value="undergraduate">Undergraduate Degree</option>
<option value="post graduate">Post-graduate Degree</option>
</select>
</div>
<div>
<label for="stats-course">Have you ever taken any statistics course?</label>
<select name="stats-course" id="stats-course">
<option value="yes">Yes</option>
<option value="no">No</option>
<option value="not sure">Not Sure</option>
</select>
</div>
`,
on_finish: function(data) {
// Let's say the key is formData for example
if(data.responses) {
var responses = JSON.parse(data.responses);
demographicsData = {
'subj ID': subjectID,
Gender: responses.gender,
Age: responses.age,
Race: responses.race,
Education: responses.education,
Statcourse: responses['stats-course']
};
// Save the demographicsData to CSV
jsPsych.data.addDataToLastTrial(demographicsData);
jsPsych.data.get().localSave('csv', 'demographics_' + subjectID + '.csv');
} else {
console.warn('Form responses are not found.');
}
}
}
/* create cover story */
var coverStory = {
type: 'html-keyboard-response',
stimulus: `<p>Imagine you are a space rescuer whose job is to search for astronauts lost in deep space. Our fleet of spaceships are all equipped with radio transmitters, which can be operated by the astronaut in case they are in need of rescue. To call for help, astronauts can use the transmitter to send out sequences made of two types of radio waves - 0 and 1. However, both types of waves may also be produced by natural phenomena, such as celestial body activities - in this case, 0 and 1 are equally likely to appear. Everyone in space knows that by current technical standard, radio receivers can only pick up 10 waves in a row - that is, you can only detect sequences that have 10 waves (as mentioned before, each wave is either 0 or 1). If you receive a sequence and think it was produced by natural phenomena, you will ignore it and stay on course. If you think it came from humans, then we will send a rescue team. In this study, you will see about 250 sequences. Your task is to decide whether each sequence was generated by a natural phenomenon or by a human astronaut. Please answer as quickly and accurately as possible!</p> <p>Press any key to continue.</p>`
};
/* create instructions */
var instructions = {
type: 'html-keyboard-response',
stimulus: `<p>In the following experiment, you will be shown strings and asked to rate their randomness.</p>
<p>Rate the randomness of each string on a scale from 1 (nonrandom) to 5 (very random).</p>
<p>Press any key to begin.</p>`
};
/* create the task components */
var fixation = {
type: 'html-keyboard-response',
stimulus: '<p style="font-size: 48px; font-family: monospace;">+</p>',
choices: jsPsych.NO_KEYS,
trial_duration: FIXATION_DURATION
};
var numpool = [{"00000000":"00000001"},{"00000000":"00000010"},{"00000000":"00000011"},{"00000000":"00000100"},{"00000000":"00000101"},{"00000000":"00000110"},{"00000000":"00000111"},{"00000000":"00001000"},{"00000000":"00001001"},{"00000000":"00001010"},{"00000000":"00001011"},{"00000000":"00001100"},{"00000000":"00001101"},{"00000000":"00001110"},{"00000000":"00001111"},{"00000000":"00010000"},{"00000000":"00010001"},{"00000000":"00010010"},{"00000000":"00010011"},{"00000000":"00010100"},{"00000000":"00010101"},{"00000000":"00010110"},{"00000000":"00010111"},{"00000000":"00011000"},{"00000000":"00011001"},{"00000000":"00011010"},{"00000000":"00011011"},{"00000000":"00011100"},{"00000000":"00011101"},{"00000000":"00011110"},{"00000000":"00011111"},{"00000000":"00100000"},{"00000000":"00100001"},{"00000000":"00100010"},{"00000000":"00100011"},{"00000000":"00100100"},{"00000000":"00100101"},{"00000000":"00100110"},{"00000000":"00100111"},{"00000000":"00101000"},{"00000000":"00101001"},{"00000000":"00101010"},{"00000000":"00101011"},{"00000000":"00101100"},{"00000000":"00101101"},{"00000000":"00101110"},{"00000000":"00101111"},{"00000000":"00110000"},{"00000000":"00110001"},{"00000000":"00110010"},{"00000000":"00110011"},{"00000000":"00110100"},{"00000000":"00110101"},{"00000000":"00110110"},{"00000000":"00110111"},{"00000000":"00111000"},{"00000000":"00111001"},{"00000000":"00111010"},{"00000000":"00111011"},{"00000000":"00111100"},{"00000000":"00111101"},{"00000000":"00111110"},{"00000000":"00111111"},{"00000000":"01000000"},{"00000000":"01000001"},{"00000000":"01000010"},{"00000000":"01000011"},{"00000000":"01000100"},{"00000000":"01000101"},{"00000000":"01000110"},{"00000000":"01000111"},{"00000000":"01001000"},{"00000000":"01001001"},{"00000000":"01001010"},{"00000000":"01001011"},{"00000000":"01001100"},{"00000000":"01001101"},{"00000000":"01001110"},{"00000000":"01001111"},{"00000000":"01010000"},{"00000000":"01010001"},{"00000000":"01010010"},{"00000000":"01010011"},{"00000000":"01010100"},{"00000000":"01010101"},{"00000000":"01010110"},{"00000000":"01010111"},{"00000000":"01011000"},{"00000000":"01011001"},{"00000000":"01011010"},{"00000000":"01011011"},{"00000000":"01011100"},{"00000000":"01011101"},{"00000000":"01011110"},{"00000000":"01011111"},{"00000000":"01100000"},{"00000000":"01100001"},{"00000000":"01100010"},{"00000000":"01100011"},{"00000000":"01100100"},{"00000000":"01100101"},{"00000000":"01100110"},{"00000000":"01100111"},{"00000000":"01101000"},{"00000000":"01101001"},{"00000000":"01101010"},{"00000000":"01101011"},{"00000000":"01101100"},{"00000000":"01101101"},{"00000000":"01101110"},{"00000000":"01101111"},{"00000000":"01110000"},{"00000000":"01110001"},{"00000000":"01110010"},{"00000000":"01110011"},{"00000000":"01110100"},{"00000000":"01110101"},{"00000000":"01110110"},{"00000000":"01110111"},{"00000000":"01111000"},{"00000000":"01111001"},{"00000000":"01111010"},{"00000000":"01111011"},{"00000000":"01111100"},{"00000000":"01111101"},{"00000000":"01111110"},{"00000000":"01111111"},{"00000000":"10000000"},{"00000000":"10000001"},{"00000000":"10000010"},{"00000000":"10000011"},{"00000000":"10000100"},{"00000000":"10000101"},{"00000000":"10000110"},{"00000000":"10000111"},{"00000000":"10001000"},{"00000000":"10001001"},{"00000000":"10001010"},{"00000000":"10001011"},{"00000000":"10001100"},{"00000000":"10001101"},{"00000000":"10001110"},{"00000000":"10001111"},{"00000000":"10010000"},{"00000000":"10010001"},{"00000000":"10010010"},{"00000000":"10010011"},{"00000000":"10010100"},{"00000000":"10010101"},{"00000000":"10010110"},{"00000000":"10010111"},{"00000000":"10011000"},{"00000000":"10011001"},{"00000000":"10011010"},{"00000000":"10011011"},{"00000000":"10011100"},{"00000000":"10011101"},{"00000000":"10011110"},{"00000000":"10011111"},{"00000000":"10100000"},{"00000000":"10100001"},{"00000000":"10100010"},{"00000000":"10100011"},{"00000000":"10100100"},{"00000000":"10100101"},{"00000000":"10100110"},{"00000000":"10100111"},{"00000000":"10101000"},{"00000000":"10101001"},{"00000000":"10101010"},{"00000000":"10101011"},{"00000000":"10101100"},{"00000000":"10101101"},{"00000000":"10101110"},{"00000000":"10101111"},{"00000000":"10110000"},{"00000000":"10110001"},{"00000000":"10110010"},{"00000000":"10110011"},{"00000000":"10110100"},{"00000000":"10110101"},{"00000000":"10110110"},{"00000000":"10110111"},{"00000000":"10111000"},{"00000000":"10111001"},{"00000000":"10111010"},{"00000000":"10111011"},{"00000000":"10111100"},{"00000000":"10111101"},{"00000000":"10111110"},{"00000000":"10111111"},{"00000000":"11000000"},{"00000000":"11000001"},{"00000000":"11000010"},{"00000000":"11000011"},{"00000000":"11000100"},{"00000000":"11000101"},{"00000000":"11000110"},{"00000000":"11000111"},{"00000000":"11001000"},{"00000000":"11001001"},{"00000000":"11001010"},{"00000000":"11001011"},{"00000000":"11001100"},{"00000000":"11001101"},{"00000000":"11001110"},{"00000000":"11001111"},{"00000000":"11010000"},{"00000000":"11010001"},{"00000000":"11010010"},{"00000000":"11010011"},{"00000000":"11010100"},{"00000000":"11010101"},{"00000000":"11010110"},{"00000000":"11010111"},{"00000000":"11011000"},{"00000000":"11011001"},{"00000000":"11011010"},{"00000000":"11011011"},{"00000000":"11011100"},{"00000000":"11011101"},{"00000000":"11011110"},{"00000000":"11011111"},{"00000000":"11100000"},{"00000000":"11100001"},{"00000000":"11100010"},{"00000000":"11100011"},{"00000000":"11100100"},{"00000000":"11100101"},{"00000000":"11100110"},{"00000000":"11100111"},{"00000000":"11101000"},{"00000000":"11101001"},{"00000000":"11101010"},{"00000000":"11101011"},{"00000000":"11101100"},{"00000000":"11101101"},{"00000000":"11101110"},{"00000000":"11101111"},{"00000000":"11110000"},{"00000000":"11110001"},{"00000000":"11110010"},{"00000000":"11110011"},{"00000000":"11110100"},{"00000000":"11110101"},{"00000000":"11110110"},{"00000000":"11110111"},{"00000000":"11111000"},{"00000000":"11111001"},{"00000000":"11111010"},{"00000000":"11111011"},{"00000000":"11111100"},{"00000000":"11111101"},{"00000000":"11111110"},{"00000000":"11111111"}];
/* Randomly select trials without repetition */
function getRandomTrials(array, numTrials) {
var shuffledArray = array.slice().sort(function () {
return 0.5 - Math.random();
});
return shuffledArray.slice(0, numTrials);
}
// Add cover story to main timeline
var mainTimeline = [];
mainTimeline.push(demographicQuestions)
mainTimeline.push(coverStory);
var randomizedTrials = getRandomTrials(numpool, NUM_TRIALS);
if (randomizedTrials === "00000000" || randomizedTrials === "11111111") {
numpool.push({ "00000000": randomizedTrials });
} else {
for (let j = 0; j < 6; j++) {
numpool.push({ "00000000": randomizedTrials });
}
}
console.log(numpool)
// Add instructions to main timeline
mainTimeline.push(instructions);
// Create an array of condition descriptions
var conditionDescriptions = [
"1. In the quadrant you are currently monitoring, the astronauts are trained to be vigilant and to always accept help. When the emergency protocol is triggered, they will follow guidelines and send distress signals, as they very much want help to arrive.",
"2. In the quadrant you are currently monitoring, the astronauts are trained to be unafraid and are reluctant to accept help when the emergency protocol is triggered. They will follow guidelines and send distress signals but do not really want help to arrive.",
"3. In the quadrant you are currently monitoring, astronauts have a detailed, up-to-date instruction manual for what to do in case of an emergency. As a result, the astronauts know that the signals should be non-random sequences since only then do the rescue ships recognize the sequences as a distress signal.",
"4. In the quadrant you are currently monitoring, astronauts have an instruction manual for what to do in case of an emergency but it has some unfortunate omissions. As a result, the astronauts don not know that the signals should be non-random sequences, since only then do the rescue ships recognize the sequences as a distress signal.",
"5. In the quadrant you are currently monitoring, each member of the team is well-trained to use the transmission equipment. Even though the equipment can be difficult to operate when in zero gravity and while wearing bulky gloves, the astronauts are highly skilled at executing the radio transmissions they want to send.",
"6. In the quadrant you are currently monitoring, no member of the team has been trained to use the transmission equipment. The equipment can be difficult to operate when in zero gravity and wearing bulky gloves, so the astronauts are often unable to execute the radio transmissions they want to send.",
"7. In the quadrant you are currently monitoring, one of the reasons why a distress signal may be triggered is because of a life support malfunction. To stay fully conscious astronauts are equipped with oxygen tanks. As a result, when they are sending a radio transmission, they are fully aware of what they are doing.",
"8. In the quadrant you are currently monitoring, one of the reasons why a distress signal may be triggered is because of a life support malfunction. In such as state, astronauts will often drift in and out of consciousness. As a result, when they are sending a radio transmission, they may not be fully aware of what they are doing."
];
// Updated comprehension questions array with pairs of questions for each condition
var comprehensionQuestions = [
// Vignette 1: Desire Present
[
{ prompt: "True or False: In this quadrant astronauts desire to receive help and actively want help to arrive when they send a distress signal.", correct: "True" },
{ prompt: "True or False: You would expect astronauts in this quadrant to disregard guidelines when they encounter an emergency.", correct: "False" }
],
// Vignette 2: Belief Present
[
{ prompt: "True or False: Astronauts in this quadrant believe that sending non-random sequences as distress signals will ensure their messages are recognized by rescue ships.", correct: "True" },
{ prompt: "True or False: The instruction manuals for astronauts in this quadrant are potentially out of date.", correct: "False" }
],
// Vignette 3: Skill Present
[
{ prompt: "True or False: All team members in this quadrant are well-trained and highly skilled at executing the radio transmissions they intend to send despite the operation difficulties in zero gravity and while wearing bulky gloves.", correct: "True" },
{ prompt: "True or False: During a life support malfunction astronauts will have to take off their gloves to send a signal.", correct: "False" }
],
// Vignette 4: Awareness Present
[
{ prompt: "True or False: During a life support malfunction astronauts remain fully aware of their actions when sending a radio transmission thanks to being equipped with oxygen tanks.", correct: "True" },
{ prompt: "True or False: During a life support malfunction astronauts may slip in and out of consciousness due to lack of oxygen and this will affect their transmissions.", correct: "False" }
],
// Vignette 1: Desire Absent
[
{ prompt: "True or False: Astronauts in this quadrant are eager to accept help and express a strong desire for assistance when an emergency protocol is triggered.", correct: "False" },
{ prompt: "True or False: Astronauts in this quadrant have been trained to be independent and refuse help if offered.", correct: "True" }
],
// Vignette 2: Belief Absent
[
{ prompt: "True or False: Astronauts have a clear understanding and believe that sending any type of signal including random sequences will be recognized by rescue ships as a distress signal.", correct: "False" },
{ prompt: "True or False: Astronauts in this quadrant have manuals which contain omissions that may impact their transmissions in the event of an emergency.", correct: "True" }
],
// Vignette 3: Skill Absent
[
{ prompt: "True or False: The team members in this quadrant are proficient in using the transmission equipment ensuring they can effectively execute the radio transmissions they intend to send.", correct: "False" },
{ prompt: "True or False: The astronauts in this quadrant are wearing bulky gloves.", correct: "True" }
],
// Vignette 4: Awareness Absent
[
{ prompt: "True or False: During a life support malfunction astronauts maintain constant awareness and full consciousness unaffected by their physical state while sending radio transmissions.", correct: "False" },
{ prompt: "True or False: The lack of oxygen in these environments may impact the transmissions you receive.", correct: "True" }
]
];
var NUM_STORIES_PER_VERSION = 4;
var NUM_VERSIONS = 70;
var versions = [];
for (var i = 0; i < conditionDescriptions.length; i++) {
for (var j = i + 1; j < conditionDescriptions.length; j++) {
for (var k = j + 1; k < conditionDescriptions.length; k++) {
for (var l = k + 1; l < conditionDescriptions.length; l++) {
var version = [conditionDescriptions[i], conditionDescriptions[j], conditionDescriptions[k], conditionDescriptions[l]];
versions.push(version);
}
}
}
}
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
shuffleArray(versions);
// Prepare versions to ensure each has a unique set of comprehension questions
var preparedVersions = versions.map(function(version, idx) {
// Extract comprehension questions for this version
var comprehensionQuestionsForVersion = version.map(function(description) {
var index = conditionDescriptions.indexOf(description);
return comprehensionQuestions[index];
});
return {
version: idx + 1, // version number, if you need it
descriptions: version,
questions: comprehensionQuestionsForVersion
};
});
var selectedVersion = preparedVersions[Math.floor(Math.random() * preparedVersions.length)];
selectedVersion.descriptions.forEach(function(description, versionIndex) {
let descriptionTrial = {
type: 'html-keyboard-response',
stimulus: '<p>' + description + '</p><p>Press any key to continue.</p>'
};
// Correctly access the set of questions for the current description
let questionSet = selectedVersion.questions[versionIndex];
let questionsTrial = {
timeline: [{
type: 'survey-multi-choice',
questions: questionSet.map(function(q, index) {
return {
prompt: q.prompt,
options: ['True', 'False'],
required: true,
horizontal: true,
name: 'Q' + index // Unique name for each question
};
}),
on_finish: function(data) {
var responses = data.response;
var allCorrect = true; // Assume true initially
questionSet.forEach(function(question, index) {
var responseKey = 'Q' + index;
var correctAnswer = question.correct;
var userAnswer = responses[responseKey];
if (userAnswer !== correctAnswer) {
allCorrect = false; // Set to false if any answer is incorrect
}
});
jsPsych.data.getLastTrialData().values()[0].allCorrect = allCorrect;
}
}],
loop_function: function(data) {
if (!data.values()[0].allCorrect) {
// Participant got at least one answer wrong
// Warning and re-display of the condition description
let warningTrial = {
type: 'html-keyboard-response',
stimulus: '<p>Some of your answers were not correct. Please read the story again and try to answer the questions correctly this time.</p><p>' + description + '</p><p>Press any key to try the questions again.</p>'
};
// Re-insert the description and questions trials into the timeline
jsPsych.addNodeToEndOfTimeline({
timeline: [warningTrial, descriptionTrial, questionsTrial]
});
return true; // Repeat the loop, which now includes the warning and re-display of the condition description
} else {
return false; // All answers were correct; do not repeat the loop
}
}
};
mainTimeline.push(descriptionTrial, questionsTrial);
// Now add 'string_num' string trials after each description and question
for (let i = 0; i < string_num; i++) {
// This calculation is to ensure we're pulling the correct strings
let trialIndex = versionIndex * string_num + i;
if (trialIndex < randomizedTrials.length) {
let stringTrial = Object.values(randomizedTrials[trialIndex])[0]; // Assuming this accesses the string correctly
let trial = {
type: 'survey-likert',
questions: [{
prompt: '<p>Please rate how random do you think this string is:</p><p>' + stringTrial + '</p>', // Adjust if needed to match structure of randomizedTrials
labels: ['1 (not random)', '2', '3', '4', '5 (very random)'],
required: true // Ensure the response is required
}],
data: {
'subj ID': subjectID,
stimulus: stringTrial, // Adjust if needed
task: 'rating'
}
};
mainTimeline.push(trial);
} else {
console.error('Invalid item in randomizedTrials at index:', trialIndex);
}
}
// Optionally, add a fixation between sets if desired
let fixation = {
type: 'html-keyboard-response',
stimulus: '<div style="font-size:24px;">+</div>',
choices: jsPsych.NO_KEYS,
trial_duration: 1000 // Adjust as necessary
};
mainTimeline.push(fixation);
});
/* create the end screen */
var end = {
type: 'html-keyboard-response',
stimulus: `<p>You're done! A .csv file containing your data should be automatically downloading right now.
Check your default downloads location to find it. Once you've found it, you can close the experiment.</p>`,
on_load: function() {
jsPsych.data.get().localSave('csv', 'psychology_test_data.csv');
}
};
/* add end screen to main timeline */
mainTimeline.push(end);
/* run the experiment */
jsPsych.init({
timeline: mainTimeline,
experiment_width: 850
});
</script>
</body>
</html>