# Counterbalancing

**URL:** <https://discourse.psychopy.org/t/counterbalancing/5969>\
**Category:** Builder\
**Created:** [November 29, 2018, 5:59am UTC](https://discourse.psychopy.org/t/counterbalancing/5969 "2018-11-29T05:59:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leorelizur](https://avatars.discourse-cdn.com/v4/letter/l/eada6e/32.png) [@leorelizur](https://discourse.psychopy.org/u/leorelizur)\
**Post date:** [November 29, 2018, 5:59am UTC](https://discourse.psychopy.org/t/counterbalancing/5969/1 "2018-11-29T05:59:24Z")

</div>

Hi,

I am running an experiment where participants see two images presented side by side on the screen. An image is paired with either a neutral or a negative image and I am trying to counterbalance which images will appear with the neutral and which will appear with the negative. Basically, in one trial I was 30 images to be paired with negative images and in the next trial those same 30 images to appear with the neutral images.

I have tried to follow the counterbalancing code from the PsychoPy manual but am confused about how to include the `$"group"+expInfo['group']+".xlsx"` text.

So far I have set up my experiment like this:

 ![Capture](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/5/45024fbc61b2222fd831a6582b09701625aa9709.jpeg)

With the ‘BOSSandNAPS’ loop box like this

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/c/9c411837789afc33a7ac341daad733d7327befdd.png)

and the ‘trial loop’ box like this

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/c/2c50299d13f57531738e9190c2461ea993659d8b.png)

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [November 29, 2018, 9:01pm UTC](https://discourse.psychopy.org/t/counterbalancing/5969/3 "2018-11-29T21:01:42Z")

</div>

> [@leorelizur](#):
>
> I have tried to follow the counterbalancing code from the PsychoPy manual but am confused about how to include the `$"group"+expInfo['group']+".xlsx"` text.

You need to explain to us what you are trying to achieve. Do you have two conditions files you want to switch between? If so, what are they called? Are they presented in random or constant order?, etc etc.

---

<div class="post-metadata">

**Author:** ![leorelizur](https://avatars.discourse-cdn.com/v4/letter/l/eada6e/32.png) [@leorelizur](https://discourse.psychopy.org/u/leorelizur)\
**Post date:** [November 30, 2018, 12:38am UTC](https://discourse.psychopy.org/t/counterbalancing/5969/4 "2018-11-30T00:38:24Z")

</div>

Yes, there are two condition files and I have made a third excel file to call upon each of the excel files with the images.

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/8/f8cf2240b01fdf6c96edf997a3540ab5bb749d3c.png)

When I did this, the program would show the BOSSCritical and NAPS Pairing.xlsx first and then BOSSCritical and NAPS Pairing Second Counterbalance.xslx second.

BOSSCritical and NAPS Pairing.xlsx

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/6/b6408be2d9d44d34b53a60562874baed42940c38.png)  
BOSSCritical and NAPS Pairing Second Counterbalance.xslx  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/2/82d377bd4783eca08563917a811793ec9438a323.png)

What I want, instead, is that for one participant BOSSCritical and NAPS Pairing.xlsx will be presented and for the next participant BOSSCritical and NAPS Pairing Second Counterbalance.xslx will be presented (the only difference between the BOSSCritical and NAPS Pairing.xlsx file and the BOSSCritical and NAPS Pairing Second Counterbalance.xslx file is that just the second column of images is flipped). I want it to alternate between the two mentioned excel files for each participant.

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [December 2, 2018, 4:00am UTC](https://discourse.psychopy.org/t/counterbalancing/5969/5 "2018-12-02T04:00:15Z")

</div>

> [@leorelizur](#):
>
> I want it to alternate between the two mentioned excel files for each participant

You should be wary of conditions that alternate between participants: this can lead to systematic confounding (e.g. one order more likely to be presented in the morning than in the afternoon, etc). It is more secure to randomly shuffle the order across subjects.

If you don’t care about exact balancing, you can simply set the outer loop to be randomised: then roughly half of your subjects will get each order.

If you want to strictly control the balancing so exactly 50% get each order, then make two conditions files, identical except for the order of the two rows. Then instead of a fixed filename in the loop dialog, use a variable from the info dialog (i.e. on each run of the experiment, enter the file you want to use).

e.g.

```
expInfo['condition_file']

```

Lastly, get rid of all the absolute paths inside your conditions file. They only cause you pain. Use relative paths instead (and `/` separators rather than Windows-style `\`, which can also cause strange side effects in Python).
