Counterbalancing problem

Hi! I am in the middle of creating an online experiment but my problem is still at the level of PsychoPy.
I have instructions, then a practice session with randomised trials and then a double loop, with two trial blocks. I wanted to change the order of the blocks depending on the group and I used the counterbalancing procedure described here: Blocks of trials and counterbalancing — PsychoPy v2022.1.1
It works fine.

Then, since the study will be online, I wanted to make the block sequence depend on the participant number (odd vs even), as described here: Counterbalancing online — PsychoPy v2022.1.1
I added a code component to the routine Start_Break (see attached pic) with this simple code:
if expInfo[‘participant’] % 2:
group = ‘A’
else:
group = ‘B’
It aborts my experiment right after the practice session.

I also tried to replace the conditions $“chooseBlocks”+expInfo[‘group’]+".xlsx" by $“chooseBlocks”+‘group’+".xlsx" as suggested on the webpage. This changes nothing.

Also, I am not sure if in this case I should keep the ‘group’ [‘A’, ‘B’] in the info dialogue or delete it. Either way, the experiment aborts after the practice session.

Hi Karolina, can I check that line 2 and 4 are indented? So it should look something like this:

if expInfo[‘participant’] % 2:
    group = ‘A’
else:
    group = ‘B’

And with this piece of code, you should keep group = [‘A’, ‘B’] in the experiment settings

Hope this helps,
Sue Lynn

Thanks! Yes, the code is indented :slight_smile: But it doesn’t work :confused:

Try if int( expInfo[‘participant’] )% 2:

Hi Sue Lynn! Thanks - this helped with the interpretation of the code!

The experiment stopped aborting. However, I still couldn’t get PsychoPy to change the initial group assignment from expInfo. After some trial and error I solved it :slight_smile:

I provide a solution in case somebody runs into the same problem. I used this code instead:

if int(expInfo[‘participant’]) % 2:
…expInfo[‘group’] = ‘A’
else:
…expInfo[‘group’] = ‘B’

This changes the initial specification of the group accordingly. But to make the programme choose the right conditions file, I had to put the code at BeginExperiment instead of BeginRoutine. Otherwise the group specification was e.g. initially A, then changed to B at the beginning of the routine but the choice of the conditions file would not follow…

With the code set at the beginning of the experiment, group assignment is changed right at the beginning (regardless of what is chosen in expInfo) and everything goes well (at least that’s what the output csv files show :))

Once again thanks for your help in solving this!

Hi Karolina!

The way I do this kind of counterbalancing is by duplicating the routines to be counterbalanced (adding the loops if relevant) and insert loops around with $int(expInfo[‘participant’])%2==1 in the nRep field for the routine order to be displayed for the odd participants and $int(expInfo[‘participant’]))%2==0 in the nRep field for the routine order to be displayed for the even participants.
The int() function makes sure the participant number is taken as an integer.
This should be easily translated in Java Script.

I added a picture to be more concrete.

Hi Ambre! Nice to see you here :slight_smile:

Thanks for the tip! I guess this is a nice solution :slight_smile:

In the meantime, I also found a different solution but I edited the post too many times and they temporarily blocked it. I hope it is visible soon!

Best,
Karolina

1 Like