Randomization
Hi,
I am designing an experiment that has 3 IVs : Incongruent vs. Congruent shapes, Audio (Silence, 120 bpm, 240 bpm), and Angle of rotation of the shapes (0, 50, 100, 150), giving me 24 unique trials. I have a total of 96 different images that account for 4 unique sets of the visual IVs. I would like to present all 96 of these stimuli in random order, but I also want each image to be randomly paired with one level of the Audio variable, so that no two participants experience the same trial order and paired image and sound combination. I am sort of stuck trying to figure out if this level of randomization is doable using the block loops, or if this would require changes to the script, addition of blocks, etc... Any assistance would be great. Thank you. I can definitely provide more information, if needed.
Comments
Hi @Tpatrick,
I'm not sure I understand your description.
You seem to have a 2 x 3 x 4 design, yielded 24 trial types that you want to present 4 timees each, leadiong to a total of 96 trials. You have 96 pictures that you want to allocate randomly to these 96 trials, Is that correct?
If so, my recommendation would be to build your loop with the 96 trials, coding all three IVs as you want them to ensure full orthogonality (and setting the loop to select rows randoly).
Regarding the pictures, you'd need to use some coding to create an array containing the 96 picture file names, shuffle that array (all of this before the loop). Then, in your trial sequence, set up a variable that counts the trials and use it to pull individual elements from the array to indicate to the task which picture to show. That would result in a random allocation of the pictures to the 96 trials, different every time the task runs.
Hope this helps,
Fabrice.
Hi Fab,
Yes. That is correct.
Does this code look correct?
Additionally,
I am trying to evenly distribute 3 audio files throughout the 96 images. So each audio file is paired with 32 trials (randomly). I am having some trouble getting the audio track to stop when a key is pressed. Does this require code to halt the audio and move onto the next trial when a response is provided?
Thank you for your response.
This is the code I attempted to use to get the audio to stop when either the i or c key is pressed. I am getting the following error message:
Inline script, line 5, in <module>
AttributeError: 'str' object has no attribute 'start'
Hi @Tpatrick,
I'm still not clear as to what you're trying to achieve exactly (I don't really follow your design). In any case, print screens of code don't really allow me to comment. Your first screen shot shows arrays but I'm not sure what you do with this later in the task. Doesn't look like you're actually storing the images in an array that you shuffle. I'd still recommend the method I described earlier (though again, I'm not sure what you're actually trying to do; but in case, you'll need to do some coding to resolve it).
As for the sound, I don't typically use Python code for this, so I can't really comment. But the error seem to suggest that you haven't defined the sound object.
Best of luck,
Fabrice.
Hi Fabrice,
I apologize, allow me to explain more clearly. I am creating a classic mental rotation task. The images are 1/2 incongruent (48) and 1/2 congruent (48) and within each set they are made up 12: 0 degree difference, 12: 50 degree difference, 12: 100 degree difference, and 12: 150 degree difference. My other IV is audio made up of: Silence, 120 bpm ticks, and 240 bpm ticks.
My hope was to randomly present the different images, but also randomly (but evenly) pair them with the different levels of the audio. I want to present the image and the audio together and have the participants press either 'C' for congruent or 'I' for incongruent. I am trying to set it up so that the trial ends (both the audio and image stop) and moves on to the next trial (new image and new audio) when a key is pressed.
Where I am running into difficulty is 1) figuring out how to randomly present the images and randomly pair the images with the audio and 2) getting the complete trials to end when the appropriate key(s) are pressed.
I am going to continue chipping away at it, but to be honest I have little experience coding, so its an uphill battle right now. Any guidance would be much appreciated.
Thanks again!
Hi @Tpatrick,
Your description seems to fit my prior understanding. You have 4 times (2 x 4 x 3) = 96 trials and you want to allocate 96 images to these 96 trials in a random manner.
So, the method is that I described earlier: creating an array with the 96 file names, shuffle it, then pull out elements one by one as your trials run. One simple method is to implement a counter, increment it in every trial, and use it to pull the nth element of the array.
As for starting a sound and stopping it when a key is pressed, I'd run the following code in the trial sequence:
For this to work, you must have a variable called
sound_filein your loop and it must contain the name of the sound file (which must be present in the pool).Then I'd insert the sketchpad with the stimulus you want to show (duration=0), a keyboard object, and right after the keyboard object, I'd run the follwing code to stop the sound:
Hope this helps,
Fabrice.
Hi Fabrice,
Thank you. This is definitely moving me in the right direction. Does this still apply if I have 3 different sound files that I will be selecting randomly? I created the variable sound_file in the loop and within that variable are the file names contained in my pool (0.wav, 120.wav, 240.wav) In the sampler under sound file I have [sound_file].wav to indicate that I want to call these different files. After entering the code above in the prepare and run phases, respectively, I am getting an error saying "sound_file is not defined". I am not sure what is off. I am going to continue toying with it but currently this is my issue.
I've tried using the inline script to randomly call both the images and files throughout the actual experiment. But its telling me that none of the images in my pool exist. I know there is a disconnect somewhere, but I can tell I am spinning my wheels trying to make sense of the most minor errors.
Just to reiterate, in the experiment, I would like each image to be shown in random order, but only once. I would also like each image to be randomly paired with 1 of the .wav files. I would like the audio and the image to go away once a key press is made, recording the response time. This seems like a basic design, but I am struggling. Would you mind looking at what I have so far? I think that would help clarify any ambiguity that exists from trying to put this into words. Any guidance would be great. Please don't do it for me, but if you have any insight into what is wrong with the script or general setup that would be so helpful.
Thank you
Hi @Tpatrick,
If you get the message that the picture is not in the pool, print to the console the actual content of the variable you're using to retrieve a specific picture and check that it is correct. If the string OS uses to retrieve the picture is correct, then it must be that you did not include the picture in the pool.
As for the presentation of the images paires with sound files, it's a matter of setting up your loop and if needed populating it in real time from an array (which requires coding as explained earlier, or some variation of it, depending on what exactly you want to do).
To stop the sound and image when a key press has been registered, you simply need to insert the next code stopping the sound right after the keyboard event, as well as whatever sketchpad you want to appear after a key press.
Good luck,
Fabrice.