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


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!


  • 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 (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
    // quick check of the selections in the console
    for (let i = 0; i < sevengood.length; i++) {
    for (let i = 0; i < sevenethnicity.length; 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: 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!



    If you found my reply helpful and wish to invite me to a coffee, you can do so here 😉:

    Buy Me A Coffee

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games