Millisecond Forums

Constrained randomisation trouble

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

By LMK - 6/5/2012

Dear forum,


I’m a little trapped by a tricky design for a false memory experiment.  The issue is that I have 60 sets of 5 associates (e.g., ADD: subtract, sum, plus, multiply, maths), half of which will be presented randomly (i.e., any associate from any list can be presented as part of a 5 stimuli sequence before a textbox appears for recall), and half of which need to be presented as complete sets (i.e., “lists”)  in the sequence specified (e.g.,  1 = subtract, 2 =  sum, 3 = plus, 4 =  multiply, 5 = maths). Unfortunately, the sets that become “random” and those that become “lists” are ideally random too, however, to satisfy the constraints (the researchers would REALLY like for all stimuli to be presented to each participant, and NEVER to appear more than once) this assignment seems to need to be done at the beginning of the experiment.


For completeness, there is also a picture element. Specifically, the design is 2 (random, list) by 3 (no picture, matched picture, unmatched picture). This works fine.


So, I hit problems if I have “random” sequences presented first –because single items are chosen from too many whole sets (e.g., 10 random sequences can draw from 50 “lists”, leaving only 10 unsampled lists rather than the 30 needed) . This will be true for 50% of participant. I figure that if I could randomly assign sets to be used for “random” versus “lists”, I could fix this, but I can’t seem to work out how to do this (probably at the experiment level).  


The code is huge (and includes 300 images too) so I have left it out. Any suggestions on how this could be achieved would be GREATLY appreciated!


Thanks, Leah

By Dave - 6/5/2012

You will have to use conditional logic to determine a given set's selection mode (random vs. list) and then sample from the set's items accordingly. Here's a simple example which should hopefully provide some pointers:


<values>
/ set1selectionmode = ""
/ set2selectionmode = ""
/ set1item = 0
/ set2item = 0
</values>

<counter setselectionmodes>
/ items = ("random", "list")
/ select = noreplace
/ selectionrate = always
</counter>

<expt>
/ onexptbegin = [values.set1selectionmode=counter.setselectionmodes.selectedvalue;
    values.set2selectionmode=counter.setselectionmodes.selectedvalue]
/ blocks = [1-2=noreplace(set1block, set2block)]
</expt>

<block set1block>
/ trials = [1-4=set1trial]
</block>

<block set2block>
/ trials = [1-4=set2trial]
</block>

<trial set1trial>
/ ontrialbegin = [if(values.set1selectionmode=="random")values.set1item=counter.set1random.selectedvalue else
    values.set1item=counter.set1sequence.selectedvalue]
/ stimulusframes = [1=set1]
/ validresponse = (57)
</trial>

<trial set2trial>
/ ontrialbegin = [if(values.set2selectionmode=="random")values.set2item=counter.set2random.selectedvalue else
    values.set2item=counter.set2sequence.selectedvalue]
/ stimulusframes = [1=set2]
/ validresponse = (57)
</trial>

<text set1>
/ items = set1items
/ select = values.set1item
</text>

<text set2>
/ items = set2items
/ select = values.set2item
</text>

<counter set1random>
/ select = noreplace(1-4)
</counter>

<counter set1sequence>
/ select = sequence(1-4)
</counter>

<counter set2random>
/ select = noreplace(1-4)
</counter>

<counter set2sequence>
/ select = sequence(1-4)
</counter>

<item set1items>
/ 1 = "1a"
/ 2 = "1b"
/ 3 = "1c"
/ 4 = "1d"
</item>

<item set2items>
/ 1 = "2a"
/ 2 = "2b"
/ 3 = "2c"
/ 4 = "2d"
</item>


Regards,


~Dave

By LMK - 6/6/2012

Dear Dave,


This looks great, and I think I get it..... but will have to wait until the weekend to try it out.  Just wanted to say thanks.


Cheers, Leah

By LMK - 6/10/2012

