Scoring the Questionnaire
Within our data frames, the questionnaire data is stored as a JSON object (JavaScript Object Notation). JSON is a structured way to represent data as key-value pairs, making it easy to read and exchange between systems. It is similar to the objects we saw in JavaScript.
Example questionnaire data as JSON object:
{"question1":1,"question2":3,"question3":0,"question4":1,"question5":2,"question6":3,"question7":3,"question8":0,"question9":0,"question10":4,"question11":1,"question12":0,"question13":"","question14":4,"question15":1}
Note, you may have personalized your question names and R is case sensitive, so make sure you are matching your questionnaire specification once you get to the reverse scoring (common versions are "question1", "Q1", "q1", etc.).
The full object is enclosed in curly braces { }
, the keys are strings enclosed in double quotes " "
, and the values paired with each key can be strings, numbers, booleans, arrays, other JSON objects, or null
.
In our data frames, the questionnaire JSON object can be found in the response
column in the row where trialType == Questionnaire
. For some of you that will be at the beginning of your data files, whereas others put it at the end after their task. Note, you may have personalized the trialType and R is case sensitive, so make sure you are matching your trialType specification (common versions are "Questionnaire", "questionnaire", or the specific name of your questionnaire).
We can extract the JSON object by using the fromJSON()
function from the jsonlite
package. The fromJSON()
function reads a JSON string and converts it into a corresponding R data structure, such as a list, data frame, or vector. We will then need to transform the data into a format where we can take the mean of all questionnaire items to get our final questionnaire score.
To start, please download this my-iat-test-data.csv raw participant data file and place it into your "~/your_path/psy1903/stats/data_cleaning/data"
directory.
Next, copy and paste the following code structure at the end of your existing dataCleaningExercise.R
script.
#### Questionnaire Scoring -----------------------------------------------------
## Read in data file to a data frame called iat_test
## Extract questionnaire data
## Use fromJSON to Convert from JSON to data frame
## Convert to numeric
questionnaire <- as.data.frame(lapply(questionnaire, as.numeric))
## Reverse score if necessary
## Calculate mean or sum score
Reverse Scoring
Reverse scoring is used in questionnaires to balance response patterns and ensure the reliability and validity of the measurement. When all items on a questionnaire are worded in the same direction, respondents might fall into a pattern of answering without truly considering each question (e.g., always selecting "Agree"). Reverse-scored items force respondents to think more carefully about their answers, breaking any response pattern. They also allow for a broader range of questions, and for two questions to assess the same behavior or cognition from opposite directions.
Let's use the example of the following Likert scale:
-
1 = Strongly Disagree
-
2 = Disagree
-
3 = Neutral
-
4 = Agree
-
5 = Strongly Agree
A reverse scored item was answered as 4 = Agree
, but directionally this matches with 2 = Disagree
on the overall construct. To reverse score this item, we can use the following equation: reverseScore = (maxLikertScore + minLikertScale) - itemScore
, which would become reverseScore = (5 + 1) - 4 = 2
, so 4 = Agree
reversed is equivalent to a score of 2
, which will bring this item into alignment with non-reverse scored items on the overall psychological construct.
Note, jsPsychSurveyLikert
defaults to the first Likert scale item having a value of 0. In this case, the reverseScore will simplify to the maxLikertScore - itemScore
:
-
reverseScore = (maxLikertScore + minLikertScale) - itemScore
-
reverseScore = (maxLikertScore + 0) - itemScore
-
reverseScore = maxLikertScore - itemScore
jsPsychSurveyLikert default Likert scale:
-
0 = Strongly Disagree
(reversed becomes4
) -
1 = Disagree
(reversed becomes3
) -
2 = Neutral
(reversed becomes2
) -
3 = Agree
(reversed becomes1
) -
4 = Strongly Agree
(reversed becomes0
)
Summary
Once you've filled in code using the above structure, you will have:
- Isolated the cell with the json object of questionnaire data.
- Converted it into a mangeable format (data frame) and made sure all items are numbers to calculate the mean/sum score.
- Used a
for
loop to reverse-score specific items. - And calculated the overall participant score on the questionnaire.