I am programming a psychological experiment.
In every trial, they read a scenario and see a face photo and hear an answer for the scenario.
Scenarios are 20.
And there are 4 conditions for the scenarios. (Happy face-Happy sound, Neutral face-Happy sound, Happy face-Neutral sound, Neutral face-Neutral sound)
Therefore, All trials are 80. (Scenario 20 * Condition 4)
The point is I need to randomize scenario order without repeating stimuli twice in a row.
My problem is that the “random trials” must NOT include consecutive presentations of one scenario.
For example, scenario 1(Happy f-Happy v) → scenario 1(Happy f-Neural v)
Or scenario 1 - 3 - 5 - 6 - 7- 8 - 3 - 4 - 4- 5 - 10
However, I am very new to psychopy/coding and am not sure of how to do this.
Is anyone able to please help guide me in generating a code that will constrain the randomisation process so that no one square/keys be presented consecutively?
This demo presents a new method of randomising a set of trial types without consecutive presentation of the same type. Instead of loading the trials into a list and then shuffling until a suitable order has been created, it skips consecutive presentations and then repeats the loop only selecting those trials. Since there is a danger that doing this on the fly can end up with an insoluble problem (for example, the final two trials are of the same trial type), this method will add an extra trial into the new list. The participant may therefore end up seeing one or two additional trials in the experiment, but they can easily be excluded from the analysis if desired, using column that records the presentation number.
I hope this is the right thread to ask for help with the randomisation without repetition code! I am new to PsychoPy and am coding an experiment using your code for randomization without repetition, but when I run my experiment, I get the following error:
repeatRows.append(useRows[trials.thisIndex]) IndexError: string index out of range
When I check the data sheet that results from the run, I consistently see that the experiment crashes 2-3 trials after trial 63, including skipped trials. I have 64 stimuli divided across 5 different conditions and have useRows currently set to ‘0:65’. Besides changing the variables in the code to align with the variables in my own .xlsx file, I haven’t really modified your code much, so I don’t know how the original demo code manages to avoid this error.
I don’t know if this is descriptive enough, so if not, I’d be happy to add more detail! Thank you in advance!
useRows 0:65 means use rows with indices 0 to 64 and if you have 64 rows they only have indices 0 to 63. Try 0:64 (or leave it blank if you are presenting all trials from the spreadsheet)
I tried replacing 0:64 with [ ] and with 0:65, but I still run into the same error IndexError: string index out of range. Is there something else that prevents this error from occurring in the original code?
I’ve also noticed that not all of my stimuli have recorded responses because of being skipped over, so even though my data sheets show 64 to 66 trials, participants aren’t being shown the same stimuli. Is this part of the code, or is it due to the IndexError?
I don’t have any blank rows in my spreadsheet, but I do have a column that isn’t used for this code in particular (it’s a remnant from another attempt at coding randomization). I used the conditionNo for your code because it wouldn’t accept strings, but the condition variable isn’t used in this randomization at all. The extra rows at the bottom are from copying the table as an image, but there’s nothing that comes after them.