psychopy.org | Reference | Downloads | Github

Randomly assign participants to trials

OS (e.g. Win10): Win 7
PsychoPy version (e.g. 1.84.x): 1.85
**Standard Standalone? yes

Hi. I have two question regarding randomization of trials.

  1. How can I design my trials so that participant will be presented randomly with one of the “trial1/trial2” routines? In other words, how can I assign subjects to different trials?

  2. When I assign participants in one of the trial (trial1 or trial2), in the next routine, they need to retrieve what they have been presented in the “trial1/trial2” routines. How can I define the correct answer so that psychopy know a given participant was presented with one trial and calculate the correct answer based on that?

Is it possible to do all these just in builder view?

Thank you.

We don’t know what “trial1” or “trial2” means in this context, and how they relate to “the next routine”. You really need to describe your experiment in more detail for us and ideally provide a screenshot of your experiment flow panel.

Dear Michael, thanks for your time.

This is how I create my flow panel. I’m not sure it is correct or not, but this is how I wanna to execute my experiment.

In fact, participants will be assigned to a 2*2 conditions (load 1 trial 1/ load 1 trial 2/ load 2 trial 1/ load 2 trial 2). I asked you before about the detail of the routines and I am working on it based on your perfect guides. But here I need to randomize my trials. Thus, I have 2 question here:

  1. How can I create the experiment so that participants randomly be presented with a given trial?

  2. How can I tell Psychopy that in the last routine (Working Memory) which answer is a correct answer based on the previous exposure to load 1/ load 2 routines?

I know that I need to write some lines of codes for this problem and the dot pattern which I asked you already, But could you introduce some references to learn programming effectively? I already watch 2 courses of Bucky Roberts about Python on Youtube and a Python programming on Coursera. But I still have problems to write codes in Psychopy. I also watched every Psychopy tutorial on the internet and practice with some demos. Thus, I think I have a good understanding of the builder view. So, how can I improve my knowledge of coding?

Thank you

What you need to do here is modify the experiment settings dialog that opens at the start of each session so that you can enter some variables to control which conditions will appear. Click the experiment settings icon on the toolbar and push the ‘+’ button to add a field to the experiment info. e.g. a field called load_condition with a default value of 1 and a field called trial_condition with a default value of 1. When the experiment runs, enter the appropriate values in each of those boxes (1 or 2 as required).

Then you can control which routines run on a given trial. For an isolated routine, this is easy. In a code component, put this in the Begin routine tab:

# load1 routine: only run if the condition is 1:
if load_condition != 1:
    continueRoutine = False

And similarly for the load2 routine.

For routines in loops, you need to terminate the loop as well as prevent the routine running:

# trial2 routine in trials loop:
if trial_condition != 1:
    continueRoutine = False
    trials.finished = True

I’m not sure how you are determining what answer is correct but hopefully you can see how it can be chosen, depending on values for your trial and/or load conditions.