Randomize blocks #1800
-
Hello, I'm having trouble randomizing my 4 blocks between participants. The idea is that the order of the blocks by participants is random, but I'm not getting it. Part of my script I will insert for a better understanding. var blockstimuli_faces1 = [
{stimulus: 'alegria.jpg', prompt:"<div style='position:absolute;font-size:30px;text-align:right;width:650px;top:2%'><p><strong>ALEGRIA1</strong></div>", prompt1: "<div style=font-size:30px;><p>Qual face expressa <strong>ALEGRIA</strong> ?</div>", data: {correct_response: '1', vi1: "feminino", vi2: "alegria", vi3: "direita"}},
];
// create the question screen, with no key choices and a fixed duration (2 seconds in this example)
var question_block_faces1 = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('prompt1'),
choices: jsPsych.NO_KEYS,
trial_duration: 2000
};
// create blocktrial_faces
var blocktrial_faces1 = {
type: "image-button-response",
stimulus: jsPsych.timelineVariable('stimulus'),
prompt: jsPsych.timelineVariable('prompt'),
stimulus_height: 630,
stimulus_width: 1080,
stimulus_duration: 10000,
choices: ["<div style=font-size:15px;><p><strong>ESQUERDA</strong></div>", "<div style=font-size:15px;><p><strong>DIREITA</strong></div>"],
margin_horizontal: '250px',
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
data.correct = data.response == data.correct_response;
}
};
// create blocktrial_procedure_faces
var blocktrial_procedure_faces1 = {
timeline: [fixation, question_block_faces1, blocktrial_faces1], // <---- add the question trial to the procedure timeline
timeline_variables: blockstimuli_faces1,
randomize_order: true
};
// create blockstimuli_faces
var blockstimuli_faces2 = [
{stimulus: 'alegria.jpg', prompt:"<div style='position:absolute;font-size:30px;text-align:right;width:650px;top:2%'><p><strong>ALEGRIA2</strong></div>", prompt1:"<div style=font-size:30px;><p>Qual face expressa <strong>ALEGRIA</strong> ?</div>", data: {correct_response: '1', vi1: "feminino", vi2: "alegria", vi3: "direita"}}
];
// create the question screen, with no key choices and a fixed duration (2 seconds in this example)
var question_block_faces2 = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('prompt1'),
choices: jsPsych.NO_KEYS,
trial_duration: 2000
};
// create blocktrial_faces
var blocktrial_faces2 = {
type: "image-button-response",
stimulus: jsPsych.timelineVariable('stimulus'),
prompt: jsPsych.timelineVariable('prompt'),
stimulus_height: 630,
stimulus_width: 1080,
stimulus_duration: 10000,
choices: ["<div style=font-size:15px;><p><strong>ESQUERDA</strong></div>", "<div style=font-size:15px;><p><strong>DIREITA</strong></div>"],
margin_horizontal: '250px',
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
data.correct = data.response == data.correct_response;
}
};
// create blocktrial_procedure_faces
var blocktrial_procedure_faces2 = {
timeline: [fixation, question_block_faces2, blocktrial_faces2], // <---- add the question trial to the procedure timeline
timeline_variables: blockstimuli_faces2,
randomize_order: true
};
// create blockstimuli_faces
var blockstimuli_faces3 = [
{stimulus: 'alegria.jpg', prompt:"<div style='position:absolute;font-size:30px;text-align:right;width:650px;top:2%'><p><strong>ALEGRIA3</strong></div>", prompt1:"<div style=font-size:30px;><p>Qual face expressa <strong>ALEGRIA</strong> ?</div>", data: {correct_response: '1', vi1: "feminino", vi2: "alegria", vi3: "direita"}},
];
// create the question screen, with no key choices and a fixed duration (2 seconds in this example)
var question_block_faces3 = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('prompt1'),
choices: jsPsych.NO_KEYS,
trial_duration: 2000
};
// create blocktrial_faces
var blocktrial_faces3 = {
type: "image-button-response",
stimulus: jsPsych.timelineVariable('stimulus'),
prompt: jsPsych.timelineVariable('prompt'),
stimulus_height: 630,
stimulus_width: 1080,
stimulus_duration: 10000,
choices: ["<div style=font-size:15px;><p><strong>ESQUERDA</strong></div>", "<div style=font-size:15px;><p><strong>DIREITA</strong></div>"],
margin_horizontal: '250px',
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
data.correct = data.response == data.correct_response;
}
};
// create blocktrial_procedure_faces
var blocktrial_procedure_faces3 = {
timeline: [fixation, question_block_faces3, blocktrial_faces3], // <---- add the question trial to the procedure timeline
timeline_variables: blockstimuli_faces3,
randomize_order: true
};
// create blockstimuli_faces
var blockstimuli_faces4 = [
{stimulus: 'alegria.jpg', prompt:"<div style='position:absolute;font-size:30px;text-align:right;width:650px;top:2%'><p><strong>ALEGRIA4</strong></div>", prompt1: "<div style=font-size:30px;><p>Qual face expressa <strong>ALEGRIA</strong>?</div>", data: {correct_response: '1', vi1: "feminino", vi2: "alegria", vi3: "direita"}},
];
// create the question screen, with no key choices and a fixed duration (2 seconds in this example)
var question_block_faces4 = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('prompt1'),
choices: jsPsych.NO_KEYS,
trial_duration: 2000
};
// create blocktrial_faces
var blocktrial_faces4 = {
type: "image-button-response",
stimulus: jsPsych.timelineVariable('stimulus'),
prompt: jsPsych.timelineVariable('prompt'),
stimulus_height: 630,
stimulus_width: 1080,
stimulus_duration: 10000,
choices: ["<div style=font-size:15px;><p><strong>ESQUERDA</strong></div>", "<div style=font-size:15px;><p><strong>DIREITA</strong></div>"],
margin_horizontal: '250px',
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
data.correct = data.response == data.correct_response;
}
};
// create blocktrial_procedure_faces
var blocktrial_procedure_faces4 = {
timeline: [fixation, question_block_faces4, blocktrial_faces4], // <---- add the question trial to the procedure timeline
timeline_variables: blockstimuli_faces4,
randomize_order: true
};
timeline.push(blocktrial_procedure_faces1, blocktrial_procedure_faces2, blocktrial_procedure_faces3, blocktrial_procedure_faces4);
jsPsych.init({
timeline: [ fullscreen, preload, welcome, instructions_experiment11, blocktrial_procedure_faces1, blocktrial_procedure_faces2, blocktrial_procedure_faces3, blocktrial_procedure_faces4, end_experiment, fullscreen_exit ], I await a help :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
FYI @lily2brain, I just edited your post to make your code block easier to read. See #1113 😃 |
Beta Was this translation helpful? Give feedback.
-
Edit: Fixed earlier error with the result of the concat function not being assigned back to the timeline variable, which resulted in the randomized blocks not being added to the timeline. Hi @lily2brain, one way to do this is to create an array of just the blocks that you want to randomize, randomize that array using jsPsych.randomization.shuffle, and then concatenate the randomized blocks with your // create an empty array to store your experiment's timeline
var timeline = [];
// define the trials/procedures that come before your blocks, and add them to the timeline array
timeline.push(fullscreen);
timeline.push(preload);
timeline.push(welcome);
timeline.push(instructions_experiment11);
// after defining your 4 blocks, put these into an array, and then randomize the order
var blocks = [blocktrial_procedure_faces1, blocktrial_procedure_faces2, blocktrial_procedure_faces3, blocktrial_procedure_faces4];
var blocks_rand = jsPsych.randomization.shuffle(blocks);
// add the randomized blocks onto the end of your timeline array
// (unlike .push, .concat doesn't automatically modify the original array, so the result has to be assigned back
// to the timeline variable)
timeline = timeline.concat(blocks_rand);
// add the trials/procedures that come after the blocks
timeline.push(end_experiment);
timeline.push(fullscreen_exit); Does that work for you? |
Beta Was this translation helpful? Give feedback.
Edit: Fixed earlier error with the result of the concat function not being assigned back to the timeline variable, which resulted in the randomized blocks not being added to the timeline.
Hi @lily2brain, one way to do this is to create an array of just the blocks that you want to randomize, randomize that array using jsPsych.randomization.shuffle, and then concatenate the randomized blocks with your
timeline
array using the JavaScript arrayconcat
function. Here's an example: