| Reference | Downloads | Github

Is it possible to use variables for the category choices on rating scale?


is it possible to use variables for the category choices on rating scale?

I have a list of sounds in Excel sheet that are played randomly. The Excel sheet has four columns: first column - file names (variable aud, 2, 3, 4 - the words that I want to appear as choices on the rating scale, variables bat, bi, hiru

I want the participant to listen to the file, and depending on what file is played, the category choices are taken from the excel sheet

Can I do it in builder? If not in builder, can I do it in coder? Or is it not doable?


If there are always the same number of choices (just different values to be displayed), then yes it is quite possible with a little bit of code in a code component (in Builder).

Define the rating scale in the usual way, and be sure to include a list of choices that is the same length as desired. Those values will not be shown, but are used to make the tick marks in the right place, and so on.

Then in a code component, at the start of the routine:

list_of_labels = [ ]  # put an actual list of strings here, not empty [ ]
rating.choices = list_of_labels
for iii, label in enumerate(rating.labels):

Thank you very much. It worked.

Mikhail, in future you should tick ‘solution’ on a correct answer to your problem. Thanks

Hello All,

@jeremygray Thank you for putting code to allow us to put variables as category choices. I am wondering if everyone who is using this is able to store their ratings. Although I have “Store history”,“Store rating”, and “store rating time”. It seems that the responses are not saving to the excel sheet. More specifically I’ll run the experiment, and only a few of the responses will make it to the excel sheet.

I thought it was because I had “force end of routine” clicked, but after trying it without it clicked, it did not make a difference.

Any advice on how I can get all of the responses to make it onto the excel sheet?

Best Regards,

@Laur - For me the selected label is saved in the data file. I use .csv format for saving (.xlsx format is not recommended for saving data anymore, for several reasons). If the labels are sometimes saved for you and sometimes not saved, we’ll need more information to go on to work out why. First try using .csv files. Then try a simple experiment structure (I have a single rating scale within a loop of 2 trials). Then add complexity back until you see the problem reappear. This is a good way to diagnose a problem.

Hi Jeremy,

Thank you for the prompt response. My data files are currently in .csv format (I actually do not know how to get them in .xlsx form). This is likely because I have the newest version of PsychoPy (I’m sure the default format has been changed to .csv).
I currently have a single rating scale (with the custom code above) and the ratings are still reporting back as “None”. This is strange because I am using “hover” for my “marker type” (just to make sure I was correctly clicking on the rating scale (mostly a sanity check)). I even condensed it to one trial, and it is still happening.

Thank you again,

Okay, csv is good. Hover works fine for me (saves the clicked data item, and the history).

Can you paste the code you actually use?

This is the code I am using:

import random

list_of_labels = [‘cat1’,‘cat2’,‘cat3’,‘cat4’] # the four categories

current =[] #this is going to be used so I can rearrange the categories on a trial by trial basis

while len(current) < 4:
idx = random.randint(0,3)
if list_of_labels[idx] not in current:

rating.choices = current
for iii, label in enumerate(rating.labels):

The idea is for every trial, the order of the list will change, and then participants will have to search for the rating they want to give. More specifically in our case, they’re looking at an image, the image will fall into a specific category, and then the participant should click on the category.
For now, my lab is debating the categories, and that is why we are currently using “cat1”,“cat2”,“cat3”,“cat4”

I simplified the randomizing part, and the following works for me. When I put this code in ‘Begin experiment’:

import random
list_of_labels = ['cat1','cat2','cat3','cat4']  # the four categories

and then this code in Begin Routine:

random.shuffle(list_of_labels)  # this randomizes the order within the list
rating.choices = list_of_labels
for iii, label in enumerate(rating.labels):

then I get the correct values in the data file (i.e., the ones I clicked on)

Thank you so much! It now works! Thank you!

This is exactly what we needed!

I likely would not have gotten around to separating the code, but now I see how much of a difference this made.