-
Hi, I am looking for a way to shuffle my items based on a group membership, but I do not want each group to be spaced evenly or be in a consistent group order. My (shortened) timeline now looks like this:
But with this sample function the group order is fixed. I want it to be completely random. Basically, I just want to ensure that members belonging to the same group are not selected right after another, but otherwise the order between the items should be completely random. Any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Do you want all 32 items to be presented exactly one time? Are there any other constraints? |
Beta Was this translation helpful? Give feedback.
-
A custom sampling function using the shuffleNoRepeats method could work. timeline.push({
// timeline
// timeline_variables
sample: {
type: 'custom',
fn: function(){
// define groups
var groups = [[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15],[16,17,18,19],[20,21,22,23],[24,25,26,27],[28,29,30,31]];
// create object for each timeline variable specifying group membership and item
var all_items = [];
for(var i=0; i<groups.length; i++){
for(var j=0; j<groups[i].length; j++){
all_items.push({group: i, trial_num: groups[i][j]});
}
}
// randomize group order, with no repeat constraint
// use custom equality function to specify what a "repeat" means
var order = jsPsych.randomization.shuffleNoRepeats(all_items, function(a,b){
return a.group == b.group;
});
// create the final list of trials
return order.map(function(x){ return x.trial_num });
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Can I follow up on this? Would it be possible to insert attention check trials (which are of the same kind as targets) after target groups are fully randomized using the above code? Let's say I have forty target sentences. I also have three attention check trials; I'd like them to appear on trial numbers 12, 24, and 36. In that case, should I create a randomized order of the target items first and then insert attention check items into an array later? I was thinking of something like this:
|
Beta Was this translation helpful? Give feedback.
A custom sampling function using the shuffleNoRepeats method could work.