Recording non-numerical responses from sliders

Apologies if this is a silly question, but is there a way to use the slider/getRating functions in such a way that we record the user’s feedback as categorical/non-numerical data? For a questionnaire I’m trying to record responses for gender, “agree or disagree”, and so on. Recording the data as integers just means there’s more faffing/room to make mistakes when it comes to analysis.

My neighbours started making a lot of noise from 5am, so if I’m missing something obvious that’s my excuse.:eyes:

Hello Chris,

set the Granularity (silder Properties , Basic) to 1 instead of 0.

Best wishes Jens

Hi Jens,

Thanks for your response. However the issue isn’t so much saving integers only, I’d like to save non-numerical data. E.g, save responses to a gender question as “Male”, “Female”, etc instead of 1, 2, … Is there a way to do this?

I know there are simple ways to save the data as integers and then convert later on (dictionaries, if statements etc), but I’d rather keep things terse and reduce the areas for things to go wrong. I have a lot of these sorts of questions too.

Best,
Chris

Edit- attached the code I have. I should mention that the actual failure occurs when I run .getRating() to record the data to a file- perhaps there is an alternative for dealing with non-numerical data? However I can’t seem to find this online.

Hello Chris

well, I recode the values in my analysis script. But if you want to save the values “female” and “male” directly to the result-file, you need some code.

Add a code-component following the slider. Add the following code to the End routine tab:

rating = slider.getRating()

if rating == 1:
    recodedRating = "male"
elif rating == 2:
    recodedRating = "female"
else:
    recodedRating = "unkown"
    
thisExp.addData("rating", recodedRating)

Adapt the variable names to your liking. Notice this example uses only male and female as labels, but you see how it can be extended to your labels.

BTW. I used the Builder to “program” the code. So, in the Coder you probably need to add this following the Run routine-part.

# --- Ending Routine "trial" ---
for thisComponent in trialComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
thisExp.addData('slider.response', slider.getRating())
# Run 'End Routine' code from code
rating = slider.getRating()

if rating == 1:
    recodedRating = "male"
elif rating == 2:
    recodedRating = "female"
else:
    recodedRating = "unkown"
    
thisExp.addData("rating", recodedRating)
# the Routine "trial" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

Best wishes Jens

Hi Jens, thanks for your advice. I was thinking of possibly having something along those lines, but it seemed worth checking just in case there was a way to make it a little more terse.

I’m using the Coder, so the last part is definitely helpful.

Best,
Chris