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

Need help for experiment for display randomly narratives across participant

I need to construct an experiment with 12 short narratives, knowing that each narrative has 4 different ending, which means 48 stories. But each participant must read only 12 stories with one type of ending.
I would like to display randomly these 12 narratives with only one of their associate ending across participant and i don’t know how.

Comments

  • fladdfladd Posts: 69

    Dear oriane_g26,

    If I understand you correctly, I would suggest to create 12 different trials and assign each trial a factor "ending", with 4 levels (http://docs.expyriment.org/expyriment.design.Trial.html#expyriment.design.Trial.set_factor). You can then create a corresponding between subject factor (http://docs.expyriment.org/expyriment.design.Experiment.html#expyriment.design.Experiment.add_bws_factor), and use get_permuted_bws_factor_condition() (http://docs.expyriment.org/expyriment.design.Experiment.html#expyriment.design.Experiment.get_permuted_bws_factor_condition) to get the corresponding ending for each participant (assuming you want the same ending for all 12 narratives per participant). This balances the endings over participants.

    To then present the 12 trials randomly, just shuffle the block you put them in (http://docs.expyriment.org/expyriment.design.Block.html#expyriment.design.Block.shuffle_trials).

    Something like this maybe (not tested!):

    import expyriment as xpy
    
    narratives = [{"beginning":"narrative1", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative2", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative3", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative4", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative5", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative6", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative7", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative8", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative9", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative10", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative11", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]},
                  {"beginning":"narrative12", "possible_endings": ["ending1", "ending2", "ending3", "ending4"]}]  # Replace with actual narratives and endings
    
    exp = xpy.control.initialize()
    block1 = xpy.design.Block()
    for counter, narrative in enumerate(narratives):
        trial = xpy.design.Trial()
        trial.set_factor("Narrative", counter+1)
        s = xpy.stimuli.TextBox(narrative["beginning"])
        trial.add_stimulus(s)
        trial.possible_endings = narrative["possible_endings"]
        block1.add_trial(trial)
    block1.shuffle_trials()
    exp.add_block(block1)
    exp.add_bws_factor("Ending", [1, 2, 3, 4])
    exp.add_data_variable_names(["Narrative", "Ending"])
    xpy.control.start()  # This will create a subject ID
    
    for trial in exp.blocks[0].trials:
        ending = exp.get_permuted_bws_factor_condition("Ending")
        trial.set_factor("Ending", ending)
        s = xpy.stimuli.TextBox(possible_endings[ending-1])
        trial.add_stimulus(s)
    
        for stimulus in trial.stimuli:
            s.present()
            exp.keyboard.wait()
    
        exp.data.add([trial.get_factor("Narrative"), trial.get_factor("Ending")])
    
    xpy.control.end()
    

    I hope this helps, let me know if you have any further questions.

    Thanked by 1oriane_g26

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

  • this helps !Thank you very much !
    i have one more question, for narratives can i import stories from a folder or do i write them directly on the script ?

  • maybe this could be efficient...

  • fladdfladd Posts: 69

    I just put them into my example directly in order to demonstrate the principle, but you can of course also read them from a text file.

    Thanked by 1oriane_g26

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

  • Ok, thanks !
    for the selection of the type of ending i need something like random.choice() because the number of each ending correspond to a specific condition (ending1 = condition1, ending 2= condition..) but across stories participant mustn't read only one type of condition.
    I've try to change this by replace s = xpy.stimuli.TextBox(possible_endings[ending-1]) by s = xpy.stimuli.TextBox(random.choice(possible_endings)) but in data i don't have the correct index associate with the type of ending presented

Sign In or Register to comment.