#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

# counterbalancing 4 blocks

hi,
I am quite new to OpenSesame, so I am currently doing an experiment that involves in 4 block, and I am trying to counter-balance the order of the blocks, which should have 24 different combinations. I have watched the counter-balancing tutorials, and I only have 4 combinations after followed those steps mentioned in the video, so could someone help?

many thanks

may

• Also, how can the results file comes out with a clear structure, for example, with block names?
• Hi,

For this, you need to do a few things:

• First get all possible orders of the four blocks. You can do this with `itertools.permutations()`.
• Then get one order (from all possible orders) based on the `subject_nr` variable
• Use this order to define four variables: `block1`, `block2`, etc.
• And then use these variables to determine which block is executed first, second, etc.

This probably sounds a bit abstract, but it's not that complicated. I attached a simple example.

Cheers!
Sebastiaan

• edited April 2020

Is `psychopy.tools.itertools` deprecated? In favour of what?

If so, why is it not MOVED to removed folder, like `iohub`'s deprecated modules?

• @sebastiaan Can you please attach the example you said you would attach???

• I need your example too. Can please attach it if you still have it?

Thanks a lot!

• Hi @SezerReng and @VictorVarela ,

Here is the example again. (Some attachments got lost during a server crash some time ago.)

The crucial part is the script in init_counterbalancing item. This gets the block order based on a permutation of all possible block orders and the subject number.

```import itertools as it

# Gets a list of block orders, where each block order is itself a list
# of the four block numbers, e.g. [3, 2, 1, 4]
all_block_orders = list(it.permutations([1, 2, 3, 4]))
# The current block order depends on the subject number, while wrapping
# around so that participant 0 and 24 have the same order
current_block_order = all_block_orders[var.subject_nr % len(all_block_orders)]
print('block_order = {!s}'.format(current_block_order))
# Assign the block orders to these variables, which will be used in the
# loop table of counterbalanced_loop
var.block1, var.block2, var.block3, var.block4 = current_block_order
```

Good luck!

— Sebastiaan

• Sorry for the late reply Sebastiaan,

It worked really smoothly, thank you so much for your solution!

Best regards,

Sezer