Dear Forum (Dave),


The above code works beautifully. I have filled in a subset of the 60 lists and it’s perfect. Unfortunately, it won’t let me use the cheat I had developed to assign the images, so having tried all the things I could think of, I’m stuck again!


So, following on from my previous message, I have successfully assigned each of my sets to a random versus sequence mode (using your code), so I am now trying to also set these to a picture mode (related, unrelated, none – using a shape). I have guessed that the / onexptbegin is the best option, using an empty item which I have tried to fill with the correct picture items.  Again, the tricky thing here is that if the pictures are “related” they should be linked (I have a counter with /select = current(related set), whereas if they are unrelated they can be anything from the set, presented without replacement). I’m not sure if it’s possible, but it seems like it would be.


I think the issue is that I don’t really know what I am doing (or can do) with / onexptbegin.



One last point, it would be ideal if this, like the random/list assignment was equal (i.e., of my 60 sets, 10 would be presented random with related pics, 10 would be presented random with UNrelated pics, 10 would be presented random without pics, 10 would be presented list with related pics, 10 would be presented list with UNrelated pics, 10 would be presented list without pics).



I would (again) appreciate any assistance. This time I have attached the subset of image (zipped folder) and script* I have been working with. I have uploaded these to my files. I didn’t find an option to attach it directly to this post.


Many thanks, Leah


*Note I have been working in phases so some bits of the script are in older phases.

By Dave - 6/10/2012

You should first fix the various syntax issues in your <picture> elements' /items attribute. E.g.


<picture ballpic>
/ items = (1 = "bounce.jpg",2 = "soccer.jpg",3 = "bat.jpg",4 = "throw.jpg",5 = "round.jpg")
[...]
</picture>


is wrong. Correct syntax would be


<picture ballpic>

/ items = ("bounce.jpg","soccer.jpg","bat.jpg","throw.jpg","round.jpg")

[...]

</picture>


Unfortunately you didn't include all required pics, so your script can't be run. Regardless, very much the same strategies as outlined previously should apply: Assign the correct type of picture to each set based on conditional logic. See e.g. https://www.millisecond.com/forums/Topic3960.aspx for one way to do such things with pics.


Regards,


~Dave

By LMK - 6/10/2012

Dave,


Thanks for the super quick response again.


I have had a look at https://www.millisecond.com/forums/Topic3960.aspx  and tried to download DynamicPictureLoading.zip but keep getting the message "The Compressed (zipped) Folder is invalid or corrupted." when downloading or attempting to extract.


Is there any way I could access just the example script (without the .zip)?


Cheers, Leah


By Dave - 6/10/2012

The respective zip file downloads and extracts perfectly fine for me -- I'm re-attaching it here.

By LMK - 6/10/2012

Dear  Dave,


I'm still having trouble which must mean its an issue of an old PC. I will try again from work tomorrow.


Thanks, Leah

By Dave - 6/10/2012

Weird. Anyway, I'm pasting the syntax from the respective script below for reference:


### Some initialization
<defaults>
/ screencolor = (255, 255, 255)
/ inputdevice = keyboard
</defaults>


### Counter to select one of the pictures in the sets ITEM_male and ITEM_female
<counter COUNTER_pic>
/ items = (1, 2, 3)
/ select = noreplace
/ selectionrate = trial
</counter>


### Counter to select the gender of the picture to be displayed
<counter COUNTER_gender>
/ items = (0, 1)
/ select = noreplace
/ selectionrate = trial
</counter>


### Items with the file names of the pictures to be displayed
<item ITEM_male>
/ 1 = "..\pic\img_male_asia_001.gif"
/ 2 = "..\pic\img_male_blac_001.gif"
/ 3 = "..\pic\img_male_cauc_001.gif"
</item>

<item ITEM_female>
/ 1 = "..\pic\img_feml_asia_001.gif"
/ 2 = "..\pic\img_feml_blac_001.gif"
/ 3 = "..\pic\img_feml_cauc_001.gif"
</item>


