Millisecond Forums

Shuffle items in list to use same order of stimuli throughout experiment

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

By Tahwan - 4/17/2018

After the fast reply to my last question I am trying it again. I am very suprised I couldn't find a previous post asking the same thing, because it appears to me to be a standard feature I am looking for:
I have four stimuli. I want the order of the stimuli randomized per subject at the beginning of the experiment (counterbalancing between subjects). Then I want to use the same order of stimuli at various points of the experiment. 
So lets say I have four stimuli:

<item Simuli_Portraits>
/1 = "flower1.jpg"
/2 = "flower2.jpg"
/3 = "flower3.jpg"
/4 = "flower4.jpg"
</item>

I could call a specific item in "picture" using select:
<picture Portrait1>
/ items = Simuli_Portraits
/ select = 1
</picture>

All I would need is a shuffeled array of numbers that I could call one by one via select, let's say
/select = order_stimuli(1), where order_stimuli is a random order of the numbers 1-4

I can also create a sequence of numbers via list:
<list order_stimuli>
/ items = (1,4)
/ selectionmode = random
/ selectionrate = experiment
</list>

Yet, what I don't understand is whether this really provides me a list of numbers or only one number. All I need is a function that shuffles an array of numbers, in which I can call the x-th element of the array.
I was also thinking about some workaround methods:
1. Manually creating all possible orders (a list of items with all combination "1234", "1243, "1324", ..., "4321") as randomly choosing one. Here again I have the problem that I don't know how to call the x-th element of the string/number/array for select in the picture function.
2. Using some complicated randomization with branches at the beginning of the experiment to create a randomized order in items, also not having a clue how that could work.

I am very much into the logic of (dynamical) indexing that I might miss the very obvious solution on how to keep randomization consistent throughout multiple blocks of the experiment. Thank you for your help!

By Dave - 4/17/2018

Tahwan - Tuesday, April 17, 2018
After the fast reply to my last question I am trying it again. I am very suprised I couldn't find a previous post asking the same thing, because it appears to me to be a standard feature I am looking for:
I have four stimuli. I want the order of the stimuli randomized per subject at the beginning of the experiment (counterbalancing between subjects). Then I want to use the same order of stimuli at various points of the experiment. 
So lets say I have four stimuli:

<item Simuli_Portraits>
/1 = "flower1.jpg"
/2 = "flower2.jpg"
/3 = "flower3.jpg"
/4 = "flower4.jpg"
</item>

I could call a specific item in "picture" using select:
<picture Portrait1>
/ items = Simuli_Portraits
/ select = 1
</picture>

All I would need is a shuffeled array of numbers that I could call one by one via select, let's say
/select = order_stimuli(1), where order_stimuli is a random order of the numbers 1-4

I can also create a sequence of numbers via list:
<list order_stimuli>
/ items = (1,4)
/ selectionmode = random
/ selectionrate = experiment
</list>

Yet, what I don't understand is whether this really provides me a list of numbers or only one number. All I need is a function that shuffles an array of numbers, in which I can call the x-th element of the array.
I was also thinking about some workaround methods:
1. Manually creating all possible orders (a list of items with all combination "1234", "1243, "1324", ..., "4321") as randomly choosing one. Here again I have the problem that I don't know how to call the x-th element of the string/number/array for select in the picture function.
2. Using some complicated randomization with branches at the beginning of the experiment to create a randomized order in items, also not having a clue how that could work.

I am very much into the logic of (dynamical) indexing that I might miss the very obvious solution on how to keep randomization consistent throughout multiple blocks of the experiment. Thank you for your help!


What you do is this: Have one <list> containing the values 1 to 4 set to random selection. Have another empty <list> set to sequential selection. Sample four values from the 1st list /onexptbegin and store them in the empty list. You now have a fixed randomly generated sequence which you can use for selection as needed. In a nutshell:


<list rand>
/ poolsize = 4
/ selectionrate = always
/ selectionmode = random
/ replace = false
</list>

<list fixedseq>
/ selectionmode = sequence
</list>

<expt>
/ onexptbegin = [
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
]
/ blocks = [1=myblock]
</expt>


<block myblock>
/ trials = [1-16 = mytrial]
</block>

<trial mytrial>
/ stimulusframes = [1=mytext]
/ validresponse = (57)
</trial>

<text mytext>
/ items = myitems
/ select = list.fixedseq.nextvalue
</text>

<item myitems>
/ 1 = "A"
/ 2 = "B"
/ 3 = "C"
/ 4 = "D"
</item>

Hope this helps.
By Dave - 4/17/2018

Dave - Tuesday, April 17, 2018
Tahwan - Tuesday, April 17, 2018
After the fast reply to my last question I am trying it again. I am very suprised I couldn't find a previous post asking the same thing, because it appears to me to be a standard feature I am looking for:
I have four stimuli. I want the order of the stimuli randomized per subject at the beginning of the experiment (counterbalancing between subjects). Then I want to use the same order of stimuli at various points of the experiment. 
So lets say I have four stimuli:

<item Simuli_Portraits>
/1 = "flower1.jpg"
/2 = "flower2.jpg"
/3 = "flower3.jpg"
/4 = "flower4.jpg"
</item>

I could call a specific item in "picture" using select:
<picture Portrait1>
/ items = Simuli_Portraits
/ select = 1
</picture>

All I would need is a shuffeled array of numbers that I could call one by one via select, let's say
/select = order_stimuli(1), where order_stimuli is a random order of the numbers 1-4

I can also create a sequence of numbers via list:
<list order_stimuli>
/ items = (1,4)
/ selectionmode = random
/ selectionrate = experiment
</list>

Yet, what I don't understand is whether this really provides me a list of numbers or only one number. All I need is a function that shuffles an array of numbers, in which I can call the x-th element of the array.
I was also thinking about some workaround methods:
1. Manually creating all possible orders (a list of items with all combination "1234", "1243, "1324", ..., "4321") as randomly choosing one. Here again I have the problem that I don't know how to call the x-th element of the string/number/array for select in the picture function.
2. Using some complicated randomization with branches at the beginning of the experiment to create a randomized order in items, also not having a clue how that could work.

I am very much into the logic of (dynamical) indexing that I might miss the very obvious solution on how to keep randomization consistent throughout multiple blocks of the experiment. Thank you for your help!


What you do is this: Have one <list> containing the values 1 to 4 set to random selection. Have another empty <list> set to sequential selection. Sample four values from the 1st list /onexptbegin and store them in the empty list. You now have a fixed randomly generated sequence which you can use for selection as needed. In a nutshell:


<list rand>
/ poolsize = 4
/ selectionrate = always
/ selectionmode = random
/ replace = false
</list>

<list fixedseq>
/ selectionmode = sequence
</list>

<expt>
/ onexptbegin = [
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
]
/ blocks = [1=myblock]
</expt>


<block myblock>
/ trials = [1-16 = mytrial]
</block>

<trial mytrial>
/ stimulusframes = [1=mytext]
/ validresponse = (57)
</trial>

<text mytext>
/ items = myitems
/ select = list.fixedseq.nextvalue
</text>

<item myitems>
/ 1 = "A"
/ 2 = "B"
/ 3 = "C"
/ 4 = "D"
</item>

Hope this helps.

Oh, and if you have several fixed orders you wish to counterbalance between subjects, you can do this like so, by essentially nesting lists:

<list orders>
/ items = (list.order1.nextvalue, list.order2.nextvalue)
/ selectionmode = values.ordernumber
</list>

<list order1>
/ items = (1,2,3,4)
/ selectionmode = sequence
</list>

<list order2>
/ items = (4,3,2,1)
/ selectionmode = sequence
</list>

<values>
/ ordernumber = 1
</values>


<expt>
/ onexptbegin = [
    values.ordernumber = 1;
]
/ blocks = [1=myblock]
/ subjects = (1 of 2)
/ groupassignment = groupnumber
</expt>

<expt>
/ onexptbegin = [
    values.ordernumber = 2;
]
/ blocks = [1=myblock]
/ subjects = (2 of 2)
/ groupassignment = groupnumber
</expt>


<block myblock>
/ trials = [1-16 = mytrial]
</block>

<trial mytrial>
/ stimulusframes = [1=mytext]
/ validresponse = (57)
</trial>

<text mytext>
/ items = myitems
/ select = list.orders.nextvalue
</text>

<item myitems>
/ 1 = "A"
/ 2 = "B"
/ 3 = "C"
/ 4 = "D"
</item>
By Tahwan - 4/17/2018

Dave - Tuesday, April 17, 2018
Dave - Tuesday, April 17, 2018
Tahwan - Tuesday, April 17, 2018
After the fast reply to my last question I am trying it again. I am very suprised I couldn't find a previous post asking the same thing, because it appears to me to be a standard feature I am looking for:
I have four stimuli. I want the order of the stimuli randomized per subject at the beginning of the experiment (counterbalancing between subjects). Then I want to use the same order of stimuli at various points of the experiment. 
So lets say I have four stimuli:

<item Simuli_Portraits>
/1 = "flower1.jpg"
/2 = "flower2.jpg"
/3 = "flower3.jpg"
/4 = "flower4.jpg"
</item>

I could call a specific item in "picture" using select:
<picture Portrait1>
/ items = Simuli_Portraits
/ select = 1
</picture>

All I would need is a shuffeled array of numbers that I could call one by one via select, let's say
/select = order_stimuli(1), where order_stimuli is a random order of the numbers 1-4

I can also create a sequence of numbers via list:
<list order_stimuli>
/ items = (1,4)
/ selectionmode = random
/ selectionrate = experiment
</list>

Yet, what I don't understand is whether this really provides me a list of numbers or only one number. All I need is a function that shuffles an array of numbers, in which I can call the x-th element of the array.
I was also thinking about some workaround methods:
1. Manually creating all possible orders (a list of items with all combination "1234", "1243, "1324", ..., "4321") as randomly choosing one. Here again I have the problem that I don't know how to call the x-th element of the string/number/array for select in the picture function.
2. Using some complicated randomization with branches at the beginning of the experiment to create a randomized order in items, also not having a clue how that could work.

I am very much into the logic of (dynamical) indexing that I might miss the very obvious solution on how to keep randomization consistent throughout multiple blocks of the experiment. Thank you for your help!


What you do is this: Have one <list> containing the values 1 to 4 set to random selection. Have another empty <list> set to sequential selection. Sample four values from the 1st list /onexptbegin and store them in the empty list. You now have a fixed randomly generated sequence which you can use for selection as needed. In a nutshell:


<list rand>
/ poolsize = 4
/ selectionrate = always
/ selectionmode = random
/ replace = false
</list>

<list fixedseq>
/ selectionmode = sequence
</list>

<expt>
/ onexptbegin = [
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
]
/ blocks = [1=myblock]
</expt>


<block myblock>
/ trials = [1-16 = mytrial]
</block>

<trial mytrial>
/ stimulusframes = [1=mytext]
/ validresponse = (57)
</trial>

<text mytext>
/ items = myitems
/ select = list.fixedseq.nextvalue
</text>

<item myitems>
/ 1 = "A"
/ 2 = "B"
/ 3 = "C"
/ 4 = "D"
</item>

Hope this helps.

Oh, and if you have several fixed orders you wish to counterbalance between subjects, you can do this like so, by essentially nesting lists:

<list orders>
/ items = (list.order1.nextvalue, list.order2.nextvalue)
/ selectionmode = values.ordernumber
</list>

<list order1>
/ items = (1,2,3,4)
/ selectionmode = sequence
</list>

<list order2>
/ items = (4,3,2,1)
/ selectionmode = sequence
</list>

<values>
/ ordernumber = 1
</values>


<expt>
/ onexptbegin = [
    values.ordernumber = 1;
]
/ blocks = [1=myblock]
/ subjects = (1 of 2)
/ groupassignment = groupnumber
</expt>

<expt>
/ onexptbegin = [
    values.ordernumber = 2;
]
/ blocks = [1=myblock]
/ subjects = (2 of 2)
/ groupassignment = groupnumber
</expt>


<block myblock>
/ trials = [1-16 = mytrial]
</block>

<trial mytrial>
/ stimulusframes = [1=mytext]
/ validresponse = (57)
</trial>

<text mytext>
/ items = myitems
/ select = list.orders.nextvalue
</text>

<item myitems>
/ 1 = "A"
/ 2 = "B"
/ 3 = "C"
/ 4 = "D"
</item>

Thank you very much for your fast response. Unfortunately it is not solving my problem. "/ select = list.orders.nextvalue" is not working for me, because I do not always want the "next value". I want participants to judge 4 images. First regarding one trait, then regarding another trait and so on. The participant has several options to get additional information, branching to several different pages/trials. Easiest would be a function "/ select = list.orders.1", calling the first number of the fixed sequence list "fixedseq" whenever I need to. Working with nextvalue would drive me crazy, because I want to call the same number in different blocks.

A different idea: I could create a list of all combinations as strings, call the n-th position via some regex (if possible), convert that string to a number that could be used for / select". For example would "/a{2}/" extract the third value of a string "3412", providing me a "1". But I neither know whether Regey works nor whether it is possible to to use/convert the string to a number usable by "/ select".
By Tahwan - 4/17/2018

Dave - Tuesday, April 17, 2018
Dave - Tuesday, April 17, 2018
Tahwan - Tuesday, April 17, 2018
After the fast reply to my last question I am trying it again. I am very suprised I couldn't find a previous post asking the same thing, because it appears to me to be a standard feature I am looking for:
I have four stimuli. I want the order of the stimuli randomized per subject at the beginning of the experiment (counterbalancing between subjects). Then I want to use the same order of stimuli at various points of the experiment. 
So lets say I have four stimuli:

<item Simuli_Portraits>
/1 = "flower1.jpg"
/2 = "flower2.jpg"
/3 = "flower3.jpg"
/4 = "flower4.jpg"
</item>

I could call a specific item in "picture" using select:
<picture Portrait1>
/ items = Simuli_Portraits
/ select = 1
</picture>

All I would need is a shuffeled array of numbers that I could call one by one via select, let's say
/select = order_stimuli(1), where order_stimuli is a random order of the numbers 1-4

I can also create a sequence of numbers via list:
<list order_stimuli>
/ items = (1,4)
/ selectionmode = random
/ selectionrate = experiment
</list>

Yet, what I don't understand is whether this really provides me a list of numbers or only one number. All I need is a function that shuffles an array of numbers, in which I can call the x-th element of the array.
I was also thinking about some workaround methods:
1. Manually creating all possible orders (a list of items with all combination "1234", "1243, "1324", ..., "4321") as randomly choosing one. Here again I have the problem that I don't know how to call the x-th element of the string/number/array for select in the picture function.
2. Using some complicated randomization with branches at the beginning of the experiment to create a randomized order in items, also not having a clue how that could work.

I am very much into the logic of (dynamical) indexing that I might miss the very obvious solution on how to keep randomization consistent throughout multiple blocks of the experiment. Thank you for your help!


What you do is this: Have one <list> containing the values 1 to 4 set to random selection. Have another empty <list> set to sequential selection. Sample four values from the 1st list /onexptbegin and store them in the empty list. You now have a fixed randomly generated sequence which you can use for selection as needed. In a nutshell:


<list rand>
/ poolsize = 4
/ selectionrate = always
/ selectionmode = random
/ replace = false
</list>

<list fixedseq>
/ selectionmode = sequence
</list>

<expt>
/ onexptbegin = [
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
    list.fixedseq.appenditem(list.rand.nextindex);
]
/ blocks = [1=myblock]
</expt>


<block myblock>
/ trials = [1-16 = mytrial]
</block>

<trial mytrial>
/ stimulusframes = [1=mytext]
/ validresponse = (57)
</trial>

<text mytext>
/ items = myitems
/ select = list.fixedseq.nextvalue
</text>

<item myitems>
/ 1 = "A"
/ 2 = "B"
/ 3 = "C"
/ 4 = "D"
</item>

Hope this helps.

Oh, and if you have several fixed orders you wish to counterbalance between subjects, you can do this like so, by essentially nesting lists:

<list orders>
/ items = (list.order1.nextvalue, list.order2.nextvalue)
/ selectionmode = values.ordernumber
</list>

<list order1>
/ items = (1,2,3,4)
/ selectionmode = sequence
</list>

<list order2>
/ items = (4,3,2,1)
/ selectionmode = sequence
</list>

<values>
/ ordernumber = 1
</values>


<expt>
/ onexptbegin = [
    values.ordernumber = 1;
]
/ blocks = [1=myblock]
/ subjects = (1 of 2)
/ groupassignment = groupnumber
</expt>

<expt>
/ onexptbegin = [
    values.ordernumber = 2;
]
/ blocks = [1=myblock]
/ subjects = (2 of 2)
/ groupassignment = groupnumber
</expt>


<block myblock>
/ trials = [1-16 = mytrial]
</block>

<trial mytrial>
/ stimulusframes = [1=mytext]
/ validresponse = (57)
</trial>

<text mytext>
/ items = myitems
/ select = list.orders.nextvalue
</text>

<item myitems>
/ 1 = "A"
/ 2 = "B"
/ 3 = "C"
/ 4 = "D"
</item>

Sorry, in fact it does work, because I can call the x-th element of the list via list.fixedseq.x, for example list.fixedseq.2. Thank you very much!