How can I go from one routine to another in a probabilistic way?

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 1.85.2
Standard Standalone? (y/n) yes
What are you trying to achieve?:

Hi,

I am making self-paced reading task. I want to make participants read sentences (e.g. Judy met Tom last Saturday) and with a 20% chance, I want them to solve probe question (e.g. Did Judy meet Tom last Saturday?) with yes or no answer. I made two different routine, one for reading sentences, and another for this questions. Sentences and their relevant probe questions are all stored in one EXCEL file but two different routines recruit two different columns with sentences and probe questions respectively. I made everything else go well but the current design makes participant meet this probe question 100% of the trials.

image

Long story short, I want to make that ‘trial1’ routine to go to ‘probe1’ routine 20% of the time participants solve it. For 80% of the time, I want them to skip the ‘probe1’ and go to ‘cross1’ routine which shows them fixation cross.

Thank you for reading!

Hi, this will take a little code. On each trial, get a random number and use it to control which routine runs.

Insert a code component on the first routine. In its “end routine” tab put something like this:

if random() >= 0.8:
    option = 'probe'
else:
    option = 'cross'

thisExp.addData('option', option) # save to data

Then in a code component on the probe routine, put this in the “begin routine” tab:

if option != 'probe':
    continueRoutine = False

Similarly on the other routine:

if option != 'cross':
    continueRoutine = False

Hi Michael,
Thank you for your reply.

I adopted this and it doesn’t work properly. What I found out was that most of the time, the fixation cross ‘cross’ disappears from every trial and there is probe appearing every trial. I think this random number defined at the initial trial is somehow fixed. And it is fixed higher than 0.8 everytime. Below is the ‘option’ column of the data after I ran a few trials.

I already have code component in the ‘trial1’ routine. Its ‘Begin Routine’ and ‘Each Frame’ tab is filled with some codes but there was nothing in the ‘End Routine’ tab before I put this code in. I don’t think they interacted each other. I also tried creating an additional code component with only ‘End Routine’ filled with your code so that there will be two separate code component in the ‘trial1’ routine. But this did not change anything. I don’t think there is a problem with codes in other routines (‘probe1’ or ‘cross1’). Why would the random number not change? And why is it fixed to probe all the time? I wonder…

Just in case that it is something to do with loop, I attached this capture. It shows how I set the parameters in the loop.

image

Best,
Kyung-Hwan

Sorry, I typed that post on an iPad which was a bit laborious, and there was a typo in the code (now amended). In particular note that if random should have been if random()

1 Like

Oh, why did I not catch that?

It works beautifully!

Thank you very much.