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 + 5h
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.
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.
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)
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?
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
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?
#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"
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.