Randomizing within a single routine

843 views
Skip to first unread message

Jose Camacho

unread,
Apr 19, 2012, 10:01:57 AM4/19/12
to psychopy-users
Hi,

I have an experiment that involves presenting two images with a text
below them for the participant to choose between them. Because these
pairs of images are different for each text, we have designed it as
separate routines, each involving a unique text and pair of images. A
loop with a single repetition encompasses all the routines.

My questions are the following:

a) Is it possible to have the presentation of the individual routines
randomized from participant to participant? As it stands, the loop is
set to randomize, but each run of the experiment presents the same
order.

b) (this is a more general question) Is it possible to draw the images/
texts from a single file? I understand this can be done when there is
only text (using an excel file), but I can't think of a way to do the
same to pair images with text.

Thanks,

Jose Camacho

Michael MacAskill

unread,
Apr 19, 2012, 5:37:29 PM4/19/12
to psychop...@googlegroups.com
Dear Jose,

I hope this helps, but it is more than possible that I've misunderstood your intended procedure.



On 20 Apr, 2012, at 02:01, Jose Camacho wrote:

> I have an experiment that involves presenting two images with a text
> below them for the participant to choose between them. Because these
> pairs of images are different for each text, we have designed it as
> separate routines, each involving a unique text and pair of images. A
> loop with a single repetition encompasses all the routines.
>
> My questions are the following:
>
> a) Is it possible to have the presentation of the individual routines
> randomized from participant to participant? As it stands, the loop is
> set to randomize, but each run of the experiment presents the same
> order.

Loop randomisation doesn't have any meaning when there is only a single repetition of the loop. Effectively there is only one "trial" here from PsychoPy's point of view, as a trial equates to a single iteration of a loop. So it can't be randomised: the one-and-only trial can only be presented first.

From the point of view of the subject, it might appear that there multiple trials are being presented, but in the PsychoPy world view, it is just a single trial with multiple stimuli being presented consecutively in a chain. You need to restructure things, but the good news is that it will be much simpler than what you have already done. You currently have a single (redundant) iteration of a loop, containing multiple routines. What you actually want is a single routine within a loop which repeats.

> b) (this is a more general question) Is it possible to draw the images/
> texts from a single file? I understand this can be done when there is
> only text (using an excel file), but I can't think of a way to do the
> same to pair images with text.

Certainly, this is the fundamental way in which PsychoPy is structured. You create a .xlsx or .csv file containing three columns, such as:

leftImage rightImage questionText
happy.jpg bored.jpg Who is happy?
myCat.jpg myDog.jpg Who goes woof?

etc
The randomisation works by selecting entire rows at random from the file, so the two images you want will always be paired with their correct text.

Create just a SINGLE routine, which draws two images and a text message. Put a randomised loop around the routine, and browse for your conditions .xlsx file. If there are, say, 50 trials, then there should be 50 lines in the .xlsx file and you should set the number of repetitions in the loop to be 50.
In the "image" field of the picture stimuli, type "$leftImage" (without the quotes) in one and "$rightImage" in the other. In the text stimulus, type "$questionText" in the text field. The $ symbol tells PsychoPy to get the current value of the .xlsx column with that name from the loop rather than to use the literal text you typed.

This arrangement means that you can easily change your experimental stimuli just by editing the .xlsx file, without having to edit an individual routine inside PsychoPy. It is then also easy to change the order of presentation, repeat trials, etc, just by changing the loop settings. PsychoPy will do the heavy lifting for you…

Regards,

Michael


Hezi Ben Sasson

unread,
Feb 24, 2015, 11:29:55 AM2/24/15
to psychop...@googlegroups.com
Hi guys.

