Block RT feedback for multiple responses

OS Win11
PsychoPy version PsychoPy 2022.2.5

Hopefully, no stupid mistakes this time. I’m trying to give RT feedback at the end of a block. I have a detection task in different conditions so have more than one response component I want to average RTs and present to participants at the end of the block. But, so far I’m struggling to average RTs from one component and present that. I have tried to follow: Builder - providing feedback — PsychoPy v2022.2.5

meanRT = trials.data[‘respOne.rt’].mean
fb_text = “You got %.3f average reaction time” %(meanRT)

but I get
meanRT = trials.data[‘long_detect.rt’].mean
KeyError: ‘respOne.rt’
################ Experiment ended with exit code 1

Not sure why. Any ideas would be helpful. Once solved, I then need a mean of multiple responses to present back to participants, but one step at a time.

Thanks in advance!

Hello,

is your keyboard-component called respOne or long_detect? Also, check the quotation marks. They should be '.

meanRT = trials.data['long_detect.rt'].mean
meanFB = 'You got %.3f average reaction time' %(meanRT)

not

meanRT = trials.data[‘long_detect.rt’].mean
fb_text = “You got %.3f average reaction time” %(meanRT)

when you surround code with triple ` your code gets formatted and it is easier to spot errors. When auto-translation (Auto → JS) is set in your code-component and the Python-code does not translate to JS, there is probably an error in your Python-code.

Best wishes Jens

1 Like

thanks. Sorry for the confusion. actually code is:

trials.data[‘long_detect.rt’].mean
fb_text = ‘You got %.3f average reaction time’ %(meanRT)

Double-checked the quotation marks, and I’m still getting the same error.

Any other things I should check?

Thanks!

Hello Jonathan,

in the code you post you still have intelligent instead of dumb quotation marks. But it might be that the forum replaces dumb quotation marks with “intelligent” ones. Please surround your code with triple `.

Best wishes Jens

Hi Jens,

Thanks. My code copy & pasted this time around triple ` . I think these are the right quotes:

meanRT = trials.data['long_detect.rt'].mean
fb_text = 'You got %.3f average reaction time' %(meanRT) 

I think that’s right?

Many thanks.
Jon

Apologies - had to edit a few times getting used to using the tripple `.

That looks good.

Does this work for you? Just press y, when “press” is displayed (five trials).

blockFeedback.psyexp (12.2 KB)

You did not answer one question.

So, does the code you wrote and the components match in names and spelling?

Do you have anything named respOne.rt?

Best wishes Jens

Thanks Jens - really helpful.

Yes - that file works fine. I changed my code to make it closer to what you have in the file by adding in the begin experiment tab:

fb_text=""
meanRT=""

and the code in the begin routine reads:

meanRT = trials.data['long_detect.rt'].mean()
fb_text = 'You got %.3f average reaction time' %(meanRT)
  • no sorry, that was me poorly editing the error output trying to make it more understandable. error code reads as such:
meanRT = trials.data['long_detect.rt'].mean()
KeyError: 'long_detect.rt'

Thanks again for your time and support!
Jon

not sure if it helps but this is the routine in the trials loop it’s aimed at:

And this is the loop:

Thanks!
Jon

Is this issue happening because the participant always responds during short_detect? Why do you have separate keyboard components? Won’t that mess up your mean RT anyway?

Thanks.

No - the participant will respond, depending on the condition at either short_detect or long_detect. I’ve used separate keyboard responses for two reasons - 1. So I can easily calculate response time to either short_target or long_target depending on the trial 2. So I can view data easily by correct response - if a response is recorded in short_detect on a long_target trial this would be incorrect… or maybe this is a hangover from moving recently from e-prime(?)
Thanks!

Hello Jonathan

AFAIK you need two physical keyboards to use two keyboard-components. Now two keyboard-components “fight” for one response.

Best wishes Jens

The two components are active at different times so that should be fine. Personally I’m more familiar with appending RTs to lists and calculating means from that than interrogating the trials.data.

Hello,

well, if two keyboards-components when when they don’t overlap in time, then the code posted above should work.

Best wishes Jens

Thanks both.

I’ll muck about - if one keyboard response fixes the problem, I’ll do as Wakefield suggests and deal with the data as it comes.

Odd that the file code doesn’t work as it is though.

I’ll let you know how it goes.
Thanks

What error are you getting now? Presumably it can’t still be KeyError: ‘respOne.rt’.

Hi,

tried modifying the routine with one response like so:

new code in BlockFeedback routine:

meanRT = trials.data['detect.rt'].mean()
fb_text = 'You got %.3f average reaction time' %(meanRT)

And i get the same error:

meanRT = trials.data['detect.rt'].mean()
KeyError: 'detect.rt'

Any more ideas?
Thanks

Hello

can you print detect.rt to the console?

print(detect.rt)

or

print(trials.data['detect.rt'])

Insert a code-component following the keyboard-component in the end-routine tab. The first print-command will print the current RT, the second the RT-list.

Best wishes Jens

1 Like

Hey, thanks again.

I now get these errors before the BlockFeedback routine:

meanRT = trials.data['detect.rt'].mean()
KeyError: 'detect.rt'

or

    print(trials.data['detect.rt'])
KeyError: 'detect.rt'

depending on whether I enter

print(detect.rt)

or

print(trials.data['detect.rt'])

Respectively.

Bit stuck.

That error means that trials.data doesn’t contain a field called detect.rt.

As I said before, I am unfamiliar with whether you can use trials.data (or indeed whether that is how you are supposed to use it). I would instead have something like rtList = in Begin Experiment and rtList.append(detect.rt) in End Routine. Then meanRT = rtList.mean() should work.

1 Like