| Reference | Downloads | Github

Random assignment of participants to groups

Hey all!

I am trying to set up a PsychoPy experiment, first time all by myself.
Unfortunately, I am a total beginner when it comes to Python and programming.
Good thing is, I already have a working experiment template from a previous pilot study which I now need to change to my needs.

Major thing which needs to be included is: Participants should randomly be assigned to one of four different groups. The experiment consists of two phases: training phase and generalisation phase. Thus, when a participant was assigned to group 1 in the training phase, they have to be assigned to the same group in the generalisation phase.

I’ve created the files I need (excel & folder with pictures) for each group and each phase: so I have for example the files for TrainingG1 (group 1) containing the TrainingG1 excel file and the TrainingG1 zip-folder with the PNG files. Same goes for TrainingG2-4 and GeneralisationG1-4.

I know how to set up the experiment with Training & Generalisation phase for one group, but how can I add a “junction” so to say where the participants are randomly assigned one way (either group1, group2, group3, group4)?

I would really appreciate your help!

Hello Lucia

if int(expInfo['participant']) %4 == 0:
    stimfile = "stimfile4.xlsx"
elif int(expInfo['participant']) %3 == 0:
        stimfile = "stimfile3.xlsx"
elif int(expInfo['participant']) %2 == 0:
        stimfile = "stimfile2.xlsx"
        stimfile = "stimfile1.xlsx"

Put this code at a “Begin Experiment”-tab. It loads four differtent stimulus-files depending on the participant number.

Best Jens

Hey Jens and LuciaIglhaut,
two things:
Do you know of a way to group participants with non-numeric IDs? I am using Prolific (for the first time) and I believe they don’t use a simple incrementing number as ID.

and for Lucial:
once you used the Code of Jens, you need to use the variable (in this case stimfile) in the conditionsfile of a loop. like this: $stimfile
it is necissary, that all of the variables in the .xlsx are called the same and is kind of prone to errors.


Hello Becker,

sorry, I have use Prolific, but you find suggestion on how to use Prolifc and Pavlovia in the forum

Best Jens

1 Like