Create conditional loop based on percentage of response

Hello everyone,
I’m new to PsychoPy (PsychoPy 2020.2.4) and I need some help please.
I’m working on an experiment in which participants have to memorize word pairs. After the memorization phase, they have to complete a Recall Phase. They will see the first word of each pair and have to recall and submit the second word of that pair. I have to questions :

  1. Is it possible to program the experiment in a way that participants who achieve 75% of correct responses can pass to the next phase of the experiment and those who do not achieve 75% of correct responses have to do an other Memorization phase and the Recall phase ?

  2. in the second Memorization phase, words would appear only 3 times (instead of 5, in the first Memorization task). I think this will require creating another loop and not just asking to go back to the previous loop if people have less than 75% but i’m not sure. Am i right ?

Thank you for help :slight_smile:

Just to be clear: You want a memorization section, where they have to get 75% correct to move on to the recall phase. If they get less than 75% correct, they have to restart the memorization phase, but this time they see the words only three times instead of five. Is that correct?

Assuming I’m understanding correctly, here’s what you’ll do:

At the beginning of the memorizing loop, set up a routine with a code component. In the begin experiment tab, make the variables memorizingAttempt = 1 (or something along those lines) and then include all the other code stuff you need for the loop. Then, in the begin routine tab (or wherever you define how many times the words appear), make an if statement:

if memorizingAttempt == 1 :
    numberWordRepeats = 5 #if it's their first time around, they see each word 5 times
else
    numberWordRepeats = 3 #if it's not their first time, they see them 3 times

Then at the end of the loop (but still within the loop), create another routine with a code component and put something like this in the begin routine tab:

if trialNumber == 180 #how many trials your memorizing phase is supposed to have; aka, if we've completed the last trial, do this

    #do the math to get % correct

    if percentCorrect < .75
        memorizingAttempt = memorizingAttempt + 1 #now it is no longer their first attempt
    else
        memorizingLoop.finished = True #end the loop and go continue to recall loop if they got above 75%

Then in the nReps in the loop settings, put a very large number like 99999 so that the loop won’t end before memorizingLoop.finished = True happens.

Hope that helps/makes sense!

Thank You for your answers. It’s not really that : Participants see the Memorization Phase, then they do the Recall test. If they have less they 75% to the Recall Test, they go back to Memorization Phase. It’s 2 differents loops. Maybe your codes can work if Memorization Phase and Recall Test are in the same loop ?
Thank you again

Yes, just make a giant loop around both phase loops and do the same thing. Put the first code in a routine at the beginning of the big loop and the second at the end, both outside of the phase loops.

Dear @sal,

I’m a student working with @Jbruxelm on this experiment. Just to be sure, regarding the flow, is this the way you suggest we should implement our experiment?

Also, we have an Excel sheet with our conditions, i’m sorry to bother you but is not clear for me where we should put the <$target_response> in the builder (we are using a TextBox component that allows the participants to type in their responses in the Recall Test).

Capture d’écran 2020-10-09 à 10.48.57

Thank you in advance and sorry for the bad english,

Lola

It depends on what you put in your codes. That’s where I would put them, but you might want to put another code inside the MemoLoop to tell it how many times they see each word. But if you define that in the beginning code and set nTrials in the MemoLoop settings to the number you define in the beginning code, it should be fine. If you want, you can add me as a guest member to your repository and I can look at the code for you. Or you can post the codes you put in each code routines.

As for the conditions, I believe you would put that in the experiment settings, but I don’t define conditions that way so I’m not 100% sure.

Your English is great–I feel like I’m barely making sense here, and English is my only language… So if something I said is confusing, let me know!

Dear @sal,

I will give this a try, thank you very much for the help. I hope we don’t take up too much of your time.

Best regards,

Lola

1 Like