Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

Counterbalancing stimulus positions

rrrrrr Posts: 78

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_squarefunction or Expyriment's example code of simon task.

Are there any better ways or suggestions?

Thanks

Comments

  • rrrrrr Posts: 78
    edited January 15

    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[1], i[0]] 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[0] for z in all]
    listRIGHT = [z[1] for z in all]
    
    t_fix = 1000
    ######### INITIALIZE ##############
    control.initialize(exp)
    
    fixcross = stimuli.FixCross()
    fixcross.preload()
    
    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)
        l_image.preload()
        r_image.preload()
        canvas.preload()
        trial.add_stimulus(canvas)
        block.add_trial(trial)
    block.shuffle_trials(block)
    exp.add_block(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

  • fladdfladd Posts: 69

    Can you provide a working example?

    Florian Krause (Developer)
    http://www.expyriment.org

  • rrrrrr Posts: 78
    edited February 10

    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[0].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)
                l_image.preload()
                r_image.preload()
                canvas.preload()
                trial.add_stimulus(canvas)
                trial.preload_stimuli()
                block.add_trial(trial)
            block.shuffle_trials(block)
            exp.add_block(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[0].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!

  • fladdfladd Posts: 69

    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")
    exp.add_bws_factor('picture_arrangement', ['x_is_left', 'x_is_right'])
    

    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":
        # Present arrangement
    else:
       # Present other arrangement
    

    Florian Krause (Developer)
    http://www.expyriment.org

Sign In or Register to comment.