Participant conditions

809 views
Skip to first unread message

rohen...@gmail.com

unread,
Jul 28, 2015, 1:31:27 PM7/28/15
to jsPsych
I'm wondering if there are any examples (I can't seem to find any) where block order is randomly generated?

There are some blocks that I want to keep in a fixed order, but others that should be random (ideally counterbalanced).

I'm working on an IAT, so some participants should get a congruent block first, and others should get an incongruent block first. Another way to do this might be to assign people to a condition at the beginning (either congruent1 or congruent2) and base the block order on that condition - not sure what the best approach is.

Any tips on how to implement this as simply as possible are appreciated!

Josh de Leeuw

unread,
Jul 28, 2015, 2:00:05 PM7/28/15
to rohen...@gmail.com, jsPsych
There are a couple ways to randomize the order of blocks.

If you have a set of trials that are being declared using a single object, then you can add the randomize_order parameter:

This will randomize the order of trials within a block.

If you want to randomize the order of the blocks themselves (I think this is what you are after), then you can do this by creating the blocks first and then shuffling their order before adding them to the experiment timeline. For example:

var block1 = [];
var block2 = [];

// now create trials and push them to either block1 or block2. 

// create an array with both block1 and block2, and then call shuffle to randomize the order
var random_order = jsPsych.randomization.shuffle([block1, block2]);

// create the experiment timeline, and add the randomly ordered blocks
var timeline = [];

timeline = timeline.concat(random_order);


--
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 post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/b11b242b-51b5-4ff1-be11-a4ed2caf3e9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rohen...@gmail.com

unread,
Jul 28, 2015, 7:36:10 PM7/28/15
to jsPsych, josh.d...@gmail.com
I think this is almost exactly what I'm trying to do.

This line seems to not be working though:
timeline = timeline.concat(random_order);

I get the error: "Uncaught Error: Invalid experiment structure definition. One or more trials is missing a 'type' parameter. "

If I instead do
timeline = timeline.concat(block1, block2)
that works, which tells me there's something happening when I shuffle the array of blocks and try to add it to the timeline.

Any ideas on what I'm doing wrong here?

Josh de Leeuw

unread,
Jul 28, 2015, 10:53:59 PM7/28/15
to rohen...@gmail.com, jsPsych
You're doing it (mostly) right. I wasn't keeping the levels of nested arrays correct. A fix is:

timeline = timeline.concat(random_order[0], random_order[1]);

amen...@gmail.com

unread,
Nov 30, 2015, 9:18:13 PM11/30/15
to jsPsych, rohen...@gmail.com
Hello,

I am also a huge fan of JsPsych! I had a similar question about randomizing block order. I am not trying to randomize the trials within a block. I have attached my code.


/* Blocks */
var experiment = [];
experiment.push(pineapple1, pineapple2, pineapple3, pineapple4, pineapple5);
experiment.push(orange1, orange2, orange3, orange4, orange5);
experiment.push(debrief_block);

/* Run the experiment */
function startExperiment(){
jsPsych.init({
experiment_structure: experiment,
display_element: $('#jspsych-target'),
on_finish: function() {
jsPsych.data.displayData();
}
});
}

I am trying to rotate the pineapple and orange blocks. I need pineapple blocks 1-5 to stay in order and orange blocks 1-5 to stay in order. I then need to rotate whether pineapple or orange blocks display first. All orange and pineapple blocks use the single-stim plugin.


Randomized ex:
var experiment = [];
experiment.push(orange1, orange2, orange3, orange4, orange5);
experiment.push(pineapple1, pineapple2, pineapple3, pineapple4, pineapple5);
experiment.push(debrief_block);


I feel like it is pretty easy to random these blocks, and I trying to learn more about jsPsych. Thank you for any help!

Josh de Leeuw

unread,
Nov 30, 2015, 9:28:55 PM11/30/15
to amen...@gmail.com, jsPsych, rohen...@gmail.com
You could nest the arrays and then unpack them after randomizing:

var blocks = [
  [p1, p2, p3, p4, p5],
  [o1, o2, o3, o4, o5]
];

var random_order = jsPsych.randomization.shuffle(blocks);

// random order will now either be [ [p1, p2, ... ], [o1, o2, ... ] ] or [ [o1, o2, ... ], [p1, p2, ... ] ] 

experiment = experiment.concat(blocks[0], blocks[1]);

--
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 post to this group, send email to jsp...@googlegroups.com.

amen...@gmail.com

unread,
Nov 30, 2015, 10:29:27 PM11/30/15
to jsPsych, amen...@gmail.com, rohen...@gmail.com
Thank You! This worked. Great explanation.

I figured out how to incorporate randomization of blocks into my experiment now. JsPsych is awesome!

Nested Arrays!

Reply all
Reply to author
Forward
0 new messages