Assigning Participant condition #1899
-
Hi there, I am designing an experiment that will need subjects randomly assigned to one of four conditions. So far, I have var condition_assignment = jsPsych.randomization.sampleWithoutReplacement(['LIST1', 'LIST2', 'LIST3', 'LIST4'], 1)[0]; How do I make only the materials specific for the condition play for the participant? Sorry if this is a bad question! This is my first time coding! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi @kassyec! First of all, there are no bad questions. Lots of researchers are new coding, and especially to web programming. Assuming you have some different stimulus lists that correspond to each of these conditions, then what I would do is create some if/else statements that check the value of // randomly assign a condition
var condition_assignment = jsPsych.randomization.sampleWithoutReplacement(['LIST1', 'LIST2'], 1)[0];
jsPsych.data.addProperties({
condition: condition_assignment
});
// trial information for each condition
var list_1 = [{stimulus: 'List 1, trial 1'}, {stimulus: 'List 1, trial 2'}];
var list_2 = [{stimulus: 'List 2, trial 1'}, {stimulus: 'List 2, trial 2'}];
// create a variable to hold the trial information, which changes based on the condition
var stimuli;
if (condition_assignment == "LIST1") {
stimuli = list_1;
} else if (condition_assignment == "LIST2") {
stimuli = list_2;
}
// define the trial
// here the value of the stimulus will come from the timeline variables (stimuli) array,
// so it will change according to the condition that was assigned
var trial = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('stimulus')
};
// use the stimuli array as your timeline variables array
// this will repeat the trial for each object in your stimuli array, and use the appropriate stimulus value
var trial_procedure = {
timeline: [trial],
timeline_variables: stimuli
}
jsPsych.init({
timeline: [trial_procedure],
on_finish: function(){jsPsych.data.displayData();}
}); Of course, your solution might look quite a bit different, for instance if you're not using timeline variables. I hope this helps! Feel free to follow up here if you're not sure how to make this idea work for your experiment. |
Beta Was this translation helpful? Give feedback.
Hi @kassyec! First of all, there are no bad questions. Lots of researchers are new coding, and especially to web programming.
Assuming you have some different stimulus lists that correspond to each of these conditions, then what I would do is create some if/else statements that check the value of
condition_assignment
, and use that to create an array of trial information. Then, you would use that trial information array to run your experiment. Here's a little example using timeline variables: