Millisecond Forums

randomizing list but with certain % consecutive stimuli types

https://forums.millisecond.com/Topic36875.aspx

By achen - 2/13/2025

Hi,

I want 38 trials that are each made up of 2 stimuli. Is there a way to randomize the stimuli but make it so that 50% of trials have the same stimuli type? For example, each stimulus is categorized as type A, B, or C. 50% of trials should be stimuli of the same category (eg. AA), and 50% do not (eg. AB). Is it possible to incorporate this logic?
By Dave - 2/13/2025

achen - 2/13/2025
Hi,

I want 38 trials that are each made up of 2 stimuli. Is there a way to randomize the stimuli but make it so that 50% of trials have the same stimuli type? For example, each stimulus is categorized as type A, B, or C. 50% of trials should be stimuli of the same category (eg. AA), and 50% do not (eg. AB). Is it possible to incorporate this logic?

Give a more detailed description and a concrete example.
By achen - 2/13/2025

Each stimulus is a word pair (eg. cap:bottle, mammal:fox, etc.) and is categorized into A, B, or C. Each trial shows the first word pair, then a "+", then the second word pair, then an "X". On the second word pair, participants respond by pressing F or J. This sequence is one trial.

I'd like to randomize the list of word pairs, but make it so that 50% of trials have word pairs from the same category (ie. AA or BB or CC), and 50% of trials do not. Hopefully this makes more sense? 
By Dave - 2/13/2025

achen - 2/13/2025
Each stimulus is a word pair (eg. cap:bottle, mammal:fox, etc.) and is categorized into A, B, or C. Each trial shows the first word pair, then a "+", then the second word pair, then an "X". On the second word pair, participants respond by pressing F or J. This sequence is one trial.

I'd like to randomize the list of word pairs, but make it so that 50% of trials have word pairs from the same category (ie. AA or BB or CC), and 50% of trials do not. Hopefully this makes more sense? 

You have 3 possible "same" trial types: AA, BB, CC
As for the "different" trials, it's unclear if you care about order. I assume you do, so you have 6 types: AB, AC, BA, BC, CA, CB.

Normally you would care that each type occurs equally often. That doesn't work with 38 trials total. It would work with 36.
Same:
6 x AA
6 x BB
6 x CC
Different:
3 x AB
3 x AC
3 x BA
3 x BC
3 x CA
3 x CB

So, what do you want to do to get to 38 trials? Unclear to me.
By achen - 2/13/2025

We don't particularly care if each type occurs equally often. It's more about the fact that participants are responding F or J roughly equal number of times.
By Dave - 2/13/2025

achen - 2/13/2025
We don't particularly care if each type occurs equally often. It's more about the fact that participants are responding F or J roughly equal number of times.

Well, it makes a difference in terms of how many items you need per category. So, what are the numbers?
By achen - 2/13/2025

Dave - 2/13/2025
achen - 2/13/2025
We don't particularly care if each type occurs equally often. It's more about the fact that participants are responding F or J roughly equal number of times.

Well, it makes a difference in terms of how many items you need per category. So, what are the numbers?

I see. (I forgot to add that there's a fourth category, D, but we don't want consecutive pairs of D)

Same:
9 x AA
6 x BB
4 x CC

Different:
3 x AB
1 x AC
2 x BA
1 x BC
2 x BD
2 x CA
3 x CB
1 x DA
1 x DB
3 x DC
By Dave - 2/13/2025

achen - 2/13/2025
Dave - 2/13/2025
achen - 2/13/2025
We don't particularly care if each type occurs equally often. It's more about the fact that participants are responding F or J roughly equal number of times.

Well, it makes a difference in terms of how many items you need per category. So, what are the numbers?

I see. (I forgot to add that there's a fourth category, D, but we don't want consecutive pairs of D)

Same:
9 x AA
6 x BB
4 x CC

Different:
3 x AB
1 x AC
2 x BA
1 x BC
2 x BD
2 x CA
3 x CB
1 x DA
1 x DB
3 x DC

By my count, that means you have

27 category A items
24 category B items
18 category C items
7 cateory D items

Does that match? In general, it would be helpful if you could provide such information in an accessible way, so I don't have to count these things up manually. Thanks.
By achen - 2/13/2025

Yes, that's right. Sorry for making this confusing!
By Dave - 2/13/2025

<values>
/ globalType = null
/ subType = null
/ firstPairItemNumber = -1
/ secondPairItemNumber = -1
</values>

<block exampleBlock>
/ trials = [1-38 = noReplace(sameTrial, diffTrial)]
</block>

<trial sameTrial>
/ onTrialBegin = {
    values.globalType = "same"; //set globa trial type
    values.subType = list.sameTypes.nextValue; // select subtype
    // select item for 1st pair according to subtype
    if (startsWith(values.subType, "A")) {
        values.firstPairItemNumber = list.catAItemNumbers.nextValue;
    } else if (startsWith(values.subType, "B")) {
        values.firstPairItemNumber = list.catBItemNumbers.nextValue;
    } else if (startsWith(values.subType, "C")) {
        values.firstPairItemNumber = list.catCItemNumbers.nextValue;
    } else if (startsWith(values.subType, "D")) {
        values.firstPairItemNumber = list.catDItemNumbers.nextValue;
    };
    // select item for 2nd pair according to subtype
    if (endsWith(values.subType, "A")) {
        values.secondPairItemNumber = list.catAItemNumbers.nextValue;
    } else if (endsWith(values.subType, "B")) {
        values.secondPairItemNumber = list.catBItemNumbers.nextValue;
    } else if (endsWith(values.subType, "C")) {
        values.secondPairItemNumber = list.catCItemNumbers.nextValue;
    } else if (endsWith(values.subType, "D")) {
        values.secondPairItemNumber = list.catDItemNumbers.nextValue;
    };
}
/ stimulusTimes = [0=clearScreen, firstPair; 1000=clearScreen, fixation; 2000=clearScreen, secondPair; 3000=clearScreen, x]
/ validResponse = ("F", "J")
/ correctResponse = ("F")
</trial>

<list sameTypes>
/ items = (
    "AA", "AA", "AA", "AA", "AA", "AA", "AA", "AA", "AA",
    "BB", "BB", "BB", "BB", "BB", "BB",
    "CC", "CC", "CC", "CC")
</list>

<trial diffTrial>
/ onTrialBegin = {
    values.globalType = "diff"; //set globa trial type
    values.subType = list.diffTypes.nextValue; // select subtype
    // select item for 1st pair according to subtype
    if (startsWith(values.subType, "A")) {
        values.firstPairItemNumber = list.catAItemNumbers.nextValue;
    } else if (startsWith(values.subType, "B")) {
        values.firstPairItemNumber = list.catBItemNumbers.nextValue;
    } else if (startsWith(values.subType, "C")) {
        values.firstPairItemNumber = list.catCItemNumbers.nextValue;
    } else if (startsWith(values.subType, "D")) {
        values.firstPairItemNumber = list.catDItemNumbers.nextValue;
    };
    // select item for 2nd pair according to subtype
    if (endsWith(values.subType, "A")) {
        values.secondPairItemNumber = list.catAItemNumbers.nextValue;
    } else if (endsWith(values.subType, "B")) {
        values.secondPairItemNumber = list.catBItemNumbers.nextValue;
    } else if (endsWith(values.subType, "C")) {
        values.secondPairItemNumber = list.catCItemNumbers.nextValue;
    } else if (endsWith(values.subType, "D")) {
        values.secondPairItemNumber = list.catDItemNumbers.nextValue;
    };
}
/ stimulusTimes = [0=clearScreen, firstPair; 1000=clearScreen, fixation; 2000=clearScreen, secondPair; 3000=clearScreen, x]
/ validResponse = ("F", "J")
/ correctResponse = ("J")
</trial>

<list diffTypes>
/ items = (
    "AB", "AB", "AB",
    "AC",
    "BA", "BA",
    "BC",
    "BD", "BD",
    "CA", "CA",
    "CB", "CB", "CB",
    "DA",
    "DB",
    "DC", "DC", "DC")
</list>

<text fixation>
/ items = ("+")
/ erase = false
</text>

<text x>
/ items = ("X")
/ erase = false
</text>

<text firstPair>
/ items = allItems
/ select = values.firstPairItemNumber
/ erase = false
</text>

<text secondPair>
/ items = allItems
/ select = values.secondPairItemNumber
/ erase = false
</text>

<item allItems>
// category A
/ 0 = "Cat A Pair 1"
/ 1 = "Cat A Pair 2"
/ 2 = "Cat A Pair 3"
/ 3 = "Cat A Pair 4"
/ 4 = "Cat A Pair 5"
/ 5 = "Cat A Pair 6"
/ 6 = "Cat A Pair 7"
/ 7 = "Cat A Pair 8"
/ 8 = "Cat A Pair 9"
/ 9 = "Cat A Pair 10"
/ 10 = "Cat A Pair 11"
/ 11 = "Cat A Pair 12"
/ 12 = "Cat A Pair 13"
/ 13 = "Cat A Pair 14"
/ 14 = "Cat A Pair 15"
/ 15 = "Cat A Pair 16"
/ 16 = "Cat A Pair 17"
/ 17 = "Cat A Pair 18"
/ 18 = "Cat A Pair 19"
/ 19 = "Cat A Pair 20"
/ 20 = "Cat A Pair 21"
/ 21 = "Cat A Pair 22"
/ 22 = "Cat A Pair 23"
/ 23 = "Cat A Pair 24"
/ 24 = "Cat A Pair 25"
/ 25 = "Cat A Pair 26"
/ 26 = "Cat A Pair 27"
// category B
/ 27 = "Cat B Pair 1"
/ 28 = "Cat B Pair 2"
/ 29 = "Cat B Pair 3"
/ 30 = "Cat B Pair 4"
/ 31 = "Cat B Pair 5"
/ 32 = "Cat B Pair 6"
/ 33 = "Cat B Pair 7"
/ 34 = "Cat B Pair 8"
/ 35 = "Cat B Pair 9"
/ 36 = "Cat B Pair 10"
/ 37 = "Cat B Pair 11"
/ 38 = "Cat B Pair 12"
/ 39 = "Cat B Pair 13"
/ 40 = "Cat B Pair 14"
/ 41 = "Cat B Pair 15"
/ 42 = "Cat B Pair 16"
/ 43 = "Cat B Pair 17"
/ 44 = "Cat B Pair 18"
/ 45 = "Cat B Pair 19"
/ 46 = "Cat B Pair 20"
/ 47 = "Cat B Pair 21"
/ 48 = "Cat B Pair 22"
/ 49 = "Cat B Pair 23"
/ 50 = "Cat B Pair 24"
// category C
/ 51 = "Cat C Pair 1"
/ 52 = "Cat C Pair 2"
/ 53 = "Cat C Pair 3"
/ 54 = "Cat C Pair 4"
/ 55 = "Cat C Pair 5"
/ 56 = "Cat C Pair 6"
/ 57 = "Cat C Pair 7"
/ 58 = "Cat C Pair 8"
/ 59 = "Cat C Pair 9"
/ 60 = "Cat C Pair 10"
/ 61 = "Cat C Pair 11"
/ 62 = "Cat C Pair 12"
/ 63 = "Cat C Pair 13"
/ 64 = "Cat C Pair 14"
/ 65 = "Cat C Pair 15"
/ 66 = "Cat C Pair 16"
/ 67 = "Cat C Pair 17"
/ 68 = "Cat C Pair 18"
// category D
/ 69 = "Cat D Pair 1"
/ 70 = "Cat D Pair 2"
/ 71 = "Cat D Pair 3"
/ 72 = "Cat D Pair 4"
/ 73 = "Cat D Pair 5"
/ 74 = "Cat D Pair 6"
/ 75 = "Cat D Pair 7"
</item>

<list catAItemNumbers>
/ items = (0-26)
/ selectionRate = always
</list>

<list catBItemNumbers>
/ items = (27-50)
/ selectionRate = always
</list>

<list catCItemNumbers>
/ items = (51-68)
/ selectionRate = always
</list>

<list catDItemNumbers>
/ items = (69-75)
/ selectionRate = always
</list>

<data>
/ columns = (
    date, time, subject, group, session, blockNum, blockCode, trialNum, trialCode, response, responseText, latency, correct,
    values.globalType, values.subType, values.firstPairItemNumber, values.secondPairItemNumber, text.firstPair.currentItem, text.secondPair.currentItem
    )
</data>