# Counterbalancing three lists of words

Hi everyone,

I just recently started working in PsychoPy and I have an issue with counterbalancing 3 lists of words. My experiment goes like this:

There’s 3 lists of words that I saved in Excel. I want the participants to get the first list of words, then they’ll have a recall phase and go to the 2nd list of words, then 2nd recall phase, then the 3rd list of words, and the 3rd recall phase.

So far I managed to program it with one list of words, where it chooses randomly from the three options. My goal is to do that with all 3 lists, so they’ll learn 3 times, each time with one of the 3 lists so that the lists don’t repeat themselves.

This is the code I have so far:

import random
random.seed()
condition = random.randint(1,3)
counter1 = 0
counter2 = 0
counter3 = 0

if condition == 1:
counter1 = 1

elif condition ==2:
counter2 = 1

else:
counter3 = 1

This is a screenshot of how it looks like for what I have now:

I would really appreciate any help and as simple of an explanation as possible, since I’m just a beginner in the program. Thank you!

The order of the lists I’m trying to achieve would be 123, then 312, then 231

I’m not entirely sure if this is what you want but how about

``````conditions = [1,2,3]
shuffle(conditions)
``````

and then

``````condition = conditions.pop()

counter1 = 0
counter2 = 0
counter3 = 0

if condition == 1:
counter1 = 1
elif condition ==2:
counter2 = 1
else:
counter3 = 1
``````

This will give your three conditions in random order with no repetitions.

Thanks for replying! I tried this, but it didn’t change anything so I think this is actually what I have right now. My idea is that condition 1 would be lists 123, condition 2 would be lists 312, and condition 3 would be lists 231.
They would first be given the 1st list, then recall, 2nd list then recall, and 3rd list then recall, and that would be condition 1. So depending on the condition I want the list order to change, but in each condition they would see 3 lists of words

Hi,
[UNTESTED]

1. at the `begin` routine (to the left of `wordlearningC3`) add a code component and modify wakecarter’s code a bit
``````conditions = [1,2,3]
shuffle(conditions)

condition = conditions.pop()

counter1 = 0
counter2 = 0
counter3 = 0

if condition == 1:
counter1 = 1
counter2 = 0
counter3 = 0
elif condition == 2:
counter1 = 0
counter2 = 1
counter3 = 0
else:
counter1 = 0
counter2 = 0
counter3 = 1
``````
1. create another routine after `wordlearningC3` (but outside the loop `condition3`) and only add a code component that will include the above code without the first two lines i.e. without `conditions = [1,2,3]` and `shuffle(conditions)`
2. surround the three `worldlearning` routines and the routine you create on step 2 in another outer loop and set as number of repetitions to 3

Again untested, just on top of my head.

BW
Yiannis

Hello,

and a further suggestion: I understood that you want all three lists to be presented. So modify the code suggested by Yiannis to

``````if condition == 1:
list1 = "list1.xlsx"
list2 = "list2.xlsx"
list3 = "list3.xlsx"
elif condition == 2:
list1 = "list3.xlsx"
list2 = "list1.xlsx"
list3 = "list2.xlsx"
elif condition == 3:
list1 = "list2.xlsx"
list2 = "list3.xlsx"
list3 = "list1.xlsx"
``````

Then use the variables list1 to list3 as a condition-filename (\$list1, \$list2, \$list3) in the loop counter1 to counter3. If you want to run the experiment online, you need to add the files lis1.xlsx to list3.xlsx as additional resources via the Online tab in Experiment properties. You should also save the list-order to your result file.

Notice that this counterbalancing does not guarantee an even distribution of the three orders across participants in either an online nor an offline-experiment. It just generates three different orders.

Best wishes Jens

1 Like

Thank you everyone for the suggestions!
So I actually experimented a bit and this something else and although the order is working, the words don’t seem to show up on the screen.
First, I created two loops like this:

I created an excel file that I named List_main and then I created one column in that file that looks like this:
Listmain
list1.xslx
list2.xslx
list3.xslx

In the textbox component for wordlearningC1 I wrote \$Listmain, then for the condition1 loop I specified this:

I know there is an error in the conditions and I’m not sure how to fix that.

For loop1 I just specified random, nReps=1 and in conditions I imported the List_main.xlsx file that I mentioned above

So what is happening right now is that once I run it, instead of showing the words from the list, it just shows “list1.xslx”, “list2.xslx” and so on, on the screen. I thought that specifying those file names in another excel file would work, but it doesn’t seem to read the actual lists of words. Is there anything that I’m missing?

I would really appreciate any help.

\$Listmain goes in your loop (ignore that error message). In the text component you need the column title that appears in your three lists (e.g. Item but definitely not Listmain).

It worked, thank you!