How to Calculate Average Response Time

Michael,

Sorry to bombard you with replies! I have managed to solve all of these problems and everything is running smoothly now!!

For those reading, here’s a detailed description of what I did to make this work. I think it’s worth pointing out because I’ve seen this dscrepency in RTs before (this post: Cannot assign fixed (independent of RT) duration to rating scale component - #9 by daniel.riggs1) but it wasn’t resolved (from what I could tell). So to anyone who might of had similar problems, here’s what I did:

  1. In my ‘FCpract’ routine (picture above), I inserted a code component. In ‘Begin Routine’ tab, I entered this following code:
if FCpractTrialsLoop.thisN == 0:
    fc_rt_list = [] # an empty list to hold your values

FYI, ‘FCpractTrialsLoop’ is the name of the inner-most loop around the FCpract routine.

  1. In this same code component, in the ‘End Routine’ tab, I entered this code:
fc_rt_list.append(FCPract.getRT()) # Add RTs to list

thisExp.addData('fc_rt_list', fc_rt_list) # to add column in output so I can verify that 
# these RTs are the same as those automatically recorded by the ratingScale component 
# (which happens when you select 'store rating time' in the ratingScale advanced options)
  1. Lastly, in my routine called ‘InstFCcontrol’, I inserted a code component. In the ‘Begin Routine’ tab, I entered this code:
if FCcontBlock.thisN == 0: # just calculate once
    # turn the list into a numpy array that supports mathematical 
    # operations better:
    rt_array = np.array(fc_rt_list)
    fc_mean_rt = rt_array.mean()
    fc_sd_rt = rt_array.std()



thisExp.addData('fc_mean_rt', fc_mean_rt) #save to output data file
thisExp.addData('fc_sd_rt', fc_sd_rt) # save to output data file

I verified that all was going well by checking the output data file:

You can see the history of RTs being appended to the list, and can also see that the mean and sd calculated with excel (in bold) matches those calculated and stored by psychopy.

Also, the error about my loop not being defined (i.e. in ‘If your_loop_name.thisN ==0’…) was solved by changing which specific code component was holding this code. Apparently, when you enter code into a component that chronologically comes before the creation some object - in my case, the loop around a routine that hadn’t occurred yet in the code - python won’t have a history of that object yet thus won’t know what you’re talking about when you refer to it. I hadn’t appreciated this subtlety of the code component/builder view relationship, but I think it’s worth spelling out here because not appreciating it caused me a lot of headache!

Lastly, the mean and sd is only being recorded and stored once (as opposed to multiple times as it was doing before; see above post). This also had to do with which particular code component held the code (i.e. ‘loppname.thisN ==0’…). Before, I was putting the code for calculating mean and sd in the RandCode2 code component, and putting ExpBlock as my loop name. But this caused it to calculate mean and sd for every block within the ExpBlock loop (i.e. four total times by the end of the experiment). Putting this code into the code component in the FCcontrol routine and entering the name of the block (FCcontBlock) made it to where pyschopy would only calculate mean and sd only once (i.e. when that block occurs). Which is obviously what you want here!

I hope this is helpful to others who find themselves googling solutions to these roadblocks!

Matthew

2 Likes