psychopy.org | Reference | Downloads | Github

Display points earned in a decision task for both per trial points and cumulative points

I am running a study where people pick between two options with different reward structures. In order for the participants to make an optimal decision, they need to try different choices and see the points they get for each choice. I need to add a progress bar that has both the points they earn per decision as well as their total points earned for the experiment.

Where h is the sum of the last 10 decisions (h = sum(last_ten)):
For decision A the payoff = 30 + 5h
For decision B the payoff = 40 + 5
h

The participants are always picking between the same two choices so the only image that will change on the screen is the progress/points meter. I am creating the experiment in builder but want to use the custom code to create the meter.

Insert some Polygon components in Builder, and then update their length attribute in your code (i.e. you don’t need to create the stimuli in code, you just update them as required).

e.g. you might have a background rectangle in, say, white, with a constant length that represents the maximum total score. On top of that, place, say, a red rectangle with an initial length of zero, and grow it accordingly as the experiment progresses. You can either explicitly set the size of the rectangle in code, or more simply, you can just put the relevant variable name from your code in the Polygon component size field, set to update on every repeat or screen refresh as required.

Thank you so much Michael.

I am looking into the polygon option and it looks like I would want a staircase loop but that requires that there be a “correct answer.” Because the points are based off their last 10 choices and there are over 100 choices, I can’t make every possible combination of choices to calculate their points. Can I put a formula in instead?

I’m not sure I really understand your design but I don’t think you need a staircase here. The staircase is designed to alter stimuli adaptively in response to subject performance (as in a psychophysics threshold-finding task).

That’s not really required here, is it? There isn’t currently enough detail provided to give you much firmer advice, but my guess would be that you just need a regular loop to cycle through a conditions file to give information about each trial. The calculation of points would need to be handled by you explicitly in code, using formulae based on those you give in the first post above. With more details, we could probably give advice on how to do that.

Hi Michael,

I made two routines in the same loop. This first routine I just am showing the images with their two choices and the 2 white rectangles where their progress will be updated.

In the second routine I added two polygons with a size of 0,0

For the custom code to make the polygons grow I am not sure how to make it the right size.
I was thinking something like this:
#begin routine
key_response_2.keys = ’ ’
height = 0
trial_points = visual.Polygon(win=win, edges=4, size=(.05, height))

#each frame
if key_response_2.keys is ‘left’:
#not sure what to put here
elif key_response_2.keys is ‘right’:
#not sure what to put here
else:
msg="Oops! "

I think I will need to write in code a variable to keep track of what trial they are on because the growth rate of the rectangle is a constant multiplied by the sum of their last 10 trials.
h = sum of last 10 trials

I am attaching my experiment file because I am super new to PsychoPy and not sure if this is making sense.ROexp.psyexp (35.4 KB)
conds.xlsx (32.3 KB)
redbutton-pressed

redbuttonbluebutton-pressedbluebutton

Hi Michael,

I took your suggestion and used polygons to make the progress bar. I set white progress bars in the background and I set the height of green polygons to go up by the points they earned and flash over the white polygons.

The only issue is that it looks like it sets the position of the polygon by the middle of the polygon so my polygons showing the points are growing from both ends (rather than being anchored at the bottom and growing up).

is it possible to set the position so that the green bars start and the same points as the white bars and only grow up?

Thank you in advanced!

Hi,

If I’m not mistaken, you should be able to calculate the required y-position of the green bars in the following way:
yPos = -(lengthWhiteBar - lengthGreenBar)/2)

Basically, you need to shift down the green bar the appropriate amount of space.

Assumptions made:

  • Length and position have the same units
  • White bars are in the middle of the screen in y-direction

Hope this helps.

Jan

1 Like

Hi,

I was able to get the points bars to work thanks to jderrfuss and michael’s suggestions.
They are working great except for one issue:
On the first trial, it does not show the points bars. Its not until the second trial that they show up when you press a key.

Is there a way to fix it so they will show up on their first choice?

Here is my code

Begin Experiment

gainstotal = 0
gainstrial = 0
lastTen = []
firstH = 5
h = 0

totsize = [.15, 0]
trisize = [.15, 0]

ypostot = [0.1, 0]
ypostri = [-0.1, 0]

Begin routine


#for first trial they get 5 pts, after that it will be the number of correct answers in the last ten trials
if trials.thisN == 0: #for first trial, h = 5 #if the first trial is indexed at 0 use 0 otherwise use 1
    if key_resp2.corr == 1:
        lastTen.append(firstH)
    elif key_resp2.corr == 0:
        lastTen.append(firstH)

else: #keeping track of corrects
    if key_resp2.corr == 1:
        lastTen.append(1)
    elif key_resp2.corr == 0:
        lastTen.append(0)

if trials.thisN < 10: #calculate h (sum of last 10)
    h = np.sum(lastTen)
else:
    h = np.sum(lastTen[-10: ])  #this is not working


if key_resp2.keys == 'left':
    msg1 = "you chose"
    msg2 = " "
else:
    msg1 = " "
    msg2 = "you chose"

Each Routine


if key_resp2.corr == 1:
    gainstrial = 10 + ((70*h)*10)
else:
    gainstrial = 30 + ((70*h)*10)


gainstotal = gainstotal + gainstrial

gtotfrac = (gainstotal/600000)
gtrialfrac = (gainstrial/7500)

totsize[1] = gtotfrac
trisize[1] = gtrialfrac


yposc = -(1 - gtotfrac)/2
ypost = -(1 - gtrialfrac)/2


ypostot[1] = yposc
ypostri[1] = ypost

thisExp.addData('trialpts', gainstrial)
thisExp.addData('totalpts', gainstotal)

Hi Joy,

I can’t tell much from that but in general would point that any code components need to run before any components that need to refer to variables generated by that code. Within a routine, this is done by shifting the code component above any stimulus component that needs to refer to it. Otherwise, if the stimulus is above the code component, it will be using the variable values from the previous trial.

Hi MIchael,

I have the code component above the stimuli.
Could it be because I initialized the values at 0 in the beginning of experiment component of builder?

totsize = [.15, 0]
trisize = [.15, 0]

ypostot = [0.1, 0]
ypostri = [-0.1, 0]

Im attaching psychopy file as well.

OR_gender.psyexp (74.5 KB)

I moved the code from End Routine to begin Routine and it seems to be working now.