Randomize 2 variables with several levels
Hello,
I am currently programming an experiment in which I want to present a list of 36 words. In this list, 12 words are positive, 12 negative and 12 neutral. I have another variable which is the value of the word (high vs low), which means that I want each word to be randomly paired with a number between 1 to 5 (low) or 8 to 12 (high). Additionnaly I need to counterbalance the proportion of high vs low value word between each emotionnal condition (half of positive words with high value and the other half with low value).
Is there any simple way of doing so ?
With E-Prime I used the nested lists functionnality, but I can't fin a way to easily programm my experiment with Open sesame.
Any idea would help :)
Comments
Hi @Naïde ,
Since you have only ten numbers (and twelve words per emotion), I assume that you want to randomly sample from these numbers with replacement. If so, then it's actually quite easy, because you can simply create a
looptable with three columns:word,emotion('positive', 'negative', or 'neutral'), andvalue('high' or 'low'). Then at the start of the trial sequence, you insert aninline_scriptwith a short piece of code in the prepare phase to actually set thenumbervariable, like so:import random if value == 'low': number = random.randint(1, 5) else: number = random.randint(8, 12)Does that make sense?
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi @sebastiaan
Thank you very much for your help. The code works perfectly to randomly assign a number. The problem is that I also want to randomize the high / low value for the words. For instance I want the first positive word to be either low or high value across participants.
I tried to creat one loop table with 3 columns corresponding to the 3 emotional conditions (positive / negative / neutral), and then a sub loop table with a full factorial design leading to 6 conditions (positive-high, positive-low, neutral-high, neutral-low, negative-high, negative-low).
Before these loops I placed the following inline_script to define the value (high/low) and randomize the numbers
import random
low=random.randint(0,5)
high=random.randint(8,12)
Now I would like to
1/ randomly assign a value high or low to each word
2/ counterbalance the proportion of high / low value words within each emotional condition (e.g. 50% of positive word with high value and 50% with low value)
I tried to import pseudorandom tu use the constrain function but it doesn't work. Opensesame indicates that pseudorandom is imported but not used.
I am sorry for these basic questions, I am a new user of opensesame and not familiar with Python (it took me a while to figure out how I could import the random plugin...)
Again, thanks a lot for your answer and your help :)
Hi,
See attached experiment for a demo how you can accomplish this with Python coding.
Essentially I create the stimuli once per block, and then access them one by one in the trials. When doing that that I get 36 words, 12 in each valence condition and of these 12, 6 with a high number and 6 with a low one. That's what you want, right?
Eduard
Hi @eduard
Your programm is wonderful, the randomization is perfect !!
Thank you so much for your help ! 😀
The only issue I have now is that among the 12 words of each valence condition, some are presented several times while some do not appear. Is there a way to tell the programm that once a word has been presented it must not be presented again in the following block ?
@eduard
Finally it works perfectly for me, you saved me a lot of precious time !
Thanks again !