Howdy, Stranger!

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

Supported by

[open] how to create feedback with different proportions

edited February 2013 in OpenSesame

Hello, we use a free choice task in which one of four relevant keys can cause an effect on the screen (a red circle changes its color to white and disappear).
We have a problem in creating different proportions of feedback to each one of the relevant keys.
for instance, a specific key will cause the effect on the screen in only 70% of the times it is pressed.

any suggestion or example how to do it will be very helpful

Noam

Comments

  • edited February 2013

    Hi Noam,

    Perhaps you can describe your problem in more detail? I.e. what exactly are you trying to accomplish, what do you have at the moment, and in what sense doesn't it work?

    Cheers!
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited February 2013

    Hi

    We are new with Sesame so I will try to be more specific:
    we have created a response effect (a proceeding sketchpad) that appears when one is pressing any one of four relevant keys. The problem we are facing is how to create two proceeding "effects" (sketchpads) that will appear with different proportions after each key. For example, a sketchpad (a response effect) will follow a key press 70% of the times and different sketchpad (different response effect) after the other 30 % of the times the same key is pressed.
    it is a common procedure in experiments using feedback in a fixed proportion.
    thank you!

    Noam

  • edited February 2013

    Hi Noam,

    If I understand correctly, a given keyboard response should lead to the appearance of a 'desired' sketchpad in 70% of the cases, whereas it leads to a different sketchpad in the remaining 30% of the cases. Is that correct? The explanation below will give you an idea of how to achieve this. You can adapt this to your specific situation, for example by extending it to multiple keypresses which all have different 'desired' and 'different' sketchpads associated with them.

    1: Append an inline_script to your block_sequence, and place the following code in its "Prepare phase" tab:

    # Import the built-in Python module 'random':
    import random
    
    # Define constant variables. (Adapt those values
    # to your specific situation):
    
    nTrials = 10 # nr of trials in one block
    pWanted = .7 # chance that the intended response effect occurs
    pDifferent = .3 # chance that another response effect occurs
    
    # Create a list containing 10 items. 7 of the items have the value 
    # 'desired', 3 of the items have the value 'different':
    blockList = ["desired"] * int(nTrials * pWanted) + ["different"] * int(nTrials * pDifferent)
    
    # Next, use the random.shuffle() function to 
    # randomize the order of the items in the list:
    random.shuffle(blockList)
    
    # Finally, make the list global such that we
    # can use it in other inline_script items as well:
    
    global blockList
    

    2: Append an inline_script item to your trial_sequence and place the following code in its "Prepare phase" tab:

    <br /># Determine which response effect will 
    # appear after a keyboard response:
    
    # We'll do this by 'popping' (i.e. drawing without replacement)
    # one item from the previously prepared blockList.
    responseEffect = blockList.pop()
    
    # Set the variable using the exp.set() function.
    # By doing so, we make sure the variable is available
    # in the graphical interface as well. This enables us,
    # for example, to log the variable and to use the square-
    # bracket method.
    # See also: 
    # http://osdoc.cogsci.nl/usage/variables-and-conditional-qifq-statements/
    exp.set("responseEffect", responseEffect)
    
    

    3: Append two sketchpad items to your trial_sequence, one with the 'desired' and one with the 'different' content. Make sure those items are placed after the inline_script item and the keyboard_response item.

    4: Open your trial_sequence item, and set the "Run if" statement of the 'desired' sketchpad to [responseEffect] = desired. Adapt the "Run if" statement of the 'different' sketchpad according to similar reasoning.

    An example experiment can be downloaded here (simply save with the extension '.opensesame'):

    Note that I used a little bit of Python inline coding. If you're not familiar with Python, this might be a good start:

    I hope this helps you getting started! Please let us know if you have any further questions!

    Best wishes,

    Lotje

  • edited 5:00AM

    You understand it correctly. thank you very match Lotje!

  • Hi Noam,

    You're welcome!
    Good luck with your experiment and don't hesitate to post more questions!

    Best,

    Lotje

  • edited March 2013

    Hi again

    The script that you sent us worked very well. We defined one key that leads to two different sketchpads with different proportion. However, we still have problem in creating four keys that lead to different sketchpads with different proportions. For example, the key "s" leads to "sketchpad 1" in 30% of the presses and to "sketchpad 2" in 70%, while key "d" leads to "sketchpad 1" in 60% of the presses and to "sketchpad 2" in 40%.
    We would like to know how to define four keys for each proportion condition and what do we need to change in the script in accordance to the above.

    Thank you for your help
    Noam

  • edited March 2013

    Hi Noam,

    I think it's a good idea to make a Python dictionary at the start of your experiment, containing the possible keyboard presses as keys, and the corresponding probabilities of sketchpad1 as values.

    For example:

    # Make a dictionary containing probability of sketchpad1
    # for every possible keyboard response.
    
    # See also:
    # http://docs.python.org/2/tutorial/datastructures.html#dictionaries
    
    dict = {}
    
    dict["s"] = .3
    dict["d"] = .6
    dict["b"] = .9
    dict["l"] = .1
    
    # Make the dictionary global such that it is available in 
    # future inline_script items as well:
    global dict
    

    Next, you could append an inline_script to your trial_sequence and determine whether sketchpad1 or sketchpad2 is going to be presented by placing the following Python code in the Run phase tab. (Note that this item should be placed after the keyboard response is collected, but before sketchpad1 and sketchpad2.)

    # Here we determine which response effect will appear 
    # after a keyboard response:
    
    # Import the built-in Python module random()
    # See also: http://docs.python.org/2/library/random.html
    import random
    
    # Determine the given keyboard response by using the self.get() function.
    # See also: 
    # http://osdoc.cogsci.nl/usage/variables-and-conditional-qifq-statements/
    key = self.get("response")
    
    # 'Look up' in the dictionary what the probability of sketchpad1 is 
    # for this response:
    pSketchpad1 = dict[key]
    
    # Draw a random float and see whether the float is higher or lower than
    # as the probability that sketchpad1 will appear. 
    # This probability depends the keyboard response.
    randomChoice = random.random()
    
    if randomChoice <= pSketchpad1:
        responseEffect = "sketchpad1"
    else:
        responseEffect = "sketchpad2"
    
    # Set the variable using the exp.set() function.
    # By doing so, we make sure the variable is available
    # in the graphical interface as well. This enables us,
    # for example, to log the variable and to use the square-
    # bracket method.
    # See also: 
    # http://osdoc.cogsci.nl/usage/variables-and-conditional-qifq-statements/
    exp.set("responseEffect", responseEffect)
    
    # Also use some other variables for potential use in the GUI:
    exp.set("randomChoice", randomChoice)
    exp.set("pSketchpad1", pSketchpad1)
    exp.set("pSketchpad2", 1-pSketchpad1)
    

    The updated example experiment can be downloaded here.

    I hope this helps!

    Best wishes,

    Lotje

  • edited 5:00AM

    thank you!

    We have another last question for the cuurent experiment, hope you could help us with this one too.
    We would like to add the data output another variable that counts the responses (key presses) whithin each trial.
    thank you again!
    Noam

  • edited March 2013

    Hi Noam,

    You're welcome!

    I don't completely understand what you mean by 'a variable that counts the responses within a trial'. Is the participant giving multiple responses in one trial?

    In general, all items in your experiment are automatically counted by OpenSesame. The counters are stored in the variables called 'count_' followed by the name of the item (e.g. 'count_keyboard_response') and automatically logged to your output file (provided that you appended a logger item to the end of your trial sequence, of course):

    image

    Note that in Python counting always starts at zero. So the first time a keyboard_response item is run, 'count_keyboard_response' has the value 0, whereas the second time it has the value 1, etc.

    Does this help? If it doesn't solve your question, please don't hesitate to post again!

    Best,

    Lotje

  • edited 5:00AM

    thanks for the quick reply,
    Participants are instructed to respond only one time. However,some may respond more than one time in a single trial.
    "count_keyboard response" counts only the first response on each trial. I am interested on the actual number of presses within a trial (even though participants are instructed to press only one time per trial).
    Noam

  • edited 5:00AM

    Hi Noam,

    It's still not completely clear to me what you mean. If you don't want participants to give multiple keyboard responses before the response effect (your second sketchpad) is shown, you could set the duration of the first sketchpad to 0, and place a keyboard_response item immediately after it (see the example experiment I uploaded earlier). By doing so, the experiment will always immediately advance to the next item (in your case the second sketchpad) as soon as a key is pressed.

    If you want to continuously check whether your participants are pressing any keys (that will not have any effect anyway) throughout the whole experiment (i.e., during your first sketchpad, your second sketchpad, and any potential other sketchpad or feedback items), you'll need to run all of those items via inline scripts. I'm not sure whether that's worth all the effort.

    If you do want to count the number of presses anyway, could you provide us with some more information by for example adding a screen shot of the overview of your experiment or uploading your script? And could you tell us where exactly in your trial sequence you want to continuously pull the keyboard input?

    Best,

    Lotje

Sign In or Register to comment.