How to set "stim_key_association" as a variable in IAT-plugin? #3299
Replies: 2 comments
-
Hi @Tongzhao9417, one way to do this is to create an array of your two labels, and randomize the order of the array at the start of the experiment. You can do this with the jsPsych.randomization.shuffle function: let labels = ["black", "white"];
let labels_rand = jsPsych.randomization.shuffle(labels);
// labels_rand will either be ["black", "white"] or ["white", "black"] Then you can use the first value (index=0) as the left label, and second value (index=1) as the right label. Whenever you need to reference the label name, you can index the randomized array instead of using a fixed label value: const trial = {
type: jsPsychIatImage,
left_category_label: labels_rand[0],
right_category_label: labels_rand[1],
// etc.
}; As for setting up the corresponding const trial_block = {
timeline: [{
type: jsPsychIatImage,
left_category_label: labels_rand[0],
right_category_label: labels_rand[1],
stim_key_association: function() {
if (jsPsych.timelineVariable('correct_response') == labels_rand[0] {
return 'left';
} else {
return 'right';
}
}
// etc.
}],
timeline_variables: [
{stimulus: "img/black1.jpg", correct_response: "black"},
{stimulus: "img/white1.jpg", correct_response: "white"},
// etc.
]
}; Another option is to dynamically construct your let labels = ["black", "white"];
let labels_rand = jsPsych.randomization.shuffle(labels);
let timeline_vars_initial = [
{stimulus: "img/black1.jpg", correct_response: "black"},
{stimulus: "img/white1.jpg", correct_response: "white"},
// etc.
];
const timeline_vars = timeline_vars_initial.map(obj => {
if (obj.correct_response === labels_rand[0]) { // 0 indexes the left label
return { ...obj, stim_key_association: "left" };
} else {
return { ...obj, stim_key_association: "right" };
}
return obj;
});
const trial_block = {
timeline: [{
type: jsPsychIatImage,
left_category_label: labels_rand[0],
right_category_label: labels_rand[1],
stim_key_association: jsPsych.timelineVariable('stim_key_association')
// etc.
}],
timeline_variables: timeline_vars
}; Do either of those solutions work for you? |
Beta Was this translation helpful? Give feedback.
-
@Tongzhao9417 I just noticed that this is an issue - I'm going to convert it to a Discussion post, since it's a question rather than a bug report or feature request. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, I have another question about the IAT-plugin.
I want to random the stimulus key association to balance the trials. For example, the left side for "black" and right side for "white" for some participants, and right side for "black" and left side for "white" for other participants. Could I achieve the goal in some way? Thank for everyone!
Beta Was this translation helpful? Give feedback.
All reactions