I am trying to repeat a set of trials when a response has been missed.
I used the same logic as the one in the repeat subset demo provided by wake carter. Specifically I did the following:
I have a routin called prepLoop (not contained within a loop of my exp routines) which includes:
n_incorrect = 0
n_correct = 0
repeatRows =
I included the following in my exp response routine which requires a mouse resp.
Specifically, in the EndRoutine of the code component I added this
if respMouse.clicked_name[0]: # Was a key pressed?
if imgResp1 == 0: # Error if not an animal
repeatRows.append(trials.thisIndex)
elif imgResp1 == 1: # Was an animal missed?
repeatRows.append(trials.thisIndex)
if respMouse.clicked_name[0]: # Was a key pressed?
if imgResp2 == 0: # Error if not an animal
repeatRows.append(trials.thisIndex)
elif imgResp2 == 1: # Was an animal missed?
repeatRows.append(trials.thisIndex)
Components requiring the mouse resp are
imgResp1
imgResp2
I would be grateful for suggestions.
Do I need to set my trial loops to random? My stim are randomised but I am using staircase tracking.
Do you have a question? What is not working as intended?
Please enclose the code in triple `. This will format it correctly. You seem to be appending to repeatRows regardless of the correctness of the answer.
I included this code below in the endroutine of the code component in my routine requiring a response.
if imgResp1 == 0: # Error if not an animal
repeatRows.append(trials.thisIndex)
```elif imgResp1 == 1: # Was an animal missed?
repeatRows.append(trials.thisIndex)
````if respMouse.clicked_name[0]: # Was a key pressed?
if imgResp2 == 0: # Error if not an animal
repeatRows.append(trials.thisIndex)
````elif imgResp2 == 1: # Was an animal missed?
repeatRows.append(trials.thisIndex)
I included this code in a routine among other code in a routine within the loop containing the rest of my routines for the experiment.
```repeatRows = []
My question is why isn't it working? So, I am trying to repeate trials that have been missed based on no mouse response. These are the components requiring a mouse response are imgResp2 and imgResp1
Thank you
# figure out if we have an incorrect or correct streak
# positive values indicate more incorrects than corrects
correct_diff = n_incorrect - n_correct
repeatRows = []
# this is how many ms to add on to our slower time
change_amount = 110
time_change = correct_diff * change_amount #100
# ensures the lists are integers (for JS)
vibrate_pattern1 = [vibrate1, 100]
vibrate_pattern2 = [vibrate2, 100]
for i in range(2):
vibrate_pattern1[i] = int(vibrate_pattern1[i])
if i == 0:
# more incorrects than corrects, just add the time change
if correct_diff >= 0:
vibrate_pattern1[i] += time_change
# more corrects than incorrects, time change is variable so we need a bit more
else:
# starts by decreasing time be 110 ms per correct answer
# for each correct answers...
for j in range(-correct_diff):
# decrease change amount to 50 once we reach or pass 600 ms
if vibrate_pattern1[i] <= 600:
change_amount = 50
# adjust by the change amount
vibrate_pattern1[i] -= change_amount
#vibrate_pattern1[i] += time_change
#if vibrate_pattern1[i] < 600:
# vibrate_pattern1[i] = 550
#if vibrate_pattern1[i] <= 600:
# vibrate_pattern1[i] = int(vibrate1) + (correct_diff * 50)
for i in range(2):
vibrate_pattern2[i] = int(vibrate_pattern2[i])
# randomly decide if we should shuffle
shuffle_patterns = [True, False]
shuffle(shuffle_patterns)
# if we decided to shuffle, swap patterns 1 and 2
temp = []
if shuffle_patterns[0]:
temp = vibrate_pattern1
vibrate_pattern1 = vibrate_pattern2
vibrate_pattern2 = temp
# calculate the trial lengths
trial_length1 = vibrate_pattern1[0]/1000
trial_length2 = vibrate_pattern2[0]/1000
# log everything
thisExp.addData("shuffled_patterns", shuffle_patterns[0])
thisExp.addData("adjusted_trial_length1", trial_length1)
thisExp.addData("adjusted_trial_length2", trial_length2)
thisExp.addData("adjusted_pattern1", vibrate_pattern1)
thisExp.addData("adjusted_pattern2", vibrate_pattern2)
thisExp.addData("pre_n_incorrect", n_incorrect)
thisExp.addData("pre_n_correct", n_correct)
```# manually calculate if the chosen response was correct
trial_acc = 0
if respMouse.clicked_name[0] == corrResp:
trial_acc = 1
#print(respMouse.clicked_name)
#print(corrResp)
# keep track of incorrect responses
if trial_acc == 0:
n_incorrect += 1
else:
n_correct += 1
thisExp.addData("n_incorrect", n_incorrect)
thisExp.addData("n_correct", n_correct)
if respMouse.clicked_name[0]: # Was a key pressed?
if imgResp1 == 0: # Error if not an animal
repeatRows.append(trials.thisIndex)
elif imgResp1 == 1: # Was an animal missed?
repeatRows.append(trials.thisIndex)
if respMouse.clicked_name[0]: # Was a key pressed?
if imgResp2 == 0: # Error if not an animal
repeatRows.append(trials.thisIndex)
elif imgResp2 == 1: # Was an animal missed?
repeatRows.append(trials.thisIndex)
So I am trying to repeat rows based on a non response. So if there is no response on a trial then I want the row of trials to repeating. Do I need to put the value 1 in `repeatRows = ````
Also please may you suggest what do with this code as well.repeatTrials = 1
And this errors = len(repeatRows) if errors == 0: continueRoutine = False # Don't show error report repeatTrials = 0 # Skip trials_2 loop repeatRows=[0] # trials_2 still needs a non-empty list of rows
errors = len(repeatRows)
if errors == 0:
continueRoutine = False # Don't show error report
repeatTrials = 0 # Skip trials_2 loop
repeatRows=[0] # trials_2 still needs a non-empty list of rows
following
if not respMouse.clicked_name[0]: # Was a key pressed?
repeatRows.append(trials.thisIndex)
You probably do not need to change this at this stage. The current problem to be solved is to get an index for a trial that needs to be repeated because the participant has made an error.
The code below will tell you the name of the object you clicked on and the trial you want to repeat. You can deal with repeating the incorrect trials if this works as intended. One problem at a time
Thank you very much. I actually don’t want to repeat the trial based on correct or incorrect response. I want to repeat trials for a missed response.
I included the code above in the EndRoutine of my code component which is in the response routine in my flow.
The only thing which has worked is that the missed mouse response are now being recorded, but the trials are not repeated on this basis. Additionally, my trial_accuray code is now no longer working, since trying to add code to repeat trials based on a missed mouse response.
repeatRows only ever contains the value 0. Why is trials.thisIndex only ever 0? Does your trials loop point at your spreadsheet?
When an animal is clicked repeatRows is reduced back to [0], which is what happens when errors == 0, which is what happens if repeatRows is cleared. Do you have repeatRows = in somewhere other than Begin Experiment?
is not enough information. You need to be more specific about what did not work. We do not have your programme in front of us, nor do we know what you want to achieve in the end. In the course of the posts we learn that you want to repeat unanswered trials. You also seem to want to count the accuracy of responses.
is an insufficient answer to
Do you manipulate trials.thisIndex ever?
Which of the above suggestions have you tried? What worked? What did not lead to the expected behaviour?
Perhaps you could compile a toy-version of you experiment which runs on a PC? Two or three trials with stimuli are usually sufficient.
I have a programmed a task that vibrates. Based on incorrect or correct responses parameters of one of the two trials changes.
I tried the above suggestion and they didn’t work. I will attach my experiment file here, if okay. Since, I tried to attach screen shots but it wasn’t very helpful as I couldn’t fit the whole flow in the view.
I fixed the code to try to repeat the missed trials and included it in the response routine. I am still having issues. Do you have any suggestions? Do you need the whole folder? It can be downloaded from the URL for the task as well.