 #### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

# Can't get feedback with accuracy to work

edited October 2018

Hi,

I'm working on a MET task (math) where the participant chooses from 5 different difficulty levels. Each difficulty level has a different maximum grade: level 1 - a 6, level 2 - a 7, level 3 - an 8, level 4 - a 9, level 5 - a 10.

I followed someones advice here on how to calculate the accuracy, and I tried calculating the accuracy (grade) by multiplying the acc with 0.6 - 1.0 for the different difficulty levels.

The problem is that it just gives a 6 if you've chosen difficulty level 1, regardless of the amount of correct answers. This is the same for each level, it just gives the maximum grade.

I hope someone can help me understand what I'm doing wrong here.

I'm sorry, but I don't know how to post the code in the correct format. This is the code for the inline script (run phase) which comes after the text input form in the experiment:

``````import numpy
import string

CR_ans_canvas = canvas()
CR_answer =  var.number1 + var.number2 + var.number3
exp.set("CR_answer", CR_answer)

if var.CR_response == CR_answer:
var.set("CR_correct", 1)
var.set("CR_incorrect",0)
var.set("CR_late", 0)

else:
var.set("CR_correct", 0)
var.set("CR_incorrect", 1)
var.set("CR_late", 0)

if var.CR_response == "":
var.set("CR_late", 1)
var.set("CR_correct", 0)
var.set("CR_incorrect", 0)

##update feedback variable
self.set_response(response=var.CR_response,correct=var.CR_correct)

##show the answer_canvas
CR_ans_canvas.show()

##set the total amount of responses (trials) to 5
self.experiment.total_responses = 5

##if the response was correct, increase the amount of correct responses by one
if self.get("CR_correct") == 1:
self.experiment.total_correct += 1

##save the total correct under the variable OpenSesame saves it to
exp.set("total_correct",self.experiment.total_correct)

##calculate the total accuracy
self.experiment.acc = 10 * (self.experiment.total_correct / self.experiment.total_responses)

##calculate the accuracy for the chosen levels
if var.response_KeuzeKey_CR == 1:
self.experiment.acc = 0.6 * self.experiment.acc
elif var.response_KeuzeKey_CR == 2:
self.experiment.acc = 0.7 * self.experiment.acc
elif var.response_KeuzeKey_CR == 3:
self.experiment.acc = 0.8 * self.experiment.acc
elif var.response_KeuzeKey_CR == 4:
self.experiment.acc = 0.9 * self.experiment.acc
elif var.response_KeuzeKey_CR == 5:
self.experiment.acc = self.experiment.acc

##save the accuracy under the two variables OpenSesame saves it to
exp.set("acc",self.experiment.acc)
exp.set("accuracy",self.experiment.acc)`
``````

## Comments

• Hi,

This looks like an integer division problem. See here for example: https://www.geeksforgeeks.org/division-operator-in-python/

Does it work, if you replace `self.experiment.acc = 10 * (self.experiment.total_correct / self.experiment.total_responses)` with self.experiment.acc = 10 * (self.experiment.total_correct / float(self.experiment.total_responses))`?

Eduard

• Hi Eduard,
Thanks for your suggestion, but it still doesn't work.
It seems to me that something goes wrong with the (self.experiment.total_correct / float(self.experiment.total_responses)) part. Maybe it always returns 1 for some reason.
Femke

• Maybe it always returns 1 for some reason.

You can easily test that, by printing out the values of relevant variables into the debug window. E.g.

``````self.experiment.acc = 10 * (self.experiment.total_correct / self.experiment.total_responses)
print 'acc: ', self.experiment.acc
print 'total_correct: ', self.experiment.total_correct
print 'total_responses: ',self.experiment.total_responses
``````

That's generally the first thing you should do when you don't know why your code is not doing what it is supposed to do.

Eduard

• I tried, it it gives me an error:

`self.experiment.acc = 10 * (self.experiment.total_correct / self.experiment.total_responses)
print 'acc: ', self.experiment.acc
print 'total_correct: ', self.experiment.total_correct
print 'total_responses: ',self.experiment.total_responses

NameErrorTraceback (most recent call last)
in ()
----> 1 self.experiment.acc = 10 * (self.experiment.total_correct / self.experiment.total_responses)
2 print 'acc: ', self.experiment.acc
3 print 'total_correct: ', self.experiment.total_correct
4 print 'total_responses: ',self.experiment.total_responses
5

NameError: name 'self' is not defined`

• I also saw this in the debug window: UserWarning: var name is stored as attribute of item experiment
% (var, self.item.name)

• Hi Femke,

You have to run the experiment. Just copying the code to the window won't work. Can you try again? Or upload the experiment?

(and sorry for the delay).
Eduard

• Hi Eduard,
I tried running the experiment first, but that also didn't work. Can I email you the experiment? It needs excel files to run, so emailing would be easier I think.
Regards,
Femke

• Hi,

You can zip everything and send it to me via a PM.

Eduard

Sign In or Register to comment.