Suppose you have created a survey in Pavlovia which contains a Radio Button Group. When configuring the choices for the radio buttons, you can provide both a label (this is what is presented to the user), as well as a name for the option. This name is what will be referenced in your data file to decide which option the participant has selected, and has to be unique for each of the options in the radio button group
In some cases, the selected option will be recoded into a numerical value. This might be the case when the radio buttons are examination questions, and you want to score performance on a question (optionally with applying a correction for guessing). You can do this by running the output data through an additional script that recodes the answers to the correct points. But it is also possible to use some advanced functionality from Pavlovia Surveys to have the score automatically calculated and added to the data output
As a proof of concept, we start with an empty Survey to which we add on the first page a simple Radio Button Group. Here we choose to give this component the name multiple_choice_q1. We create four choices. The label is not relevant, but make sure to name each of the choices as option_1, option_2, option_3 and option_4. By naming our component in an appropriate way, we will be able to refer to that component in other parts of our survey in a clear and transparent manner.
Underneath the radio button group, add an expression and name it multiple_choice_q1_scored. Configure it by adding the following code to the expression field:
iif({multiple_choice_q1} = 'option_1', 1/3,
iif({multiple_choice_q1} = 'option_2', -1/3,
iif({multiple_choice_q1} = 'option_3', 3, 4)))
This expression will produce the value 1/3 if the first option is selected, -1/3 if the second option is selected, 3 if the third option is selected and 4 if the fourth is selected.
An expression is a piece of code that will be executed when your survey is running. Expressions can contain operators and built-in functions supported by the underlying SurveyJS framework (see here for a full list). In this example we are using the iif (immediate if) function. In its simplest form it works like this:
iif(expression, if_true, if_false)
This will evaluate the expression first. If it is true, it will return what we provide at the location of if_true, or if_false otherwise. If we want to evaluate multiple options, we can simply replace the if_false part with another iif expression, producing a chain of evaluations.
Pavlovia Surveys allows you to inspect and perform computations on survey responses while the survey is running. When your responses need to be scored, you can leverage this functionality to do all the scoring while the survey is running. Just remember to set the visibility of your expression question to False, as it will display the actual score. Might be good for testing, but not something you want your participant to see!
Running into a deadline and need that project running urgently?
Have a great idea for your next experiment but not sure how to get started with implementing your ideas?
Let’s solve this together!