Balancing number of conditions


I have 3 conditions regarding the match between the color of the 3 items. For every condition, the color of the 3 items is randomly selected. Please see the code attached.

What do I want to do?
I have 96 trials and want participants to see all 3 conditions equally, i.e., 32 each.
How can I do it?

Thank you.

randomizationcode.psyexp (24.8 KB)

In the variable “trial_order”, 1,2, and 3 are repeated 70 times. If I decrease the number for each, the experiment crashes. (The memory item and test item starts mismatching e.g. car is shown but test options are pencil).

Any help is much appreciated.

Thank you

Hello B.D.5

simply set up an Excel-file with your stimuli and conditions and loop your trials over this Excel-file.

I noticed that you set the one code-component of randomizationcode.psyexp to Py. If you want to run the experiment online, you need to set it to Auto → JS.

Best wishes Jens

Hi, thank you for the answer.

The attached file is just to show the code. Since it was too long I could not paste it.

My experiment is fully ready to run. No error. I just want to equally distribute trials to my conditions. Could you please help me doing it with a code? I have solutions including .remove function but apparently it does not work in online.

Hello B.D.5

well, you might not like to read this, but if you use an Excel-file with one column containing your stimuli and another column containing your conditions, you are set.

I am sorry but I don’t understand your problem.

trials = [i for i in range(0, 95)]

cond = [1,2,3]*32

would generate trials from 0 to 95 and the condition (1, 2, 3). You shuffle the conditions get a random succession of conditions over the experiment and then simply loop your your trials.

The code you provided does not help us to understand your experiment and what you want to achieve.

What did you try to distribute 96 trials to 3 conditions and how did that fail?

Best wishes Jens

Sorry, I thought it could explain well.

There is a “trial_order” variable with repeting 1,2,3 integers. I typed them 70 times and shuffled.
In the begin routine everytime curr_item iterstes, the trial_order [curr_item] variable determines the cond number.
However this way the number of conditions were not equally distributed.

Hello B.D.5

when you type 1,2,3 70 times, you end up with 210 trials. I do not see how this relates to 96 trials and 3 conditions?

What does the variable trial_order do?

iterstes = iterates?

Do you have too many trials of one particular condition or does this vary between runs?

Best wishes Jens

Okay let me explain clearer.
Here, I am repeating condition numbers so in every loop iteration I can randomly select one number from this list.

trial_order = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
#begin routine
curr_item += 1 #increase every loop iteration by 1.
cond_n = trial_order[curr_item] 

According to the current trial number (curr_item), the code randomly selects one of the numbers from the trial order to define a condition number.

And based on the condition number (1,2,3) selected from the trial order, I set my 3 item color from the code below (full version is in the file I sent)

if cond_n == 1: #allincongruent
    if Choice [0] == 1:
        thisImage = image1        
        thisImage_color = 'Red'
    elif Choice [0] == 2:
        thisImage = image2
        thisImage_color = 'Purple'

Let’s say cond_n = 1 it means that all 3 item will have a different color. thisImage is Red, thisWord is Blue and thisImagery is Purple.

So in every loop iteration, for 96 trials, the cond_n is randomly determined by the trial_order list.
However, I realized that even though I set curr_item += 1, in every loop iteration it turns to be an odd number 1,3,5,… , not 1,2,3,4…
That is why I need more repeated 1,2,3 in the trial_order variable. Because:
If the trial no is 70 out of 96, the curr_item turns to be not 70 but 139 (i do not know why). However, there is no the trial_order [139] item in the trial order list, I have only 96 items. So, the experiment crushes.

Hello B.D.5

well, that looks overly complex to me. Where and how do you set the variable Choice? When do you use cond_n?

Best wishes Jens

Hello B.D.5

ok, when you experiment crushes you need to find out why. But I think that you are using an overly complex approach. See the attached example which uses an Excel-file to define the three conditions and the stimuli (as you can see it is a Stroop-task). If you set the number of loop-repetitions to 16, you get 96 trials in a random order and each participant see 32 trials of each condition. Adapt the example to your needs.

Cond96.psyexp (11.7 KB)
Stimuli.xlsx (8.6 KB)

Best wishes Jens

1 Like