Randomly distribute 60 images from 20 babies across 4 runs without repeating

I’m building an experiment using 60 baby face images (3 pictures each (sad, neutral, happy) for 10 male babies and 10 female babies). The experiment is a block design with four runs, each run has three blocks (sad, happy, neutral), and each block has 5 images to be shown. How can I distribute 60 baby face images across the four runs without repeating. I would like to order of babies to be different in each run for each participant.

For the baby images, there are 20 baby models (babyID 1-20) in total, and in each run, the same 5 babies should be used. (i.e. if the first block of the first run randomly selects babies 1, 6, 7, 9, 12; then the second block should display the images of these 5 babies in another random order, so on and so forth). Also, I would like the female to male ratio to be counterbalanced (2:3 or 3:2) in each run.

Right now, I built the experiment based on blocks (sad, neutral, happy) and entered a loop across these three blocks with nReps 4 so that the blocks will be looped 4 times in random order. How could I distribute the 60 images of 20 babies across the 4 runs? Should the experiment be built based on runs instead of blocks?

Thanks!!!

Hello

Is there a way to increase the number of images so that there is an even distribution of genders in a loop? This would make programming easier.

Best wishes Jens

Hi there!!

Thanks for the suggestion! If I use 6 pictures in each block (female to male ratio 3:3 for each block), how would you suggest this randomisation be done?

Many many thanks for your reply!!!

Hello

I would create two indexes, one for male, one for female, shuffle the indexes, take the first three elements of each index and use the index to access the rows in your Excel file (Selected rows-option in the loop menu, sequential presentation). These indexes could be shuffled again for the repetitions after each picture has been presented. I would then delete the selected rows from my index files and move on to the next block.

By the way, you can probably use the same trial definition for all three emotions. This would result in one RT column instead of three RT columns in your current approach. Simply add a column to your Excel file to indicate which emotion was presented.

Best wishes, Jens

const ListMale = [1,2,3,4,5,6,7,8,9,10];
const ListFemale = [11,12,13,14,15,16,17,18,19,20]

const run1List = [];
const run2List = [];
//repeat for all 4 lists

//generate a random number to decide the ratio - 2m:3f or 3m:2f
var ratio = Math.floor(Math.random()*2)

if (ratio == 0) {
  //List 1
  for (var j=0; i<=1;i++) { //2m
    for(var i=ListMale.length-1;i>=0;i--){
      var temp = ListMale.splice(Math.floor(Math.random()*ListMale.length), 1);
      run1List.push(temp[0]);
    }
  }
  for (var j=0; i<=2;i++) { //3f
    for(var i=ListFemale.length-1;i>=0;i--){
      var temp = ListFemale.splice(Math.floor(Math.random()*ListFemale.length), 1);
      run1List.push(temp[0]);
    }
  }  
}
//you need to do the same for list 2,3, and 4 - each list is defining images to be shown in each run
else { //3m:2f ratio
//List 1
  for (var j=0; i<=2;i++) { //3m
    for(var i=ListMale.length-1;i>=0;i--){
      var temp = ListMale.splice(Math.floor(Math.random()*ListMale.length), 1);
      run1List.push(temp[0]);
    }
  }
  for (var j=0; i<=1;i++) { //2f
    for(var i=ListFemale.length-1;i>=0;i--){
      var temp = ListFemale.splice(Math.floor(Math.random()*ListFemale.length), 1);
      run1List.push(temp[0]);
    }
  }
}

What this does it gives you 4 lists, each containing the numbers of babies to be displayed in a run. It also gives you two arbitrary selected orders of m:f ratios (you can select whatever ratio you wish for each list in each of the two randomly selected scenarios). If you make sure that your name conventions follow a principle (e.g. baby1_1, baby1_2, baby1_3 where “_1” is always a sad baby, “_2” is always a neutral baby, and “_3” is always a happy baby) it will be no issue to assign the proper images. Or, you can also have string elements in the male and female lists and make them actual names of the source images.

This approach makes sure to never repeat the same baby as once it’s been selected, it removes it from the list of babies for that participant. If you needed, you could reshuffle elements of each list (run1List etc.) for further randomization within the lists as this would randomize the order of different babies to be displayed. You could do that by using Fisher Yates Shuffle (there’s other ways too):

function fisherYatesShuffle(arr) {
    for (let m = arr.length - 1; m > 0; m--) {
    const n = Math.floor(Math.random() * (m + 1));
    [arr[m], arr[n]] = [arr[n], arr[m]];
    }
return arr;
}

run1List = fisherYatesShuffle(run1List);