| Reference | Downloads | Github

How to Reverse Score output

I am trying to digitize a psych questionnaire in which some of the answers are reverse scored (ex. using a 1,2,3,4,5,6 scale, an answer of 2 becomes 5, an answer of 1 becomes 6, etc. The participant still answers on a 1-6 scale, but their scores are reversed later.) To do this, I want to create a formula so that when the “scoring” column in my spreadsheet = “reverse”, the participant’s answer is subtracted from 7. Is this possible in psychopy?

I’m using a rating scale of 1-6. This is the code I have tried. I have it in a custom code box under the End Routine tab:

if Scoring=="normal":
    thisExp.addOtherData("revscore", revscore)
elif Scoring=="reverse":
    thisExp.addOtherData("revscore", revscore)

I get an error message saying that the - sign is not the correct format. I’ve also gotten several other error messages and the experiment has crashed on the reverse scored trials. I’m not sure what to do.
Thank you for your time and thought!

Mac OSX 10.10

Please copy and paste the literal error messages.

Here is the error message:
pyo version 0.8.6 (uses single precision)
18.4349 WARNING User requested fullscreen with size [1024 768], but screen is actually [2560, 1440]. Using actual size
2018-07-06 11:28:56.418 python[65739:255577] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/pj/v3qkvps53md9fllb9hk9_jg40000gr/T/org.psychopy.PsychoPy2.savedState
Traceback (most recent call last):
File “/Users/Rose/Documents/”, line 358, in
resp = (7 - ratingScale.getRating())
TypeError: unsupported operand type(s) for -: ‘int’ and ‘str’

And here is the code (there should be indents for the lines after if and else, but they aren’t formatting properly in this comment):
if Scoring == “reverse” :
resp = (7 - ratingScale.getRating())
thisExp.addData (“revscore”, resp)
resp = ratingScale.getRating()
thisExp.addData (“revscore”, resp)

OK, that makes it clear (and a good example of why it is useful to provide the literal error message rather than an interpretation of it: it is easy to go awry if you don’t know how to read the key message).

The issue is that the rating scale is returning the response as a character string (ie str) rather than an integer (int) and it isn’t possible to effectively subtract a letter from a number. I don’t know enough about rating scales to say if it could be configured to directly return a number, but you can convert the result yourself, e.g. convert the string '1' to the integer 1 like this:

resp = (7 - int(ratingScale.getRating()))

Also see this post about how to get formatted code in this forum:

Thank you so much! The code works now! My co-workers and I are truly thankful!

1 Like