### Picture stimuli referring to the just declared picture file names
### These stimuli won't be needed anywhere else in the script but
### are mandatory to have Inquisit preload and store the picture
### files at startup.
<picture PIC_male>
/ items = ITEM_male
</picture>

<picture PIC_female>
/ items = ITEM_female
</picture>


### The canvas picture that will be used to display any given
### picture during a trial. The key concept is the empty item
### which will be loaded with the file name of the picture to
### be displayed.
<item ITEM_canvas>
</item>

<picture PIC_canvas>
/ items = ITEM_canvas
/ position = (50, 50)
/ transparentcolor = (255, 255, 255)
</picture>


### This is where the magic happens. First, the canvas item is
### cleared from the picture file name assigned to it during the
### previous trial. Then, a new picture file name is loaded into
### the canvas item depending on the gender counter.
### The canvas picture is finally processed by Inquisit. It will
### find the just loaded picture file name in the canvas item
### and display the according picture.
<trial TRIAL_showall>
/ ontrialbegin = [clear(item.ITEM_canvas)]
/ ontrialbegin = [if(counter.COUNTER_gender.selectedvalue==0)
                             {item.ITEM_canvas.item=getitem(item.ITEM_male,counter.COUNTER_pic.selectedvalue)}
                           else
                             {item.ITEM_canvas.item=getitem(item.ITEM_female,counter.COUNTER_pic.selectedvalue)}]
/ validresponse = (anyresponse)
/ responseinterrupt = trial
/ stimulusframes = [1 = PIC_canvas]
</trial>


### Block to repeat the trial
<block BLOCK_showall>
/ trials = [1-10 = TRIAL_showall]
</block>


### Experiment
<expt>
/ blocks = [1 = BLOCK_showall]
</expt>


Regards,


~Dave

By LMK - 6/10/2012

Dave,


Greatly appreciated! 


Thanks, Leah

By LMK - 6/17/2012

And one last time....


I'm sure I have gone with inefficient and - given this message, flawed coding - but, I have got it to present text and pic stimuli and its nearly doing what I want....


The problems the script will typically run, however, it (seemingly randomly - i.e., sometimes between blocks, sometimes mid-block) stops and a message along the lines of " Unabled to initialize <picture addp> item number 0. Verify the item exists and is correctly defined".


There's also a quirk that sometimes the <counter xxxsequence> (compared to <counter xxxrandom>) seems to present all items, but not in order. This is true of both text and pic stimuli. I'm certain I have caused this as it was fine until I began fidling with the pictures, but can't seem to uncause it.


I will load the script and pics (all this time).


Any suggestions, corrections or efficiencies are, AS ALWAYS, greatly appreciated. I must admit that this code is generalised with very limited knowledge so I have relied with various levels of success ontrial and error to get things to "go".


Thank you,
Leah


By Dave - 6/17/2012

Both "quirks" sound like bonafide programming errors on your part. You'll want to examine test data files of such failed runs to figure out where / when the errors occur exactly and then work backwards through your script's logic.


The problems the script will typically run, however, it (seemingly randomly - i.e., sometimes between blocks, sometimes mid-block) stops and a message along the lines of " Unabled to initialize <picture addp> item number 0. Verify the item exists and is correctly defined".


Probably means you've failed to assign the item properly. Check the conditional logic in the respective <trial>'s /ontrialbegin etc. attributes responsible for assigning items to the respective <picture> element.


There's also a quirk that sometimes the <counter xxxsequence> (compared to <counter xxxrandom>) seems to present all items, but not in order. This is true of both text and pic stimuli. I'm certain I have caused this as it was fine until I began fidling with the pictures, but can't seem to uncause it.


Probably means there's a flaw in the conditional logic responsible for determining the correct selection mode. Again, you'll want to carefully check the portions of your script responsible for handling that.


