[open] Conditional randomization
Hi,
I saw that there were a couple of forums about randomization, but I either did not understand it well, or the particular question I had wasn't answered. My apologies if it is the former and this is redundant.
I have a short experiment with 16 critical items and 4 filler items. I want near-total randomization, with the condition that a participant see 1 filler item after 4 critical items. In other words, no more than 4 reps of the critical item. Is there a reasonably straightforward way to accommodate this requirement?
Thanks!
-A
Comments
Hi,
If you want to have the filler item at every 5th position, you can do following.
What you need is an
inline_scriptbefore the trial loop and oneinline_scriptwithin theloop(and of course all other stuff you might need for your experiment).First, you define three lists, one for critical, one for filler items and an empty one, which will contain all items, in an
inline_scriptand shuffle them. Then you append all the items to the empty list by adding items from the critical list and every 5th element items form the filler list. TheModulofunction will do the trick. The script could like this:Within the
loopelement you set a helper variable that works basically as a counter and add as many repetitions as you have items.Finally, you pick the item from the item list by setting the variable in the
prepare phaseof theinline_script, to the current value of the list:From then on, you should be able to use the item, e.g. by [cur_item].
This is maybe not the most efficient way, but it works. If you need more help, please let us know.
Eduard
Hi Eduard,
Thanks so much for this! I haven't gotten this to work though, but I suspect it is because my experiment turns out to be a bit more complicated than I first made it out to be. So each item (critical and filler) consists of a pair of pictures that must appear sequentially in a set order.
Right now, in my list of variables, I have columns for item# (1-20, critical = 1-16, filler = 17-20), image1, and image2. For each trial, Image1 for each item gets called first, followed after about 2 secs by Image2.
I modified your code to specify the rows that belong to the critical and filler items, and it looks like I've already messed up!
define inline_script inline_script1
_run
from random import shuffle
I'm quite new to OpenSesame, so my apologies if this is too basic!
Relatedly, I wonder about your helper variable. I won't just be able to call the item using [cur_item], since I would need to call, e.g., image1 for cur_item, followed by image2 for the same. How can I modify the code to do this?
Thanks again!
Hi,
Alright, if your items consist of two images each, you don't have to change much. It requires though, that your pictures are labelled according to the same scheme. For example: Picture_1a, Picture_1b, ...
For each picture that belongs to one item, you add one
sketchpadto thesequenceand put one picture into it. Afterwards, you open thescript viewand change the name of the picture file from, let's say, "Picture_1a" to "Picture_[cur_item]a" and likewise picture 1b. By doing so, you create a placeholder that is dynamically filled with the picture of respective trial.The general idea is described quite detailed in the step-by-step tutorial, step 6.
Oh, by the way, when I said you don't have to change much, I meant in comparison to the code I posted earlier. I didn't entirely understand in which way you modified your code. Sorry for that.
Eduard
Hi,
Thanks again. The latter part you said makes sense to me, but the first portion about defining the lists is still giving me trouble.
For some reason, I am failing to execute the (pretty much exact) code you gave in your first response. The error I am getting is "IndexError: pop from empty list"
I then try to define the lists manually (in the prepare phase of the inline script), e.g., as follows, and I continue to get the same error...
Did you also add the part, where you fill the list
all_items? Can you also post the part where you use thepopfunction? If I try the code in my first response, I don't get an error, so I guess this part has to be changed a bit.For this, I haven't changed your code at all. I have tried entering this in both the run phase and the prepare phase, but neither has worked.
This is weird, because it works just fine for me. Can you maybe give some more detail on the error that is shown to you? You can inspect it yourself in the
Debug window.Mostly, I am curious in which inline script and which line the error occurs.
What you also can do, is printing the lists and to see whether they look like you think they do (e.g.
print filler, and check again theDebug Windowfor the results).I got this to work (thank you!), but I have a follow up question. For each item, the correct response is either 't' or 'f', and I want to be able to log not just which key was pressed by the participant, but also compute accuracy. However, defining correct response in the variable list won't work anymore. Is there a way I can define in, e.g., the critical list, what the correct response is for each item? If yes, how do I refer to this when logging accuracy?
Sorry if this is too basic a question. I fairly new to OS and very new to inline scripts!
Well, you can simply add another field to your list, which contains the correct response.
E.g.
From then on you have to check whether the actual response equals the correct response and keep on counting:
Please make sure that [response] is really the proper variable that records the keypress of the participants. The other variables (exp.cor, exp.trials, exp.acc) you have to define yourself. In the beginning of your script you have to intialize them first (set them to 0).
Good luck,
Eduard
Thank you, and sorry for the late response.
My concern is the following. Currently, my critical and filler lists have singleton items ( ['1', '2', '3'...] ) and I call sounds and images using this (e.g., [cur_item]_pic1.png). If I change the items to tuples (e.g., ('1', 'correct_resp')), is there a way I can make reference to just the first field in the item when calling images, etc.?
What I have tried instead of your code is defining a dictionary with the correct response, in addition to the list. Currently, my code looks as follows:
inline_script1 prior to the experiment loop
inline script2 inside the experiment loop
cur_correct is what I was hoping to be the variable noting accuracy for a given trial.
inline script3 inside loop, after keyboard response
This doesn't seem to work. The experiment runs, but in the csv file, it is clear that cur_correct is not calculated accurately. Could you tell me where I might be going wrong?
Hi
Yes, you have to use indices. So to access an image called "1_pic1.png" and and a item list with the shape
(('1',correct_resp),'2',(correct_resp),...), you simply write[cur_item][0]_pic1.pngto access the first value in the list and connect it with the rest of the filename.I guess the reason why your script isn't working, is that there is no variable called "response_Answer" unless you have defined it yourself somewhere. The auto-logged variable that stores the key, which was pressed is called "response". Can you check whether this is already enough to fix it?
Eduard
Hi,
I have an almost identical question. I have been trying to get the code posted above to work, but I receive the error when I try to run it.
I have a setup where I want to run two critical (out of four critical items), then one (out of two filler items) randomly and then repeat the process with the leftover two critical and one filler item.
As I have to access different pictures, numbers etc. during my sequence which I have specified in my loop, it is important that these can still be accessed by the sequence.
Currently my code is as follows:
Run part of Inline script 1 (before loop)
Prepare part of inline script 2 (within loop)
I have also included the helper variable [cur_item] in my loop along with the numbers 1-6 as called.
I am still new to OpenSesame, and especially to coding, so I am probably missing some small aspect somewhere.
Thank you!
Aurelia
Hi Aurelia,
The tips in this discussion are a bit dated. As of v3.1, OpenSesame natively supports some forms of constrained randomization; that is, in the
loopitem, you can specify a maximum number of repetitions, or a minimum distance between repetitions.See also:
If this fits your needs, it's probably much easier than doing the same thing with a script!
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastian,
Thank you for your quick response. I am currently running my experiments on version 3.0.7, as this is the version installed on the experimental computers. If I update my computer to the newest version of Opensesame, will the program be compatible to be played with the earlier version of it?
I have a question regarding the possible constraints. If I understand the page correctly, I cannot specify that I want two of the critical items and then one fixed item but only that there should be maximally two critical item behind each other. Is there maybe some way to code giving the filler items a fixed spot?
Thank you,
Aurelia
No, I'm afraid not! You can use 'No installation required' package though.
Probably, but you'll first have to give a concrete and complete description of your criteria. For example, do you mean:
Once you have that clear for yourself (you may already have that, of course, even though the description wasn't), then you can think how you can use the
maxrepandmindistconstraints to implement it. I think it should be possible!Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
Thank you for your answer. I am using a Plugin for the VU-AMS measuring device which does not work on the newest version. Therefore, I cannot update to the newer version.
I mean your second criteria: Two critical items followed by exactly one fixed item.
Is there any way I can code this in the earlier version?
Thank you!
Aurelia
Hi Aurelia,
I didn't put this on the www.vu-ams.nl website yet as I'm still working on it, however (
) the VU-AMS plugin (version => 1.5) is OpenSesame 3 compatible:
Hope this helps,
Jarik
Hi Jarik,
Thank you for your help! This is of course the ideal situation. Will version 1.5 run without problems or is there something I should look out for?
Aurelia
Hi Aurelia,
There's nothing specific to look out for, but it's always important to thoroughly test your experiment and check the VU-AMS data for the sync markers.
One more handy note; you can make VU-AMS recordings without putting on electrode stickers or even without connecting the ECG/ICG electrode cable. You will only record noise but will be able to open the 5FS file in VU-DAMS to check if all event markers are stored.
You could even disable the triple beeps you get because of the out of range physiological signals via the Warning button in the configuration window. But don't forget to turn them back on!
If you run into any problems with the VU-AMS plugin please start a new discussion here or in the VU-AMS forum
Best,
Jarik