psychopy.org | Reference | Downloads | Github

Randomizing trials

Hi. I am designing an experiment as follows:

32 control trials, 32 experimental trials (only one block of encoding where all 64 trials will be presented). 16 of the 32 trials in the control phase are voluntary and 16 are mandatory, and the same goes with the experimental condition. The experimental trials have faces and names presented, along with a money transfer (+30 to participant -30 to face). The participant see the screen with the names and faces on it for 9 seconds, then writes down the name of the face they just saw as an attention check. Then they see the transfer details and accept or reject the transfer in the voluntary condition or if it is the mandatory condition they can acknowledge or click invalid but the transfer will happen regardless. These are fictious transfers. At the end, there is a surprise memory test where we present the faces and ask participants to recall their names.

I have two sets of face/name stimuli. In the experimental phase, I would like them to remain constant (I always want specific faces to be matched with specific names). This is no issue as psychopy already does that. However, I do not want a specific face to be matched with the 32 transfer amounts. I want the transfer amounts to be randomized across the face-name pairs. I have no experience with coding, I do not even know how to use the code runner. How can I randomize the transfer amounts? In addition, is there any way to do this without coding?

Hi There,

OK here is just one way you could achieve this.

  1. Make an excel file that lists your 32 transfer amounts.
  2. Add a routine called load_transfers
  3. Add a loop around this routine and add the excel file with the transfers to the conditions field.
  4. Add a code component to your load_transfers routine, In the Begin Experiment tab type: transfers = [] in the Begin Routine tab type transfers.append(transfer) where transfer is the column header from your spreadsheet. In the End Routine tab type shuffle(transfers)
  5. OK now in your main trial routine just use the conditions files with the face stimuli as the conditions file.
  6. Add a code component to the trial routine. In the Begin Routine tab type thisTransfer = transfers[-1]#sample the last transfer from the list followed by transfers.pop()#remove the last sample from the list - then just use the variable "thisTransfer wherever you need it.

From this you will have a set of face-name pairs that are presented with a randomly selected transfer amount.

Hope this helps,
Becca
PS. you can find more info on randomisation with constraints in builder with our workshop materials Randomising with constraints — Workshops for PsychoPy 2020 2020

Thank you so much for replying! I did what you suggested, but instead of putting in the word transfer, i used SelfGain and Charitygain as these are the variables in my spreadsheet (I attached it here). However, I keep getting this error message that I have attached here. I also attached the way I added the loop to make sure it’s consistent with what you said. I have my transfers presented at the same time as the faces so I am confused on what to actually put on the load transfer screen because right now my transfers are on my voluntaryencoding screen.



Also I did split up the spreadsheet into transfers and faces as you suggested I just attached the master spreadsheet here for reference.

Great to see it helped so far! is the code where you call SelfGain definitely in the Begin Routine tab and not Begin Experiment?



I don’t think it is in the begin experiment. Here are the codes for the load_transfer screen, and the maintrial screen