psychopy.org | Reference | Downloads | Github

Survey tool, code for negative scoring

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

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x): 3
Standard Standalone? (y/n) If not then what?: y
**What are you trying to achieve?:use survey tool for PANAS questionnaire. The questions have a mixture of positve and negative scoring. Is there a way of coding this into survey tool (as one can do in ratingsscales component) so that the output data reflects this?

What did you try to make it work?:
My excel file has a column ‘score’ which is either ‘+’ or ‘-’ I then put a code component at the end of the routine :
if score ==’+’:
thisExp.addData(‘scoring’, rating.getRating())
elif score == ‘-’:
thisExp.addData(‘scoring’, 5-rating.getRating())

**What specifically went wrong when you tried that?:the error: … \PANAS_lastrun.py", line 314, in
if score ==’+’:
NameError: name ‘score’ is not defined
Include pasted full error message if possible. “That didn’t work” is not enough information.

Hi @esandhu , you will need to create a column called “score” in your excel conditions file, and feed that file into the loop.

Thank you for your, as always, swift response. I have already created a column called “score” in my excel conditions file. The headings for my condition file are: questionText options score layout type questionWidth responseWidth questionColor responseColor
Is the survey tool set up to allow this?

I see, and you are using the Form component. This works different from your usual loop and simply adding a score column to the form will not work, it will just be ignored. Having negative scoring options is something that can be added to the form, so thanks for highlighting this issue. In the mean time, you need to change the scores yourself at the end of the routine. Here is some code to help:

# End Routine
import pandas as pd
newData = pd.DataFrame.from_dict(form.getData())
newData = newData.sort_values(by=["itemIndex"])

answers = pd.read_csv("PANASFILE.csv")
newData['ratings'] = np.where(answers['score']=='-', 5 - newData['ratings'], newData['ratings'])
newData.to_csv("reverseScoresdData.csv")

Thank you, that is now working. I added:
newData[‘participant’] = expInfo[‘participant’]
so that the partcipant number is saved alongside the reverse scores.
The only issue is that the file name is constant and not unique. Is pandas able to draw data from psychopy so the file name can incorporate the participant number?
Best wishes

#Sure, you could use:

newData.to_csv("{}_reverseScoresdData.csv".format(expInfo['participant']))

This will create a file name, such as the following,if your participant is labelled “1”

"1_reverseScoresdData.csv"

That’s great. Thank you