Hi the PsychoPy/Python experts here,
I try to find similar posts here but there doesn’t seem to be anything relevant. I will really appreciate anyone who can guide me to a relevant post if it already exists.
Here is a summary of a typical trial.
Each trial starts with presentation of an image stimulus (randomly taken from the linked conditions file, no repetition). Then the participant see a chart that represents the probability of getting a reward. There are 4 variations of this probability, say 20%, 40%, 60%, 80%. The task of the participant is to make a choice out of two, e.g. either ‘yes’ or ‘no’.
For the first 20 trials in the experiment, the occurrence of each probability is the same (that is, the participant will come across each probability for the same number of time, i.e. 5 times for each probability). At the end of the 20th trial, I need some codes or procedures that compute the frequency (proportion) of the participant choosing ‘yes’ / or ‘no’. This frequency measure will determine how the variations of the ‘probability’ chart are shown to the participant from trials 21-40.
For example, if the participant opted ‘yes’ for 16 times or more out of the first 20 trials, the 20%- and 40%-probability chart will then be shown more often than the 60%- and the 80%-probability (e.g. 20%: 7 times; 40%: 7 times; 60%: 3 times; 80%: 3 times) in trials 21-40. // On the other hand, if the participant opted ‘yes’ for only 4 times or less out of the first 20 trials, the 20%- and 40%-probability chart will be shown much less than the other two charts (e.g. 20% and 40%: 3 times each; 60% and 80%: 7 times each). // If the participant’s responses are somewhere in between (4-16 times out of 20 trials), then the occurrence of the probability charts will remain equal (e.g. 5 times for each probability). At the end of the 40th trial, there will be again a frequency measure of how often the participant chose ‘yes’ / ‘no’ in the last 20 trials (i.e. trials 21-40). This ‘new’ frequency measure will determine how often each ‘probability’ chart is shown in the next 20 trials (i.e. trials 41-60).
In other words, for every 20 trials, we calculate the average performance from the participant’s responses.
So far, I have created a ‘stimulus’ routine that incorporates an image component (which is set every repeat) that presents an image stimulus in each trial (by taking a path from the linked condition file). Then, for presenting the ‘probability’ chart, I created another image component. I believe I need to amend and play with parts of the scripts related to this component in the coder view?
These are parts of the codes I think I would need.
trial_no = 0, 1, 2, 3……
resp = ‘yes’, ‘yes’, ‘no’, ‘yes’, ………
sresp = []
for i in range:
sresp.append(resp[i]) #somehow I need to keep track of the participant’s response over trials
if ((trial_no==20 | trial_no==40 | trial_no==60 | trial_no==80):
cresp=sresp[len(sresp)-20:len(sresp)] #this extracts the responses of the last 20 trials when the trial number is 20,40,60, or 80
mcresp= np.mean(cresp)
if mcresp > 0.8:
probability=[20%, 20%, 20%, 20%, 20%, 20%, 20%, 40%, 40%, 40%, 40%, 40%, 40%, 40%, 60%, 60%, 60%, 80%, 80%, 80%]
elif mcresp < 0.2:
probability=[20%, 20%, 20%, 40%, 40%, 40%, 60%, 60%, 60%, 60%, 60%, 60%, 60%, 80%, 80%, 80%, 80%, 80%, 80%, 80%]
else:
probability=[20%, 20%, 20%, 20%, 20%, 40%, 40%, 40%, 40%, 40%, 60%, 60%, 60%, 60%, 60%, 80%, 80%, 80%, 80%, 80%]
Question: However, I am not quite sure how exactly I can implement the ‘probability’ array/variables to actual presentation. What I meant is what I should do to PsychoPy so that the programme will understand for trials 1 to 20 it needs to exhaust a particular list of 20 ‘probability’ variations, then for trials 21 to 40 it will exhaust potentially another list of 20 variations, and so on.
Sorry for my lengthy post. I hope someone can shed some lights on my question or kindly give me some ideas on how to address my problem in a more elegant way?
Many thanks.
Johnny