Howdy, Stranger!

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

Supported by

Sampling without replacement

I'm programming an OSpan task and want to sample without replacement. My block loop has the variables: 'equation', 'letter', and 'correct_response'. My trial sequence consists of a sketchpad presenting the [equation] stimuli, and then another sketchpad afterwards presenting the [letter] stimuli. The trial sequence will be called however many letters long I want the letter string (that the participant is trying to memorize in between math equations) to be. However, when the trial sequence is recalled, there's the possibility of getting the same math equation or same letter in that one letter string "trial", which I don't want. How can I get it to be called randomly but without replacement?

Comments

  • Hi Morgan,

    The structure of your experiment is not really clear to me. Could you upload it (you can attach it to a comment) so I can take a look?

    Cheers,
    Sebastiaan

  • How do I upload an .osexp file into the comments? I'm only seeing an external link for URL and image URL? Or did you want the general script of the experiment?

  • You can just upload it by selecting an osexp file instead of an image through the attachment dialog (which, I admit, is a bit confusing).

  • I've checked on both a PC and Mac, and 3 different web browsers and I'm not able to get a file upload through the attachment dialog. They all strictly offer an Image URL attachment. Maybe it's a function that got lost in the US version of the website? I'm not sure!

  • Oops, it was a permission issue: Regular members weren't allowed to upload files. You should be able to upload the experiment now.

  • I'm specifically looking for a way to have no replacement when I'm sampling from the tables (like the one I screenshot). I don't want any of the equations or letters to be repeated while doing one letter sequence. For example, the 2_Loop is a loop that creates a 2 letter sequence OSpan, where the participant is shown an equation, then a letter, then another equation, then another letter, and finally has to recall the 2 letters in the correct order. Within that 2 letter sequence, I don't want there to be a repeated equation or a repeated letter, but I can't figure out a way to do that.

  • edited August 2016

    Hi Morgan,

    I don't think you can make your experiment with relying only on the loop tables, at least not in an easy way. I recommend you select the trials to run from within an inline_script. This requires that you have your variables stored in some data container. As all three (equation, correct_response, and letter) belong together, it makes sense to store them in a dictionary, e.g. trial_one = dict(equation='1+4 =5',cor_resp = 'left',letter='F'). However, if you could also just have three separate lists, and use the same indices to operate on them. This should also make sure that you don't mix them up. Here some code that selects two trials with the restrictions you mentioned.

    import random
    
    # a list with all your equations (I use only 4, for brevity)
    equations = ['1+4=5','1+5=7','3+6=8','2+4=5']
    # same for correct_response and letter. Make sure you don't mess up the order!
    correct_response = ['left','right','left','right']
    letter = ['F','G','F','G']
    
    # choose the first equation and letter
    idx1 = random.choice(range(len(equations)))
    eq1 = equations[idx1]
    let1 = letter[idx1]
    
    # Keep on sampling the 2nd equation and letter as long as either matches the first equivalent
    # once both letters and equations are unique, set the correct_response and break the loop
    while True:
        idx2 = random.choice(range(len(equations)))
        eq2 = equations[idx2]
        let2 = letter[idx2]
        if let2 != let1 and eq1 != eq2:
            cr1 = correct_response[idx1]
            cr2 = correct_response[idx2]
            break
    

    I hope this is useful.

    Good luck,

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.