psychopy.org | Reference | Downloads | Github

Randomisation of image position (with certain feedback) between subjects

Hi everyone!

I have an experiment that involves presenting two images, participant clicks one of them and a feedback (points) with certain probability appears. The feedback is different for each image. There are 6 loops each containing different pair of images leading to a specific feedback for that image, and there are 100 trials in each loop.

Is it possible to present the images bounded to certain feedback in random location (right vs. left) between participants, but keep the location constant for each participant?

I tried this: in the routine AFTER participant made a choice, I put the code component for certain feedback to appear:

keys = event.getKeys()

if response.keys == ‘left’ and left11 == ‘red.png’:
hpos = [-0.5,0]
deckshown = 'redHIGH.png’
unchosenpoints = 1.5
unchosendeck = 'grey.png’
unchosenpos = [0.5, 0]
pointswon = points

elif response.keys == ‘left’ and left11 == ‘grey.png’:
hpos = [-0.5,0]
deckshown = 'greyHIGH.png’
unchosenpoints = points
unchosendeck = 'red.png’
unchosenpos = [0.5, 0]
pointswon = 1.5

if response.keys == ‘right’ and right11 ==‘grey.png’:
hpos = [0.5,0]
deckshown = 'greyHIGH.png’
unchosenpoints = points
unchosendeck = 'red.png’
unchosenpos = [-0.5, 0]
pointswon = 1.5

elif response.keys == ‘right’ and right11 == ‘red.png’:
hpos = [0.5,0]
deckshown = 'redHIGH.png’
unchosenpoints = 1.5
unchosendeck = 'grey.png’
unchosenpos = [-0.5, 0]
pointswon = points

But I get an error :

File “C:\Users\u1664328\Dropbox\1. Alina\Project\Computational and Mathematical Modeling of Behaviour and Cognition\1.My Project\2. Description-Told Group\DescriptionTold.py”, line 492, in
image.setPos(unchosenpos)
NameError: name ‘unchosenpos’ is not defined

There are a number of reasons why the unchosenpos variable can be undefined at the time it is referenced.

In this case, the most likely reason is that none of your conditional statements are executed. event.getKeys() returns a list, even for a single key press (hence getKeys rather than getKey). So you should do a test like this:

if 'left' in keys:

rather than:

if keys == 'left': # will always be untrue as keys is a list

Also note that you are mixing references to your own variable keys and some other variable response.keys. Which one are you actually wanting to test?

1 Like

Thank you very much for your reply, Michael!

I need to test response key from Trial routine. I have the code that I described above in highlight_2 routine on top of other components.

In block1 loop there is an .xlsx file that specifies the odds of getting certain points for each image for 100 trials:

I tied this:
1.


if 'left' in keys and left11 == 'red.png':

Get Error:

Description-Told Group\DescriptionTold.py", line 500, in <module>
    image.setPos(unchosenpos)
NameError: name 'unchosenpos' is not defined
keys = event.getKeys()

if 'left' in response.keys and left11 == 'red.png':

Get Error:

##### Running:
pyo version 0.8.0 (uses single precision)
Traceback (most recent call last):
Description-Told Group\DescriptionTold.py", line 469, in <module>
    if 'left' in response.keys and left11 == 'red.png':
TypeError: argument of type 'NoneType' is not iterable
Traceback (most recent call last):
  File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.84.2-py2.7.egg\psychopy\app\coder\coder.py, line 2638, in copy
    foc.Copy()
AttributeError: 'AuiTabCtrl' object has no attribute 'Copy'

My question:
I can’t get my head around how can I randomise the location of two images (that are bound to certain odds of getting points) between participants. Is there a way?
Also, what should I put in image and location for left11 and right11 images in Trial routine?

OK,

  • :+1: Bonus points for drawing the red arrows. :wink:
  • This line should deleted as you are using a keyboard component to check for keypresses:
keys = event.getKeys()
  • Because you are using a keyboard component rather than event.getKeys(), and presumably have it set to react to just a single key, you should indeed go back to using:
if response.keys == 'left'

as the keyboard component does just return a single key in that situation rather than a list (hence the error about about not being able to iterate.

  • Lastly, I’m not sure where 'red.png' comes from (as it isn’t in your conditions file), but you can’t test whether an image component (left11) is equal to a string of characters representing a filename. They are quite different beasts. I’m not sure what is really desired here, but probably you want to check whether the filename associated with that image component is 'red.png', in which case, I think you need to do something like this:
if left11.image == 'red.png'

But presumably you know which image files are being used for the stimuli if they aren’t varying (i.e. coming from a conditions file), so not really sure what this test is for.

I don’t really understand your questions in the last paragraph, as they are very broad. Perhaps just resolve your issues one a time before introducing other things.

Thanks, Michael! :slight_smile:

My questions in the last paragraph are the main ones that I try to overcome with the code. That is, put the images (‘red.png’ or ‘grey.png’) in the random location in Trial and then, depending on the location and the choice of a participant, show a feedback with certain probability.

Can I somehow randomise all 12 images (for 6 different lotteries) across all loops, in a way that, for example:

  • Participant 1 gets red image (or yellow or green) on the right, and grey (or purple or blue) image on the left. If he chooses ‘right’ in this trial, he gets 5 points in 100% times. If he chooses ‘left’, he gets 6 points with 90% chance or 0 points otherwise. Red and grey images should stay in these positions for all 100 trials, bound to the same feedback and never appear in the next loops.

  • Participant 2 gets grey image (or yellow or green) on the right and red (or purple or blue) image on the left. Again, for example, if he chooses ‘right’, he gets 5 points in 100% times. If he chooses ‘left’, he gets 6 points with 90% chance or 0 otherwise. Again, the pictures should stay in these position for all 100 trials, bound to the same feedback and not appear in the next loops.

So, it doesn’t matter which colour is bound to which feedback, but it’s important that it’s consistent for one participant for all 100 trials, doesn’t occur again in the consequent loops and changes for the next participant.

I’m not sure what code and where should I put it to implement this randomisation between participants.