Millisecond Forums

select matching substrings of items 50% of the time?

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

By S F - 12/10/2018

hi! I'm trying to write a script that, half the time, will pair items from picture and audio elements randomly for a trial. However, I also want to be able to set how frequently it samples matching files (i.e. 50% of the time, if "acorn.mp3" is selected from the video/audio element, "acorn.jpg" should be selected from the picture element). 

I'm trying to build a toy example but I've gotten nowhere-- I wonder if there's a way to use the startswith function? Or if all the items appear in the same order I could use / select and have it select for the same index as the other element? But if I did that I'd have to create two sets of audio and video elements and I don't want items to repeat during the experiment, plus I'm not sure how I would randomize the selection order across the elements.

Any thoughts appreciated!

<picture pictures>
/items=("acorn.jpg", "apple.jpg", "balloon.jpg")
/ hposition = 50%
/ vposition = 50%
/ size = (300,300)
</picture>

<video audio>
/items=("acorn.mp3", "apple.mp3", "balloon.mp3")
</video>

<trial trial>
/ stimulusframes=[1=audio; 10=pictures]
/ inputdevice=keyboard
/ validresponse=(57)
/ timeout = 1600

</trial>

<block myblock>
/ trials = [1-3=trial]
</block>

<expt myexpt>
/ blocks = [1=myblock]
</expt>
By Dave - 12/10/2018

S F - Monday, December 10, 2018
hi! I'm trying to write a script that, half the time, will pair items from picture and audio elements randomly for a trial. However, I also want to be able to set how frequently it samples matching files (i.e. 50% of the time, if "acorn.mp3" is selected from the video/audio element, "acorn.jpg" should be selected from the picture element). 

I'm trying to build a toy example but I've gotten nowhere-- I wonder if there's a way to use the startswith function? Or if all the items appear in the same order I could use / select and have it select for the same index as the other element? But if I did that I'd have to create two sets of audio and video elements and I don't want items to repeat during the experiment, plus I'm not sure how I would randomize the selection order across the elements.

Any thoughts appreciated!

<picture pictures>
/items=("acorn.jpg", "apple.jpg", "balloon.jpg")
/ hposition = 50%
/ vposition = 50%
/ size = (300,300)
</picture>

<video audio>
/items=("acorn.mp3", "apple.mp3", "balloon.mp3")
</video>

<trial trial>
/ stimulusframes=[1=audio; 10=pictures]
/ inputdevice=keyboard
/ validresponse=(57)
/ timeout = 1600

</trial>

<block myblock>
/ trials = [1-3=trial]
</block>

<expt myexpt>
/ blocks = [1=myblock]
</expt>

Something like this should do the trick:

<values>
/ pictureitem = 1
/ audioitem = 1
</values>

// 1 item is required for each "match" trial
// 2 items are required for each "no match" trial
// with 2 "match" trials and 2 "no match" trials,
// we need (2 x 1) + (2 x 2) = 6 items
// if no item is to repeat during the block
<list itemnumbers>
/ poolsize = 6
/ selectionrate = always
/ selectionmode = random
/ replace = false
</list>

<text pictures>
/items=("a.jpg", "b.jpg", "c.jpg", "d.jpg", "e.jpg", "f.jpg")
/ select = values.pictureitem
/ position = (50%, 40%)
</text>

<text audio>
/items=("a.mp3", "b.mp3", "c.mp3", "d.mp3", "e.mp3", "f.mp3")
/ select = values.audioitem
/ position = (50%, 60%)
</text>

// we sample one item number from the list
// and use it for both audio and picture
<trial match>
/ ontrialbegin = [
values.audioitem = list.itemnumbers.nextindex;
values.pictureitem = values.audioitem;
]
/ stimulusframes=[1=audio; 10=pictures]
/ inputdevice=keyboard
/ validresponse=(57)
/ timeout = 1600
</trial>

// we sample two item numbers from the list
// one for the audio and a different one for the picture
<trial nomatch>
/ ontrialbegin = [
values.audioitem = list.itemnumbers.nextindex;
values.pictureitem = list.itemnumbers.nextindex;
]
/ stimulusframes=[1=audio; 10=pictures]
/ inputdevice=keyboard
/ validresponse=(57)
/ timeout = 1600
</trial>

// we sample match and no match trials in equal proportions
<block myblock>
/ trials = [1-4 = noreplace(match, nomatch)]
</block>

<expt myexpt>
/ blocks = [1=myblock]
</expt>
By S F - 12/10/2018

This is fantastic, thank you! I'm expanding it to have many more items and I've just scaled up the pool size in multiples of 6 (as well as the items) and incremented the trials in multiples of 4.
By Dave - 12/10/2018

S F - Monday, December 10, 2018
This is fantastic, thank you! I'm expanding it to have many more items and I've just scaled up the pool size in multiples of 6 (as well as the items) and incremented the trials in multiples of 4.

Great! You are not restricted to multiples of 6 and 4, though, anything else works as well. For example, if you wanted to end up with, say, 45 match trials and 45 no-match trials (90 total), that would work out to 135 items needed.