I was wondering if anyone could help guide me on how to do the following for an experiment I am making using PsychoPy:
I want to make it so that participants must get 80% of practice trials correct before they can progress to the main experiment. Is this possible?
Is there a way to randomise the order of conditions? I am using three experimental tasks and what each participant to undertake a random order following completion of the practice trials.
I imagine you’d have to do both of these in Coder view but if it’s possible to do this in Builder view, that would be great to know!
You can achieve the first by using a while loop. I am not familiar with Builder, but this should be doable. If you want to try it with coder you could have a look at this thread about the same issue:
Regarding the second, just wrap your three tasks in a forloop, and add an if / else if / else statement that determines your three experimental conditions. Then loop through trials in that experimental condition.
I just proposed a solution to a very similar question to this, you can download the experiment and give it a good hard look, because conceptually it’s the same.
In Builder, you could do something along the following lines:
Add a code component to your trial
In “Begin Experiment”, add the following:
respcorrs = []
minNrPractice = 25 # min number of trials to practice
considerNrTrials = 20 # number of trials to consider for accuracy calculation
minAccuracy = 0.8
In “End Routine”, add:
respcorrs.append(resp.corr) # assumes your keyboard component is called "resp"
if len(respcorrs) >= minNrPractice:
respcorrsRecent = respcorrs[-considerNrTrials:]
respcorrsSum = sum(respcorrsRecent) # only works if error=0 and correct=1
accuracy = float(respcorrsSum)/considerNrTrials
if accuracy > minAccuracy:
break
Thanks for your help! I put in the code but the problem I’m now having is that it has become an infinite loop. Even if you get five trials correct, it just keeps going. I want it so that once the participant has got a minimum of 4 trials right, they can progress. Any recommendations for how to solve this?
Also it be nice to include a message at the end of the five practice trials that says ‘Sorry but you need to… etc., etc.’ - any idea how to include this into the loop?
You should remove the second loop around your practice trials, and increase the number of repetitions for your first loop (to 10, or whatever; it doesn’t really matter as the loop should be interrupted when a sufficient accuracy is achieved). Alternatively, you could also introduce more trials in your practice file.
When I said that error and correct need to be coded as 0 and 1, respectively, I meant that the code for an incorrect response needs to be 0, and the code for a correct response 1. This is the default in PsychoPy, so you don’t really need to change/add anything. I only mentioned it because I tend to use different codes in the Coder.
This appears to have fixed it, thanks so much. Spent about 20 hours trying to figure all this out! I don’t suppose you could give me some guidance as to how to add a final feedback message i.e. once 5 trials have passed, if you have less than 80% accuracy, a message appears saying ‘You need to improve’?
To clarify: Right now, you only take accuracy, but not RT into account. If a participant gets all trials correct, but never has an RT below 700 ms, they will progress. Is this what you want?
If participants get 80% accuracy (i.e. 4 out 5 trials correct), they progress.
If participants don’t react fast enough, they get given a message saying they’re too slow.
In the event participants get less than 80% accuracy, either as a result of incorrect responses or through being too slow, they receive a message telling them they’ll have to repeat the practice trials until they get 80% accuracy.
Perhaps. So, slow correct responses should basically be treated as errors, right?
While possible, in my view, you don’t really need that extra message. Why don’t you simply tell your participants that the practice will end once they achieve an overall accuracy of 80%? I mean, it’s not like it will take them another 20 minutes or so if they don’t get it right after five trials…
But this also means that the current code is not going to work! Could you change your “Begin Routine” code to this?:
if resp.rt < 0.7 :
dur=1.0
if resp.corr:
msg="Correct!"
respCorr = 1
else:
msg="Incorrect!"
respCorr = 0
else:
if resp.corr:
msg="Correct, but too slow!"
respCorr = 0
else:
msg="Incorrect AND too slow!"
respCorr = 0
(I’ve deleted the unnecessary “dur” definitions. When I did the task, I found the “Valid trial” feedback more confusing than helpful, so deleted this also.)
And then replace this:
It seems to work but the issue I’m now having is that the loop doesn’t reset if you get too low an accuracy score. Any suggestions for how to fix this?
Ah, you mean the practice stops even if though the accuracy is low? Could you upload your current code? (I was initially a bit confused because nothing is actually reset in the code.)