Howdy, Stranger!

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

Supported by

Help with modifying a script

Here I have an experiment where (with help from this forum)! I was able to have a pair of images appear randomly either on the left or the right and a target image (that matches either the left or the right image) appear on top. The goal of the experiment is for the toddler to choose the match. So if the object that appears on the right matches the object that appears on the top the correct answer would be to touch the right box. As of right now, this works perfectly. Now, I just want to add a trial in between that always uses the same objects. for example:

trial1 uses object_9 and object_10,

trial2 uses object_1 and object 2,

trial 3 uses object_4_5,

trial 4 uses object_1 and object_2,

trial 5 uses object_7 and object_8

trial 6 uses object_1 and object_2 etc.

So between every "random trial" a repeated pair is inserted but the order of those objects would still be randomized. ie object 1 sometimes appears on the left, sometimes on the right and is sometimes the target and the same for object_2.

Could someone help me modify this script to accomplish this? Thank you so much!!


Comments

  • Hi Mollie,

    I think I roughly understand what you're trying to do, but the devil is in the details.

    Could you first explain exactly how you select the stimuli at the moment? What are the constraints? In what sense are you counterbalancing things (as the name of the counterbalancing_1 item suggests)? And how exactly does the script (which is pretty dense) accomplish this?

    Next, could you explain exactly what the constraints are for these repeated trials? E.g. are they sampled from the same set as the other stimuli? How often should they occur? Can they occur twice in a row, etc.?

    Cheers!

    Sebastiaan

  • edited October 25

    Hey Sebastiaan!

    Thank you so much. At the moment the stimuli are paired such that object_5 and object_6 are always together. I have objects named object_5 through object_21.

    That is why I have the stim_match_1 and stim_match_2 part of the script so that those pairs always show up together.

    As of now, there are no repeated objects, which is how I want it.

    Basically, if it randomly selects object_6 that means it must also randomly select object_5 and that if object_5 shows up on the left then object_6 must show up on the right. Then, either object_5 or object_6 will be the top card(target). If the target is 6 then the subject must press the square on the right where object 6 was. (because they are a match).

    Additionally, I do not want the answer to be on the same side more than three times in a row which is the bottom part of the counterbalance_1.

    This is all exactly how I wanted it for the first design.

    Now, I want everything to remain the same, that is the same object pairs should stay together and be randomly assigned left or right and target, the correct answer should not be on the same side more than three times in a row, and the object pairs should not repeat. BUT, I now want one object pair to repeat over and over again and be 'sandwiched' between the non-repeated randomly selected pairs of objects.


    My current design is like so

    object_5 and object_6

    object 19_ and object_20

    object_9 and object_10

    Until 8 trials have happened and all pairs have been shown one time.


    What I would like to happen is:

    object_8 and object_7

    object_1 and object_2

    object_9 and object_10

    object_1 and object_2

    object_14 object_13

    object_1 and object_2

    etc. until all 8 pairs have been shown, none of them repeated, with the same answer not on the same side more than three times in a row.

    So same exact paradigm, just with a repeated pair every other. importantly, this repeated pair should follow the same randomization rules such that sometimes object_1 is on the right and object_2 is on the left and the target(top card) is the match for object_1. Sometimes, object_1 is on the right and object_2 is on the left and the target(top card) is the match for object_2. Sometimes, object_2 is on the right and object_1 is on the left and the target(top card) is the match for object_1. Sometimes, object_2 is on the right and object_1 is on the left and the target(top card) is the match for object_2.

    Sorry I know this is rather involved. I hope I did an ok job explaining it. I appreciate any help you are able to offer. Thank you so much again.

    Best,

    Mollie

  • edited November 14

    Hi Mollie,

    I think I understand now. The main trick would be to add a repetition target (target_1 in my example) after every regular target. This is done in the 'randomise variables' part of the script. Then, you need to also add a matching stimulus for object_1, i.e. object_2. And finally the targe_side list should be twice as long as before, because we now have twice as many trials, i.e. 16 instead of 8.

    Does that get you started?

    Sebastiaan

    from random import shuffle, choice
    
    # script is written for even number of trials. This number does not include the
    # repeated targets!
    no_trials = 8
    
    # initialize variables
    var.target_side = [0,1] * no_trials 
    var.targets = ['object_%d'%choice([idx,idx+1]) for idx in range(5,21,2)]
    # make left and right match
    
    stim_match_1 = {'object_%d'%idx:'object_%d'%(idx+1) for idx in range(5,21,2)}
    stim_match_2 = {'object_%d'%idx:'object_%d'%(idx-1) for idx in range(6,21,2)}
    stim_match_1.update(stim_match_2)
    # Also add matches for the repeating targets
    stim_match_1['object_1'] = 'object_2'
    stim_match_1['object_2'] = 'object_1'  # Update
    
    # randomise variables
    shuffle(var.targets)
    targets_with_repetitions = []
    for target in var.targets:
    	targets_with_repetitions.append(target)
    	targets_with_repetitions.append('object_1')
    var.targets = targets_with_repetitions
    print(var.targets)
    
    # Rest of the script follows
    
  • Perfect!! Thank you so so much

  • edited November 6

    Hey Sebastian!


    The only thing is that I don't want the target to always be the same in the repetition trials. Sometimes I want it to be object 1 and sometimes I want it to be object 2. I'm having trouble with the randomization of this here. Any help would be greatly appreciated!

    Thank you so much,

    Mollie

  • edited November 14

    Hi Mollie,

    If I understand the logic correctly, then would simply change this line:

    targets_with_repetitions.append('object_1')
    

    To this:

    targets_with_repetitions.append(choice(['object_1', 'object_2']))
    

    Cheers!

    Sebastiaan

  • Hi Sebastian,


    Thank you so so much again. I'm getting an error. I notice there is a missing parenthesis but when I add another it still gives me an error. Any advice?


    Thanks,

    Mollie

  • Any advice?

    Yes, to post the actual error message 😉

  • Hi Sebastian,


    It gives me a weird error as I haven't changed anything with var.targets.

    If I change the parenthesis to

    targets_with_repetitions.append(choice(['object_1', 'object_2']))


    I get:

    Thank you so much again!

    Mollie

  • Hi Mollie,

    The problem is that 'object_2' is a key in the stim_match_1 dict. I updated the code above to show how you can add it (marked 'update').

    Cheers!

    Sebastiaan

  • thank you!!!

Sign In or Register to comment.