Hope that's ok that I'm replying on an old topic (didn't want to open a new post since this one is very relevant to my issue).

I have followed your explanation about how to use the excel file to add pictures as a stimuli. However when I'm trying to run the experiment, the error that I'm getting is: 
image=leftimage, mask=None,
NameError: name 'leftimage' is not defined.

Where did I go wrong? Also, I put the pictures in the same folder of the experiment files and the excel file.

Thanks,

Michael MacAskill

unread,
Feb 24, 2015, 3:25:57 PM2/24/15
to psychop...@googlegroups.com

> On 25/02/2015, at 05:29, Hezi Ben Sasson <hbs...@gmail.com> wrote:
>
> NameError: name 'leftimage' is not defined.

Select "set every routine" rather than "constant" in the popup button next to the image field.

Michael

HBS

unread,
Feb 24, 2015, 4:40:12 PM2/24/15
to psychop...@googlegroups.com
Worked! Thanks a lot!

----
Hezi Ben Sasson


Michael

--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/yM8ZIGQoPUo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/1F0C1CE5-6C17-4D3C-9C24-C83DF3395D6A%40otago.ac.nz.
For more options, visit https://groups.google.com/d/optout.

Hezi Ben Sasson

unread,
Feb 25, 2015, 5:11:13 PM2/25/15
to psychop...@googlegroups.com
Circling back Jose's first question - 
I have a similar design in which participants see an image, and then are presented with a value. I have these two variables in an excel file (both of these routines are in a loop), and in the flow it looks as follows:

(routine of image + routine value) in a loop.

What is happening in practice is that, although the order of their appearances varies, each image is always paired with a certain value. How can keep this element (that is, to have fixed pairs throughout a participant's trial), while randomizing the pairs (image+value) from one participant to another? 

In other words, I want that within participants, randomization will stay the same (pairs to remain fixed), but across participants I want randomization to vary (that is, different pairs from one participant to another).

Thanks,

Michael MacAskill

unread,
Feb 25, 2015, 9:47:47 PM2/25/15
to psychop...@googlegroups.com
The only way to do this is to open the conditions file at the very start of the experiment, shuffle its columns relative to each other, and then save it back to disk. If this is done at the start of each participants' session, it will achieve what you want.

To automate this will require you to insert a little code in a code component within Builder. See here for guidance: <https://groups.google.com/forum/#!topic/psychopy-users/WljgXeoy6Ik>

Also, be sure to use a .csv rather than .xlsx file for ease of reading in and writing out again.

Regards,

Michael

zgabrie...@gmail.com

unread,
Jun 20, 2016, 11:44:36 AM6/20/16
to psychopy-users, michael....@otago.ac.nz
Hi, I was several days trying with this suggestions, but I was not able to do what I need. I work with language, I am new in PsychoPy, I have been using SuperLab before. 
In short, I need to randomize several sequential pairs of [sentence-word]. I have several counterbalanced lists with 36 different pairs each and I need the presentation of the 36 pairs to be random, changing subject to subject. This is: always the same sentence with the same word (sequential), but this pairs, random. How can I do this in PsychoPy, because make random the loops is not working, and the problem is not exactly the same in a full factorial design like the one discussed here.
If somebody could explain it to me like "PsychoPy for dummies", it would be vey useful...because I am new in Python as well and I don´t understand all syntax of scripts.

Thank you very much.

Gabriela

Michael MacAskill

unread,
Jun 20, 2016, 3:57:58 PM6/20/16
to <psychopy-users@googlegroups.com>
Dear Gabriela,

So as I understand it, you have several lists of 36 pairs that you want to vary across subjects. The best way to do this is use a variable in the conditions file field of your loop rather than a literal filename. That way, you specify what conditions file is to be used on each run. 

If you click on the experiment settings icon in the Builder tool bar, you can add a new field to the "Experiment info" dialog that appears at the start of the experiment. e.g. add a a field called, say, "condition_file". Then in the loop dialog, put this in its conditions field:

expInfo['condition_file']

It's best not to try to get Builder to do this actual random selection of files for you. Probably easiest just to draw up a random/balanced list yourself as required in a spreadsheet and then type in the name of the desired conditions file on each run as needed.

Regards,

Michael

zgabrie...@gmail.com

unread,
Jun 21, 2016, 10:29:01 AM6/21/16
to psychopy-users
Hi, Michael. Thank you very much. In fact, I don´t think is exactly this what I need. I have already my lists manually counterbalanced, as I understand you suggest, and I will manage manually which list I present to each subject, depending on the subject. What I need is to present the 36 sequential pairs of each list (intra-list) in a random way. The problem I am having is that if I make sentence-word sequential (from an excel file), the presentation of this pairs, as a unit, is also sequential: this I want to be random.
I don´t if I am being very clear, I am sorry, my english is a bit rust.

Best regards and thanks,

Gabriela

Michael MacAskill

unread,
Jun 21, 2016, 12:00:28 PM6/21/16
to psychop...@googlegroups.com
Dear Gabriela,

This is exactly what selecting "random" as the loop type will do. Entire rows are selected randomly, so your pairs stay together (I'm assuming you have two columns: one for the sentences and one for the words).

Regards,

Michael
  


On 21/06/2016, at 16:29, zgabrie...@gmail.com wrote:

Hi, Michael. Thank you very much. In fact, I don´t think is exactly this what I need. I have already my lists manually counterbalanced, as I understand you suggest, and I will manage manually which list I present to each subject, depending on the subject. What I need is to present the 36 sequential pairs of each list (intra-list) in a random way. The problem I am having is that if I make sentence-word sequential (from an excel file), the presentation of this pairs, as a unit, is also sequential: this I want to be random.
I don´t if I am being very clear, I am sorry, my english is a bit rust.

Best regards and thanks,

Gabriela

-- 
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph:   +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill

zgabrie...@gmail.com

unread,
Jun 21, 2016, 12:48:17 PM6/21/16
to psychopy-users
Dear Michael,

That is exactly what I understood in the first time, and I have set it like this, but for some reason is not working. I had assumed that this was not the correct way to do it, but now I think maybe another thing is wrong. I will keep trying. Thank you a lot. Best, 

Gabriela
Reply all
Reply to author
Forward
0 new messages