Randomly pair two stimuli together in builder

OS MacOS 10.15.3 PsychoPy version 3.2.4 Standard Standalone? (y/n) y

I’m putting together a face memory experiment that pairs faces with different types of behaviors, then tests people’s memory for the faces they saw.

The whole paradigm works as follows:

Fixation cross: 1s
Face presented: .5s
Behavior presented: 5s
Fixation cross: 1s
Face array presented: until decision made

The faces at presentation are all neutral, just different identities per trial, 24 in total. I have 3 different categories of behaviors, 24 each, so a total of 72 different behaviors. Counterbalancing face/behavior pairings would mean that there would be 9 different versions made. Ideally, I’d like to have 3 counterbalanced blocks, with face/behavior pairings randomized within each block. That way, across each block, each face identity has the same chance of being paired with one type of behavior as any other.

I’ve never had luck doing this in the past, and one issue I’m running into is making sure that I can randomize face presentation and behavior presentation independently, while still tracking which type of behavior was shown using ID codes (i.e., a01, n03, p07) in the data.

Another trick is, this ideally would translate to psychoJS, since the pandemic dictates that we need to run all studies on line.

Any help would be appreciated!

Also, if more details are needed I’d be happy to provide them.

There is a bit of a trick you can do to randomise two things separately in the same loop - it’s easier to show than tell, so here is an example experiment I just made which does it as simply as possible:
indrand.psyexp (11.2 KB)
strings.csv (41 Bytes)

Essentially, you create a loop with the number of repetitions you want, and make each row of the corresponding csv file a list of all the possible values, separated by a delimiter (here I use a comma). The first thing you’ll need to do is import random.numpy.choice so you have access to this function. You can do this using a Code component, with this in the Begin Experiment tab:

from numpy.random import choice as rndchoice

Using a Variable component, you can create a variable (I called mine txt1 and txt2) with the value set to be rndchoice(COLUMN NAME.split("DELIMITER")). So, essentially, you’re saying “Take the value of this column, split it at every delimiter (a comma, in my example) so that it’s a list of strings, then choose one item at random from this list”.

Then you can just use this variable (preface it with a $ so that Psychopy knows to interpret it as a variable name) in your stimuli.

Thanks for this! Would you mind including the code you inserted in the code component? For some reason I can’t seem to open it.

Sure, it was just this:

from numpy.random import choice as rndchoice

In the “Before Experiment” tab. If you’re using an older version of PsychoPy, it may not have that tab as we only added it recently, but it should work in “Begin Experiment” too.