psychopy.org | Reference | Downloads | Github

Feedback - failing to respond in 2 consecutive trials

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

OS :macOS Catalina
PsychoPy version: 3.2.3
Standard Standalone? (y/n) Yes

**What are you trying to achieve?:
I am trying to give feedback if a participant have failed to respond in 2 consecutive trials. e.g (Are you awake?)

What did you try to make it work?:
For now, I have used Conditional Branching, such that if a participant presses ‘space’, they go on to the next routine, whereas if the don’t press anything, they go to the Are you awake-routine.

This was achieved with store correct in the key component, etc, as described here.

What specifically went wrong when you tried that?:
The participants gets feedback after every trial when failing to respond. I want the participant to only receive feedback when they fail to respond in 2 consecutive trials.

You’ll have to write a code component that tracks recent responses with a variable and uses those to provide the feedback. That’s dicussed in the book but come back if you have a specific error that needs solving

I have a partial solution for now, based on the examples in Building Experiments in PsychoPy:

In a code component, I have added in Begin Experiment:

corr = []
nWakeUp = 0
nFeedbackResponse = 0

In Begin Routine, I have added:

corr.append(keyRespTrial.corr)
nCorr = sum(corr[- 2 :])
nResps = len(corr[- 2 :])

if nCorr == 0 and nResps == 2:
    nWakeUp = 1
    nFeedbackResponse = 0
else:
    nWakeUp = 0
    nFeedbackResponse = 1

However, what happens now is that:

After 2 trials with no answer, the Wake-Up routine starts, and the participant is informed that they have not answered in 2 trials, and to press a button to continue. So far so good.

After this, even if the participant does not respond in the first trial, the Wake-up Routine starts again, and the participant is informed to press continue.

After the “first” Wake-Up Routine, I want things to be reset, so that it again needs to be 2 consecutive trials with no responses before going to the wake-up routine.

I suspect I need to add some code into End Routine which clears nCorr and/or nResps?

By spelling it out, I think you’ve worke it out on your own!! :slight_smile:

Yes, you might want something to reset after the wake-up has been called. That depends on what you want. If someone gets it wrong twice and still doesn’t wake up do you keep telling them?

A reseting alternative could look like this:

if not keyRespTrial.corr:
    consecutiveErrs += 1  # increment
else:
    consecutiveErrs = 0  # reset

if consecutiveErrs >= 2:
    nWakeUp = 1
    consectiveErrs = 0  # reset

and obviously you’d need consecutiveErrs=0 at begin Experiment

That’s the best I can suggest, but really you just need to think carefully about the logic and what those values are on each iteration.

Jon

Thank you for your response.

What I want is that, if someone gets it wrong twice, they are told to press a button to acknowledge it in a Wake-Up routine.
When they have pressed the button, they need to get it wrong twice again in ordet to get the Wake-Up routine. So they are only told to wake up if they haven’t answered two times in a row.

I tried your code but the same thing still happens; after getting it wrong twice and acknowledging it, they go to the wake-up routine even after the first wrong as well.

However, I’m not entirely sure where to put the code, in which routine should the code component be added?

This was my solution:
In Begin Experiment:

nWakeUp = 0
nFeedbackResponse = 0
consecutiveErrs = 0

In Begin Routine:

# add +1 to Errors if incorrect answer
if not keyRespTrial.corr:
    consecutiveErrs += 1  # increment
else:
    consecutiveErrs = 0  # reset

# go to nWakeUp if 2 consecutive incorrect answers
 if consecutiveErrs >= 2:
    nWakeUp = 1
    nFeedbackResponse = 1
    consecutiveErrs = 0  # reset
else:
    nWakeUp = 0
    nFeedbackResponse = 1