RID | L1_1 | L1_2 | L1_3 | L1_4 | L1_5 | L1_6 | L1_7 | L1_8 | L1_9 | L1_10 | L1_11 | L1_12 | L1_13 | L1_14 | L1_15 | L1_16 | L1_17 | L1_18 | L1_19 | L1_20 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 3 | 3 | 4 | 3 | 2 | 3 | 1 | 2 | 3 | 4 | 3 | 1 | 3 | 1 | 2 | 3 | 2 | 3 | 2 | 4 |
2 | 3 | 2 | 3 | 3 | 4 | 3 | 2 | 2 | 4 | 3 | 2 | 2 | 1 | 2 | 4 | 3 | 3 | 2 | 4 | 3 |
3 | 3 | 3 | 2 | 3 | 3 | 4 | 2 | 3 | 3 | 3 | 2 | 2 | 2 | 2 | 3 | 3 | 4 | 3 | 3 | 3 |
4 | 4 | 2 | 2 | 3 | 4 | 4 | 1 | 3 | 3 | 4 | 2 | 1 | 2 | 2 | 4 | 4 | 3 | 3 | 4 | 3 |
5 | 2 | 3 | 3 | 3 | 4 | 3 | 2 | 2 | 3 | 2 | 4 | 4 | 4 | 3 | 2 | 2 | 3 | 4 | 3 | 2 |
2A Lab 3 Week 4
This is the pair coding activity related to Chapter 3.
We will once again be working with data from Binfet et al. (2021), which focuses on the randomised controlled trials data involving therapy dog interventions. Today, our goal is to calculate the average Loneliness
score for each participant measured at time point 1 (pre-intervention) using the raw data file dog_data_raw
. Currently, the data looks like this:
But we want the data to look like this:
RID | Loneliness_pre |
---|---|
1 | 2.25 |
2 | 1.90 |
3 | 2.25 |
4 | 1.75 |
5 | 2.85 |
This task is a bit more challenging compared to last week’s lab activity, as the Loneliness scale includes some reverse-coded items.
Task 1: Open the R project for the lab
Task 2: Open your .Rmd
file from last week or create a new .Rmd
file
You could continue the .Rmd
file you used last week, or create a new .Rmd
. If you need some guidance, have a look at Section 1.3.
Task 3: Load in the library and read in the data
The data should already be in your project folder. If you want a fresh copy, you can download the data again here: data_pair_coding.
We are using the package tidyverse
today, and the datafile we should read in is dog_data_raw.csv
.
Task 4: Calculating the mean for Loneliness_pre
-
Step 1: Select all relevant columns, such as the participant ID and all 20 items of the
Loneliness
questionnaire completed by participants before the intervention. Store this data in an object calleddata_loneliness
.
- Step 2: Pivot the data from wide format to long format so we can reverse-score and calculate the average score more easily (in step 3)
- Step 3: Reverse-scoring
Identify the items on the Loneliness
scale that are reverse-coded, and then reverse-score them accordingly.
-
Step 4: Calculate the average Loneliness score per participant. To match with the table above, we want to call this column
Loneliness_pre
If you’d like to practise your data wrangling skills further, you can try the “Challenge yourself” scenarios at the end of Chapter 3.