Alternate between image_stim and text_stim

Hi everyone,
I am trying to build an IAT task. I explain everything to be as clear as possible :

This is my routine “trial”.

We can see two loops : 1. blocks and 2. trials

  1. Blocks refers to an xlsx file :


    In this file, we find condition file (7 conditions), left and right label (to categorize) and instruction (appears un ready routine)

  2. In trials, I have each condition file, we find :


    StimImage and StimWord with image reference and words. Some condition have only image or only text, for training condition.

Everything works perfectly but I have one problem : in condition with image AND text, I need to alternate between this two type of stimuli (picture/text/picture/text/…) but still in a random way and I really don’t know how to code it. Do you have any idea ?

Please define your randomisation scheme precisely, as you would in a methods section. Your requirements are not clear at the moment. e.g. if it is random, how can it also alternate?

Sorry !
For example, there are 20 words and 20 images. I would like to alternate between words and images but the images / words selection in this 20 images / words is random.

OK. That won’t be possible using a single conditions file - if you set the loop to be random, it will shuffle all of the rows and you won’t be able to ensure an alternation of conditions between rows.

It would be possible using custom code, or using a more complicated structure in Builder. Let’s go with the latter route for the moment:

  • You will need two routines, one to show an image and one to show a word.
  • Each of those routines will need to be surrounded with its own loop, called, say, image_trials and word_trials.
  • Each of those loops is connected to a separate conditions file, one to control words, and one to control the images.
  • Surround the two inner loops with another loop. This is not connected to a conditions file, but just given an nReps value of 20. It goes in between your trials and blocks loops.

So what you need to do now is arrange for each of the inner loops to only run one iteration rather than loop through all 20 rows of the conditions file in one go, but you need to ensure that all 20 rows are eventually consumed, with no repetition. We can do this by creating two lists of indices that pseudo-randomly select just one row per iteration of the outer loop. So insert a code component (from the “custom” component panel), on any routine. In its “begin experiment” tab, put something like this:

image_order = range(20) # indices 0 through 19
shuffle(image_order)    # in randomised order

word_order = range(20)
shuffle(word_order)

Then in the “selected rows” field of your inner loops, put:

$image_order[your_outer_loop_name.thisN]

and

$word_order[your_outer_loop_name.thisN]

respectively.

This should give you alternation between trial types, while randomising the order of chosen stimuli, without any repetition.

You will need to alter your blocks conditions file accordingly, so that it now controls two conditions files per block, rather than just one, because you have now split the words and images into separate files.

Hello Ilona,
thank you for your code! Unfortunately, it’s not working for me. I think because the range and shuffle function isn’t working… You mentioned another option using code. Could you maybe eloborate on that?

Thank you very much!

I have the same problem. Could you find a solution?

If you want to shuffle 20 images and 20 words independently, then I would recommend looking at my independent randomisation online demo.

You could then have an image routine drawing from the spreadsheet in the loop and a word routine drawing from the preloaded list.

Thanks!
In the meantime I have found another solution:

Code:
import random
a =

a1 = random.sample(range(0, 10), 10)
a2 = random.sample(range(10, 20), 10)

max_number_of_elements = min(len(a1), len(a2))

for i in range(max_number_of_elements):
a.append(a1[i])
a.append(a2[i])

if len(a1) > max_number_of_elements:
a.extend(a1[max_number_of_elements:])
if len(a2) > max_number_of_elements:
a.extend(a2[max_number_of_elements:])

I have created a list ‘a’ that alternately contains a number from 0 to 9 and 10 to 19. In the Excel spreadsheet, image references are listed in rows 0 to 9, and words are listed in rows 10 to 19. In the ‘Selected rows’ section of the Loop, I specify that the list ‘a’ should be used.

Hi,
I have used it but I dont know why it didnt work. Could you please help me with this? Thanks.