 #### Howdy, Stranger!

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

Supported by

# Counterbalancing stimulus positions

Hello,

I'm trying to present two pictures simultaneously, counterbalancing their positions across participants.

In the trial, the two pictures are presented simultaneously after a fixation. One is presented in left side, the other is in right side.
Each picture should be presented just once, so half of participants will see the picture1 in left side, the other half will do in right side. Further, half of pictures are target stimuli and the other half are distracter stimuli, and they should be always paired. So participants see the target in either left or right side.

I was able to make just the trial sequence and present stimuli by `stimuli.canvas` function.
Now I think about using `balanced_latin_square`function or Expyriment's example code of simon task.

Are there any better ways or suggestions?

Thanks

• edited January 2017

Hello,

I made a script without using `balanced_latin_square` function as below.
In the script, the positions are just randomized but not counterbalanced.

``````########### EXPERIMENTAL DESIGN ####################
#import 2 lists of image file#
#randomizing the two lists#
listAB = [[i, j] for i, j in zip(listA, listB)]

list_former = [listAB[j - 1] for j in random.sample([i + 1 for i in range(len(listAB))], int(len(listAB) / 2))]
list_latter = [[i, i] for i in tuple(set(map(tuple, list_former)) ^ set(map(tuple, listAB)))]
list_former.extend(list_latter)
all = [list_former[i] for i in random.sample(range(len(list_former)), len(list_former))]

listLEFT = [z for z in all]
listRIGHT = [z for z in all]

t_fix = 1000
######### INITIALIZE ##############
control.initialize(exp)

fixcross = stimuli.FixCross()

block = design.Block(name="block_all")
for (l, r) in zip(listLEFT, listRIGHT):
trial = design.Trial()
trial.set_factor("Left_im", l)
trial.set_factor("Right_im", r)
canvas = stimuli.BlankScreen()
l_image = stimuli.Picture(l, position=(-200, 0))
r_image = stimuli.Picture(r, position=(200, 0))
l_image.plot(canvas)
r_image.plot(canvas)
block.shuffle_trials(block)

exp.data_variable_names = ["block", "trial", "Left_im", "Right_im", "Key", "RT"]
######### START ##############
control.start(exp)

for block in exp.blocks:
for trial in block.trials:
fixcross.present()
exp.clock.wait(t_fix)
canvas.present()
btn, rt = exp.keyboard.wait([misc.constants.K_LEFT, misc.constants.K_RIGHT])
exp.data.add([block.name, trial.id, trial.get_factor("Left_im"), trial.get_factor("Right_im"), btn, rt])
``````

In this case, the two images presented in each trial are always same while the exported data shows the images in left and right sides changed correctly every trial.

Is there any way to counterbalancing the positions across participants, and what is the cause that the same stimuli are presented?

Thanks

• Can you provide a working example?

• edited February 2017

Hi,

I found the cause of same stimuli.
It was caused by `canvas.present()`. It runs as below by changing `canvas.present()` to `trial.stimuli.present()`.

``````        block = design.Block(name="block_all")
for (l, r) in zip(listLEFT, listRIGHT):
trial = design.Trial()
trial.set_factor("Left_im", l)
trial.set_factor("Right_im", r)
canvas = stimuli.BlankScreen()
l_image = stimuli.Picture(l, position=(-200, 0))
r_image = stimuli.Picture(r, position=(200, 0))
l_image.plot(canvas)
r_image.plot(canvas)
block.shuffle_trials(block)

exp.data_variable_names = ["block", "trial", "Left_im", "Right_im", "Key", "RT"]
######### START ##############
control.start(exp)

for block in exp.blocks:
for trial in block.trials:
fixcross.present()
exp.clock.wait(t_fix)
trial.stimuli.present()
btn, rt = exp.keyboard.wait([misc.constants.K_LEFT, misc.constants.K_RIGHT])
exp.data.add([block.name, trial.id, trial.get_factor("Left_im"), trial.get_factor("Right_im"), btn, rt])

####### END EXPERIMENT ########
control.end()
``````

I'm still looking for the clear way of counterbalancing the positions across participants.
Are there any suggestions?

Thanks!

• How about creating a between-subject factor "picture_arrangement" with two levels ("x_is_left", "x_is_right"):

``````import expyriment

exp = expyriment.design.Experiment("My Experiment")
And then later in the experiment (after calling `expyriment.control.start()`, i.e. after a subject ID has been entered):
``````if exp.get_permuted_bws_factor_condition('picture_arrangement') == "x_is_left":