Reply To: Randomization of Stimuli Across Blocks

PennController for IBEX Forums Support Randomization of Stimuli Across Blocks Reply To: Randomization of Stimuli Across Blocks

#5721
Jeremy
Keymaster

Hi Andreas,

it always chooses ‘hello’ and ‘world’ for the first two trials (i.e. first block) and then ‘eyb’ and ‘etam’ for the third and fourth trial (i.e. second block)

You’re probably using Chrome (which is fine) just replace

order = [...new Array(NITEMS)].map((v,i)=>i<NITEMS/2).sort(v=>Math.random()>=0.5)

with

order = [...new Array(NITEMS)].map((v,i)=>i<NITEMS/2).sort(v=>1-2*(Math.random()>=0.5))

I was also wondering what the order array does exactly.

You got it right for the most part:

  • [...new Array(NITEMS)] indeed creates one array of NITEMS slots with the value undefined
  • map((v,i)=>i<NITEMS/2) loops through every slot, fills the v variable with its value (in this case, always undefined) and i with its index (from 0 to NITEMS-1) and replaces the value in the slot with i<NITEMS/2, which is true for the slots whose index is in the first half and false for the other half of the slots
  • sort(v=>1-2*(Math.random()>=0.5)) loops through every slot of the array returned from map (half true, half false) and depending on the value returned by the lambda function, it moves it forward (value > 0) or backward (value < 0) in the array. In this case, the value is a random number between 1 and -1 for each slot, so you end up with an array with half its slots true and half of them false in a totally random order

The Template function will then look up the first value of the order array for each trial it generates, and remove it from the array at the same time (that’s the shift() method) so that the next generated trial will look up the next “first” value from order. Then, because of how we defined of order, half your trials will be generated from a true value (-> "leftRight") and the other half will be generated from a false value, in a random (ie. non linear) order.

Not sure where to start with javascript, I never really followed a single method and the language is now more of a family of languages with many different uses. Ideally PennController lets you abstract away from javascript, but there are some cases (like this one) where it lacks some functionality that can only be implemented using some javascript

Let me know whether changing the random bit fixed the issue

Jeremy