Hey guys,
I am trying to code multiple responses as correct in my builder experiment. I have a column on excel that states either 3 or 6 as a potential correct answer (corrAns). What I want to do is add a code that states that the corrAns in the excel column, but also the corrAns - 1 (so 2 or 5 would also be classified as correct depending on whether the corrAns in the column is 3 or 6) and also the corrAns - 2 (so 1 or 4 would also be classified as correct, again depending on whether the corrAns in the column is 3 or 6) should be classified as ‘1’ and any other answer is classified as 0. For example, if the corrAns is 6, and a participant responds with 4, that answer should still be categorized as correct on the excel data output (it should say ‘1’ in the column and not '0).
I know that in builder you cannot record multiple answers as correct, as originally I tried to put the responses of 1,2,3 or 4,5,6 as correct answers in the excel column, and it would still categorize every answer as 0/incorrect.
What should the code look like? I only want to categorize corrAns, corrAns-1,corrAns-2 as ‘1’ and incorrect as ‘0’, rather than the data output categorizing every response as ‘0’.
Thank you.
1 Like
Hi @Evi_Myftaraj
I think you can use a code like below. Change it according to your variable names.
## In the Begin Experiment Tab:
general_accuracy = 0
## In the End RoutineTab:
if my_keyboard.corr:
if my_keyboard.keys == 3 or my_keyboard.keys == 6:
general_acuracy= 1
if my_keyboard.keys == 2 or my_keyboard.keys == 5:
general_acuracy= 1
if my_keyboard.keys == 1 or my_keyboard.keys == 4:
general_acuracy= 1
elif not keyboardx.corr:
general_acuracy= 0
#And save the data
thisExp.addData (“general_acuracy”, general_acuracy)
Hey,
Thanks for replying. I tried this but it only coded the ‘3’ as correct. It still did not code any other keys.
I think I had a typo. Check this one:
## In the Begin Experiment Tab:
general_accuracy = 0
## In the End RoutineTab:
if my_keyboard.keys in [3,6] and my_column in [3,6,2,5,1,4]:
general_acuracy= 1
else:
general_acuracy= 0
#And save the data
thisExp.addData (“general_acuracy”, general_acuracy)
This code checks your key press and the csv column value and evaluate them to assign 0 or 1 to general accuracy and finally, save the general accuracy for each trial.
Hi Omidrezaa,
Sadly it still doesn’t work. Is there some technical issue here?
Ok, I changed the code to the code below and now it saves 3 and 6 as correct depending on the corr_ans column, but also 1,2, 4, and 5 as correct if the corr_ans is either 3 or 6.
## In the Begin Experiment Tab:
general_accuracy = 0
## In the End RoutineTab:
# Save as accurate if 3 was pressed and the corr_ans is 3
if int(my_keyboard.keys) == 3 and corr_ans == 3:
general_acuracy= 1
# Save as accurate if 6 was pressed and the corr_ans is 6
elif int(my_keyboard.keys) == 6 and corr_ans == 6:
general_acuracy= 1
# Save as accurate if 1 or 4 were pressed and the corr_ans are either 3 or 6
elif int(my_keyboard.keys) in [1,4] and corr_ans in [3,6]:
general_acuracy= 1
# Save as accurate if 2 or 5 were pressed and the corr_ans are either 3 or 6
elif int(my_keyboard.keys) in [2,5] and corr_ans in [3,6]:
general_acuracy= 1
else:
general_acuracy= 0
#And save the data
thisExp.addData ("general_acuracy", general_acuracy)
You can find a builder experiment as well as the condition file that I tested attached.
conditions.xlsx (8.5 KB) untitled.psyexp (8.2 KB)
Just make sure that the code saves accuracy the way that you want. I am not sure if this is what you wanted or not. Cheers.
Hey Omidrezaa,
Thank you so much. I had to change a few things around but it ended up working.
This is what it looks like if anyone else is having this issue.
if int(key_resp_10.keys) == 3 and corrAns == 3:
general_accuracy = 1
elif int(key_resp_10.keys) == 6 and corrAns == 6:
general_accuracy = 1
elif int(key_resp_10.keys) == 1 and corrAns == 3:
general_accuracy= 1
elif int(key_resp_10.keys) == 2 and corrAns == 3:
general_accuracy = 1
elif int(key_resp_10.keys) == 5 and corrAns == 6:
general_accuracy = 1
elif int(key_resp_10.keys) == 4 and corrAns == 6:
general_accuracy = 1
else:
general_accuracy = 0
#And save the data
thisExp.addData (“general_accuracy”, general_accuracy)
1 Like