Regards,


~Dave

By LMK - 6/25/2012

Hi!


Thanks for you all your help.  I went back to basis and now almost everything is working....


My last issue is I'm having trouble with a counter, specifically <counter nonmatchpic>. I'm seeing pictures repeat across blocks and mutliply times with the experiment even though there are enough stimuli and I have set the resetinterval = 1000.  All the other counters seem fine.


Like always, any assistance would be gratefully received!


Thanks, Leah


By Dave - 6/25/2012

Umm, I've misplaced my crystal ball and tarot cards, so I'm not sure how to tackle this without, you know, access to your script and such...;-) Anyway, if I were to hazard a guess, this again sounds like a bonafide programming error...

By LMK - 6/25/2012

Dear Dave,


Very plausible. The script is posted (to the same place as usual.... new.exp and using the same images (zipped folder + blank) as usual.


I'm sure it will be easy to spot in my (now much simplified) script.


Cheers, Leah


By Dave - 6/25/2012

#1: For better context, you might consider attaching any materials to the respective thread instead of your profile. Alternatively mention the files you are referring to and their location.


#2: There is no element called <counter nonmatchpic> in the files you posted.


#3: The script will not parse and cannot run because you are trying to use a counter property which does not exist (.currentvalue).

By LMK - 6/25/2012

Dear Dave,


Very good points.... I guess I'm getting too tired to be useful (it's nearly 1am here).


I will definitely append scripts to post in future...... also I should have said <counter addnonmatchpic>.


Thanks, Leah

By Dave - 6/26/2012

Well, you have 15 items available in your nonmatched picture condition. However, a given participant will receive 20 trials (4 blocks of 5 trials), i.e., the respective counter will inevitably have to reset after the 3rd block as it's out of unused items by then. Consequently certain items will have to be repeated.

By LMK - 6/26/2012

I'm pretty confident that this is not the problem. 


When I reduce the number of blocks in the experiment to 3 (which would present 15 pictures (i.e., the number in the list), at least a thrid of picture are repeated, AND thet repetition begins in the second block (after only 5 or 15pics have been presented). It seems to be replacing after every block (I assume this is the case as I have not seen repetition within blocks).


What also interesting is that, although I have used "noreplace" and "resetinterval = 1000", when I reduced the number of block in the experiment to 2 (i.e., /blocks = [1-2= addblock]) four out of five pictures were repeated in the second block the first time I ran is, but only 1 out of 5 the next time i ran it.


It seems like the counter isn't working. I have tried /select = sequence(1-15) and the first block presents all items in the sequence (1-5) in perfect order, but the second repeats items and not in order?!  If, however, I set the list to the same number of items to the number of trials (e.g., sequence(1-5) or even (6-10)) each block presents the correct pics in the correct order (i.e., behaves as predicted). I'm not even sure where to look for the problem.


If there is no solution, I guess I could creat correct length (1-5) sets of randomised order and present these, but it seems like an expensive cludge.


Any suggestions?


Thank you for your help (again, and again, and again).


Cheers, Leah





By Dave - 6/26/2012

Correct, that's not the *only* problem. The selection problem is due to this:


/ ontrialbegin = [if(values.addpicselectionmode=="unmatched")item.addpicitem.item=getitem(item.addnonrelpic,counter.addnonmatchpic.selectedvalue)]


which instructs Inquisit to pull a random item from the counter and append it to <item addpicitem>. It does *not* determine which item <picture addp> will then *sample* from <item addpicitem> -- it will sample from whatever's in there randomly. See e.g. https://www.millisecond.com/forums/Topic8154.aspx#8154 for some more details. You'll want to fix that.

By LMK - 6/27/2012

Again, THANK YOU!


I had been wondering how this works. I think I'm sorted now.


I really appreciate the instruction. I'm very novice, but have learnt a lot by doing this.


Cheers, Leah