yes so 6 different colors and in both initial display and test trial only one of them will be different in the test
In that case what don’t you like about this proposal?
Hello, based on your first demo I thought maybe I should adapt it as this for the initial display where I show the 6 different colored squares:
if corrAns == ‘left’:
polygon_1.setFillColor(colours[Colour][1])
polygon_2.setFillColor(colours[Colour][1])
polygon_3.setFillColor(colours[Colour][1])
polygon_4.setFillColor(colours[Colour][1])
polygon_5.setFillColor(colours[Colour][1])
polygon_6.setFillColor(colours[Colour][1])
else:
polygon_1.setFillColor(colours[Colour][1])
polygon_2.setFillColor(colours[Colour][1])
polygon_3.setFillColor(colours[Colour][1])
polygon_4.setFillColor(colours[Colour][1])
polygon_5.setFillColor(colours[Colour][1])
polygon_6.setFillColor(colours[Colour][1])
This way could we make sure that in the initial display all squares are different, coming from colors index.
Then for the test trial :
So this is bringing a new random index based on the colour index we defined, right? :
col2 = (Colour + 1 + randint(6))%7
if corrAns == ‘left’:
polygon_1.setFillColor(colours[Colour][1])
polygon_2.setFillColor(colours[Colour][1])
polygon_3.setFillColor(colours[Colour][1])
polygon_4.setFillColor(colours[Colour][1])
polygon_5.setFillColor(colours[Colour][1])
polygon_6.setFillColor(colours[col2][1])
else:
polygon_1.setFillColor(colours[Colour][1])
polygon_2.setFillColor(colours[Colour][1])
polygon_3.setFillColor(colours[Colour][1])
polygon_4.setFillColor(colours[Colour][1])
polygon_5.setFillColor(colours[Colour][1])
polygon_6.setFillColor(colours[col2][1])
This way could we make sure that only one square is changing… and all the other squares are exactly the same as the initial trial?
for it to be repeated for 50 trials what would I need to do?
Thank you so much for your time and guidance!![]()
The code you have written should give you 6 squares with identical colours and then change square 6 to a different colour. If that isn’t what you want, please try again.
hi! i managed to create the experiment! thank you so much! currently i had an issue with syncing ( i keep seeing the rainbow sign (downloading) so I couldn’t see if this worked: I needed to calculate the % accuracy of participants for all trials. for that i added the highlighted parts as well as the overall accuracy at the end of the end of routine… do you think this would work and calculate the % accuracy of each participant?:
Hello @kimwong
Your programme executes total_trials += 1 in a Each frame tab. This is probably too many trials. On each frame the number of trials is increased by 1. Move this to a Begin Routine or End Routine tab.
Best wishes Jens
thank you so much! to confirm, that is the only issue right? and it should run without issues online?
may i also ask : i want to calculate the angular difference between the previous and current (delta)stimuli in my experiment, this is how it can be written in R now I was trying to add this to my experiment.. would something like this work for an online experiment in psychopy:
Assuming df is your DataFrame
Create a ‘delta’ column as the difference between the current and previous ‘length’
df[‘delta’] = df[‘length’] - df[‘length’].shift(1)
Summary statistics of the ‘delta’ column
summary = df[‘delta’].describe()
print(summary)
Hello @kimwong
Well, simply give it a try. You can run your experiment in a locally in a browser. There is no need to sync the experiment with Pavlovia for testing.
This is not base R. What are your variables named in PsychoPy and what do want to achieve?
Best wishes Jens
hi thanks! my goal is to calculate the delta(angular differences) between previous and current stimuli. length is the name of the column in the spreadsheet.
this was for the psychopy actually would this work: Assuming df is your DataFrame
Create a ‘delta’ column as the difference between the current and previous ‘length’
df[‘delta’] = df[‘length’] - df[‘length’].shift(1)
Summary statistics of the ‘delta’ column
summary = df[‘delta’].describe()
print(summary)
originally in r we did something like this for the same goal: #mutate delta - previous length minus current length
df ← df %>%
mutate(delta = length - lag(length))
summary(df$delta)
also although it saves the clicked stim and target square it just saves the cl correct as 0 even we clicked to the correct one. do you have any idea why this is happening and how we can solve this? (is it because we didnt create a cl_correct variable before -if so would simply target_square = cl_correct work before thisExp.addData(cl_correct)?:
You have a test for equality if target_name == clicked_stim: which appears to never be true.
In the line above add:
print('Does',target_name,'equal',clicked_stim,'?',target_name == clicked_stim)
and check the developer tools to see what happens.
Hello @kimwong
AFAIK there is no summary function in Python. To calculate the difference of length of the current and the length of the previous trial, you could try the following:
Specifiy in a Begin Experiment tab
l1 = 0
delta = 0
In the Begin routine tab specify:
if trials.thisN == 0:
l1 = length
delta = 0
elif trials.thisN > 0:
delta = length - l1
l1 = length
thisExp.addData("delta", delta)
That would compute the difference between current length and the previous length and store the difference in the results-file. Note that you have to change the name of trials.thisN to the YourLoopName.thisN
Best wishes Jens
Thank you so much for your help! I’m new to Python and have been looking for a course specifically designed for cognitive psychology students but haven’t had any luck finding one. Do you happen to know if such a course exists? Alternatively, do you have any advice on how I can best develop my coding skills for this field?
Hello @kimwong
I usually recommend reading Peirce, J. W., Hirst, R. J. & MacAskill, M. R. (2022). Building Experiments in PsychoPy. 2nd Edn London: Sage to understand how PsychoPy and PsychJS work. There are also some YouTube videos https://www.youtube.com/channel/UCQo2aB6cXJasHyXJp0afaWg and there are workshops, some of which are online courses, that you can book, https://workshops.psychopy.org/. There are no online courses at the moment.
A Python course will certainly help, but most of the time you will not need to code manually. Manual coding can be problematic for online experiments that rely on the auto-translation (PsychoPy → PsychoJS) feature of the builder. So you need to know the limitations of PsychoPy/PsychoJS.
Best wishes Jens



