Creating a dictionary for each condition

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Mac
PsychoPy version (e.g. 1.84.x): 1.84.1
What are you trying to achieve?:
I am trying to create a dictionary for my 4 different conditions. I have an excel file with a column for all the stimuli and then the next column with the conditions of each stimuli. There are a total of 4 conditions. I want to create a dictionary so that I can calculate mean RTs for each condition at the end of the trial. I’m just unsure of how or where to even start.
If anyone can tell me how to do the second part of it (calculate the mean RTs, once I have the conditions) that would be appreciated as well.

Do I put the code in the beginning of the experiment, before the trial, etc. I tried different things but the experiment refused to work. I’ve tried looking for solutions online, but they are scarce. Any help is appreciated. Thank you

The short answer to the question is “yes, the importing of conditions definitely needs to go before the running of the trial”

Have you tried looking at the demos menu? Have you thought about attending the workshops we run to get you started?

If you’re in the position of “unsure of how or where to even start” then I think we won’t be able to help to very well on the forum. There are just too many things you’d need to learn :-/

thanks,
Jon

Sorry, I meant where in this picture below would I put the code (before which routine) and where would the code go in field above (begin experiment, begin routine, etc.)

I looked at the workshops, but couldn’t find any being offered locally in Waterloo, ON.

Also, I looked at the trialhandler to create a dictionary and then use means for each condition, average them and present to participants, but haven’t been able to work it thus far.

Any help is appreciated. Thank you!

OK, I see what you mean now about the conditions and mean RTs.
Right, so imagine you have a column in your conditions file called ID (i.e. something that identifies uniquely which condition/row you’re in).

In your feedback Routine you need a code component that has this:
in the Begin Experiment (create a dictionary to store vals):

meanRTs = {}

in Begin Routine (check if this condition already exists and either append to that or create a new one, then set a message):

if ID not in allRTs: # if doesn't exist then create empty list
    allRTs[ID] = []
# now can append our most recent
allRTs[ID].append(resp.rt)
meanRT = np.average(allRTs[ID])

Then you can use meanRT however you like. Beware that the code here takes no notice of whether a valid RT has been produced though. It might well fall over if the participant doesn’t respond

Would I need to do this for each condition?
(I have a Conditions column with four conditions: UWUF UWRF RWRF and RWUF)
i.e.
mean RTs = {RWRF}

ID replaced by RWRF here…
if ID not in allRTs: # if doesn’t exist then create empty list
allRTs[ID] = [ ]

now can append our most recent

allRTs[ID].append(resp.rt)
meanRT = np.average(allRTs[ID])

Sorry for all the questions, but thank you for your quick response!

Replace the term “ID” with your own column name and you should be done. I don’t know what you mean by doing this for “each condition” the code is operating on every trial and knows which condition it’s in. Did you not try it yet?

I’m getting this error: (my column that has the four conditions is called Condition)

if Condition not in allRTs: # if doesn’t exist then create empty list
NameError: name ‘allRTs’ is not defined

Sorry the Begin Experiment should be

allRTs = {}

not

meanRTs = {}

my RTs in the data file are being presented similarly (the mean and the raw)

I was trying to make it so there would be mean of each condition calculated that I could present to participants later on.
I’m still unsure of how to fix this.

That data file will continue to provide the reaction time for each row in your conditions file. To calculate the mean across rows you would need to use an excel analysis.

But to present the mean reaction time to the participants surely you wouldn’t open the data file anyway; can’t you use the code snippet I provided for that?