Counterbalancing variables?

185 views
Skip to first unread message

princessc...@gmail.com

unread,
Jul 23, 2019, 9:22:34 AM7/23/19
to jsPsych
Sorry if this has been answered before but I can't seem to find an answer. I would like to counterbalance the order in which experimental variables are displayed. For example I have two variables:

var variable1 = {
    timeline: [
        {
            type: 'html-keyboard-response',
            stimulus: '+',
            choices: jsPsych.NO_KEYS,
            trial_duration: 200
        },
        {
            type: 'image-keyboard-response',
            stimulus: jsPsych.timelineVariable('picture'),
            trial_duration: 2000,
            choices: [37, 39]
        },

    ],
    timeline_variables: [
        {picture: 'picture1.png' },
        { picture:'picture2.png' },
      ],
      randomize_order:true,
      repetitions:8
}

var variable2 = {
    timeline: [
        {
            type: 'html-keyboard-response',
            stimulus: '+',
            choices: jsPsych.NO_KEYS,
            trial_duration: 200
        },
        {
            type: 'image-keyboard-response',
            stimulus: jsPsych.timelineVariable('picture'),
            trial_duration: 2000,
            choices: [37, 39]
        },

    ],
    timeline_variables: [
        {picture: 'picture3.png' },
        { picture:'picture4.png' },
      ],
      randomize_order:true,
      repetitions:16
}

I would like to randomly display the variables in the experiment, so sometimes variable1 comes first, and sometimes variable 2. This seems very easy but somehow I can't get it to work? Any suggestions would be appreciated! Thanks!!!!

Josh de Leeuw

unread,
Jul 23, 2019, 5:59:38 PM7/23/19
to princessc...@gmail.com, jsPsych
Hi,

One solution would be to randomly sample from the set of variables and then only push the selection onto the timeline.

var timeline = [ ... ] // other trials might be in here
var random_sample = jsPsych.randomization.sampleWithoutReplacement([variable1, variable2], 1); // generates an array of length 1

timeline = timeline.concat(random_sample);

Cheers,
Josh


--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/0e76c32e-11e9-48f9-abd7-bb695697c5a4%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages