Howdy, Stranger!

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

Supported by

How to Present a Random Subset of Stimuli

Hi!

I am trying to create a Single Category IAT on OpenSesame, rating an ethnicity as good or bad. I am following the ratio of stimuli recommended by Karpinski & Steinman (2006), where when the category is on the same response key as "good", the ratio of stimuli presented should be:

7 good : 7 ethnicity : 10 bad, which yields a total of 24 trials.

I have a list of 10 stimuli each for good, bad, and "category", and I want to present a random 7 stimuli from the pool of 10 stimuli for the good and ethnicity. How can I do this in OpenSesame?

Thanks in advance for the help!

Comments

  • FabFab
    edited August 2021

    Hi @Ashleigh,

    If I understand correctly your message, you want to select 7 "good" stimuli from a set of 10 (at random and without replacement), 7 "ethnicity" stimuli from a set of 10 (at random and without replacement), and 10 (full set) of "bad" stimuli.

    There probably several ways of doing this. Here are three that come to mind:

    Method 1

    One way may be to use nested loops, starting with a loop with a single trial where you'd have all 3 x 10 stimuli arranges in as many columns (named "good1", "good2",..., "ethnicity1", "ethnicity2",..., "bad1",...) and then use some Python coding using the "shuffle_horiz" command to shuffle each type of stimuli. Then, the nested loop would contain the actual 30 trials. You'd have to include a column that codes for the condition (bad, good, ethnicity) and use code to implement a counter to keep track of the trial number within each condition. You'd then use that to retrieve the appropriate stimulus. That way, on the first "bad" trial, you'd go retrieve the content of the "bad1" top loop, which would contain the first element of the shuffled list of "bad" stimuli. And so on.

    I haven't tried it myself, but it should work.

    More on the shuffle_horizon command here:

    Method 2

    Another method would be to use Python or Javascript code to select randomly and without replacement 7 elements out of 10, for "good" and the "ethnicity" arrays. In your loop, you'd have to have a column coding for the condition (bad, good, ethnicity) and use code to implement a counter to keep track of the trial number within each condition. You'd then use that to retrieve the appropriate stimulus dynamically (i.e., using code) on each trial.

    A quick search of the web will help you find code to select n elements from an array.

    Here's some Javascript code I adapted from what If I found on https://stackoverflow.com/questions/19269545/how-to-get-a-number-of-random-elements-from-an-array (there are loads of resources online with code achieving the same; I just picked this one 'cause it came up first and the code is relatively easy to follow). I adapted it to your needs. You'd have to implement that in your task (and adapt the rest of it to work with it, of course).// Function that randomly select n elements from an array without replacement

    function getRandom(arr, n) {
    var result = new Array(n),
    len = arr.length,
    taken = new Array(len);
    if (n > len)
    throw new RangeError("getRandom: more elements taken than available");
    while (n--) {
    var x = Math.floor(Math.random() * len);
    result[n] = arr[x in taken ? taken[x] : x];
    taken[x] = --len in taken ? taken[len] : len;
    }
    return result;
    }
    
    // defines the arrays
    let arrgood = ["good1","good2","good3","good4","good5","good6","good7","good8","good9","good10"];
    let arrethnicity = ["ethnicity1","ethnicity2","ethnicity3","ethnicity4","ethnicity5","ethnicity6","ethnicity7","ethnicity8","ethnicity9","ethnicity10"];
    
    // create selected arrays
    var sevengood=getRandom(arrgood,7)
    var sevenethnicity=getRandom(arrethnicity,7)
    // commits arrays to task-wide variables
    vars.sevengood=sevengood
    vars.sevenethnicity=sevenethnicity
    
    // quick check of the selections in the console
    for (let i = 0; i < sevengood.length; i++) {
    console.log(sevengood[i]);
    }
    for (let i = 0; i < sevenethnicity.length; i++) {
    console.log(sevenethnicity[i]);
    }
    

    With that before your trials loop, you'll just need to implement counters for the conditions as the trials run (you can adapt it from the code I posted in reply to your previous thread: https://forum.cogsci.nl/discussion/7391/affect-misattribution-procedure#latest) to retrieve the correct stimulus from the correct array.

    Coding may be a little scary at first, but it's worth taking the time to learn. It'll save you time in the long run.

    Method 3 (no coding, but least desirable in your case)

    Another method, less elegant and rather heavy, would be frontload the problem of stimuli selection by preparing a large set of stimuli files in .csv format (manually or using some formulas in Excel) where you'd make sure to have a mix of combinations of stimuli. You could then use nested loops where a first loop would contain as many trials as stimuli files but you'd only select one at random (say, you have 100 such filenames, you'd set the "repeat" property of the loop to 0.01).

    Each of this file would contain 7 good stimuli, 7 ethnicity stimuli and 10 bad ones (as well as all the other variables that are relevant to set up your trials, of course, such as the correct response etc.).

    Then, in the lower-level loop of your nested arrangement, you'd use the selected filename above to point the loop to the file using the Source:file method:

    This method should work too (though not if you're running it online, 'cause OSWeb does not support files as sources in loops, only tables). It requires no coding, but it does mean that you'd have to prepare an awful lot of csv files to cover all kinds of possible random selections. Depending on your task requirements, this may require too many. In your case, since your set of bad stimuli is the same 10 always, the relevant pieces of information are the number of possible combinations of 7 elements among 10 (without repetition), which is 120. So, to emulate a true random process, you'd have to create 120 x 120 (14400!) files, which is a monumental task (you'd have to automate it using programming, which defeats the point). or you'd have to settle for a much smaller number of possible combinations, with the risk that you may introduce a selection bias in your experiment.

    Good luck!

    Fabrice.


    _____________________________________________________________________________________

    If you found my reply helpful and wish to invite me to a coffee, you can do so here 😉: https://www.buymeacoffee.com/psyfab

    Buy Me A Coffee

Sign In or Register to comment.