install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
## (as 'lib' is unspecified)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
tracker1 <-read_csv("Participant Tracker Spreadsheet 1.csv")
## New names:
## Rows: 37 Columns: 17
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (11): Condition, Phase 1 Completed On, Phase 2 Due Date...4, Phase 2 Com... dbl
## (2): Participant Number, Participant Number 2 lgl (4): ...14, ...15, ...16,
## ...17
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `Phase 2 Due Date` -> `Phase 2 Due Date...4`
## • `` -> `...9`
## • `` -> `...10`
## • `Phase 2 Due Date` -> `Phase 2 Due Date...12`
## • `` -> `...14`
## • `` -> `...15`
## • `` -> `...16`
## • `` -> `...17`
tracker2 <-read_csv("Participant Tracker Spreadsheet 2.csv")
## New names:
## Rows: 40 Columns: 10
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (5): Condition, Phase 1 Completed On, Phase 2 Due Date, Phase 2 Complete... dbl
## (1): Participant Number lgl (4): ...7, ...8, ...9, ...10
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
##Removing incomplete participants from tracker1
tracker1 <- tracker1 %>%
filter(!`Participant Number` %in% c("9", "25", "32", "42", "46"))
##Removing incomplete data in tracker 2
tracker2 <- tracker2 %>%
filter(!`Participant Number` %in% c("25"))
tracker2 <- tracker2 %>%
filter(!(`Participant Number` == "61" &
`Phase 1 Completed On` == "20/05/26"))
##Combining trackers into 1 spreadsheet
tracker_combined <- bind_rows(
tracker1 %>% select(`Participant Number`, Condition, `Phase 1 Completed On`, `Phase 2 Completed (Y/N)`),
tracker2 %>% select(`Participant Number`, Condition, `Phase 1 Completed On`, `Phase 2 Completed (Y/N)`)
)
##checking no rows have been dropped or duplicated
nrow(tracker1) + nrow(tracker2) == nrow(tracker_combined)
## [1] TRUE
##Converting all ppt numbers to numeric
tracker_combined <- tracker_combined %>%
mutate(`Participant Number` = as.numeric(`Participant Number`))
##Uploading raw data
raw1<-read_csv("Raw data 1.csv")
## New names:
## Rows: 67 Columns: 60
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (20): ...1, ...3, ...6, ...9, ...12, ...15, ...18, ...19, ...20, ...21, ... dbl
## (24): ...2, ...4, ...5, ...7, ...8, ...11, ...13, ...26, ...28, _**How b... lgl
## (16): ...10, ...14, ...16, ...17, ...24, ...25, ...49, ...50, ...51, ......
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
## • `` -> `...11`
## • `` -> `...12`
## • `` -> `...13`
## • `` -> `...14`
## • `` -> `...15`
## • `` -> `...16`
## • `` -> `...17`
## • `` -> `...18`
## • `` -> `...19`
## • `` -> `...20`
## • `` -> `...21`
## • `` -> `...22`
## • `` -> `...23`
## • `` -> `...24`
## • `` -> `...25`
## • `` -> `...26`
## • `` -> `...27`
## • `` -> `...28`
## • `Please read and respond to the following statement(s) carefully` -> `Please
## read and respond to the following statement(s) carefully...40`
## • `Please read and respond to the following statement(s) carefully` -> `Please
## read and respond to the following statement(s) carefully...41`
## • `Please read and respond to the following statement(s) carefully` -> `Please
## read and respond to the following statement(s) carefully...42`
## • `Please read and respond to the following statement(s) carefully` -> `Please
## read and respond to the following statement(s) carefully...43`
## • `Please read and respond to the following statement(s) carefully` -> `Please
## read and respond to the following statement(s) carefully...44`
## • `Please enter the date:` -> `Please enter the date:...45`
## • `Please enter the date:` -> `Please enter the date:...46`
## • `Please enter the date:` -> `Please enter the date:...47`
## • `` -> `...49`
## • `` -> `...50`
## • `` -> `...51`
## • `` -> `...52`
## • `` -> `...53`
## • `` -> `...54`
## • `` -> `...55`
## • `` -> `...56`
## • `` -> `...57`
## • `` -> `...58`
## • `` -> `...59`
## • `` -> `...60`
raw2<-read_csv("Raw data 2.csv")
## New names:
## Rows: 40 Columns: 48
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (18): ...1, ...3, ...6, ...9, ...12, ...15, ...18, ...19, ...20, ...21, ... dbl
## (24): ...2, ...4, ...5, ...7, ...8, ...11, ...13, ...26, ...28, _**How b... lgl
## (6): ...10, ...14, ...16, ...17, ...24, ...25
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
## • `` -> `...11`
## • `` -> `...12`
## • `` -> `...13`
## • `` -> `...14`
## • `` -> `...15`
## • `` -> `...16`
## • `` -> `...17`
## • `` -> `...18`
## • `` -> `...19`
## • `` -> `...20`
## • `` -> `...21`
## • `` -> `...22`
## • `` -> `...23`
## • `` -> `...24`
## • `` -> `...25`
## • `` -> `...26`
## • `` -> `...27`
## • `` -> `...28`
## • `Please read and respond to the following statement(s) carefully` -> `Please
## read and respond to the following statement(s) carefully...40`
## • `Please read and respond to the following statement(s) carefully` -> `Please
## read and respond to the following statement(s) carefully...41`
## • `Please read and respond to the following statement(s) carefully` -> `Please
## read and respond to the following statement(s) carefully...42`
## • `Please read and respond to the following statement(s) carefully` -> `Please
## read and respond to the following statement(s) carefully...43`
## • `Please read and respond to the following statement(s) carefully` -> `Please
## read and respond to the following statement(s) carefully...44`
## • `Please enter the date:` -> `Please enter the date:...45`
## • `Please enter the date:` -> `Please enter the date:...46`
## • `Please enter the date:` -> `Please enter the date:...47`
##Listing aligning columns
intersect(names(raw1), names(raw2))
## [1] "...1"
## [2] "...2"
## [3] "...3"
## [4] "...4"
## [5] "...5"
## [6] "...6"
## [7] "...7"
## [8] "...8"
## [9] "...9"
## [10] "...10"
## [11] "...11"
## [12] "...12"
## [13] "...13"
## [14] "...14"
## [15] "...15"
## [16] "...16"
## [17] "...17"
## [18] "...18"
## [19] "...19"
## [20] "...20"
## [21] "...21"
## [22] "...22"
## [23] "...23"
## [24] "...24"
## [25] "...25"
## [26] "...26"
## [27] "...27"
## [28] "...28"
## [29] "Age"
## [30] "Please enter your chosen negative self-referential word"
## [31] "_**How believable is this word for you?**_ "
## [32] "**_How uncomfortable is the word for you?_** "
## [33] "Gender"
## [34] "_**How believable is the word for you?**_"
## [35] "**_How uncomfortable is the word for you?_**"
## [36] "**_Saying the word felt noticeably different by the end of the exercise compared to the start._**"
## [37] "**_The sound of the word felt different to me by the end of the exercise compared to the start._**"
## [38] "**_The meaning of the word seemed to shift or change by the end of the exercise compared to the start._**"
## [39] "_**I felt emotionally or mentally distanced from the word after the exercise compared to the start.**_"
## [40] "Please read and respond to the following statement(s) carefully...40"
## [41] "Please read and respond to the following statement(s) carefully...41"
## [42] "Please read and respond to the following statement(s) carefully...42"
## [43] "Please read and respond to the following statement(s) carefully...43"
## [44] "Please read and respond to the following statement(s) carefully...44"
## [45] "Please enter the date:...45"
## [46] "Please enter the date:...46"
## [47] "Please enter the date:...47"
## [48] "Please provide your Unique Participant Number (provided by the researcher):"
##Renaming questions columns so easier to work with for raw1
# Find all positions where "believable" appears (should be 2 matches)
believable_pos <- which(str_detect(names(raw1), fixed("believable")))
# Find all positions where "uncomfortable" appears (should be 2 matches)
uncomfortable_pos <- which(str_detect(names(raw1), fixed("uncomfortable")))
# Rename: 1st match = pre, 2nd match = post (columns stay in the same place)
names(raw1)[believable_pos[1]] <- "believability_pre"
names(raw1)[believable_pos[2]] <- "believability_post"
names(raw1)[uncomfortable_pos[1]] <- "discomfort_pre"
names(raw1)[uncomfortable_pos[2]] <- "discomfort_post"
##Renaming questions columns so easier to work with for raw2
believable_pos <- which(str_detect(names(raw2), fixed("believable")))
uncomfortable_pos <- which(str_detect(names(raw2), fixed("uncomfortable")))
names(raw2)[believable_pos[1]] <- "believability_pre"
names(raw2)[believable_pos[2]] <- "believability_post"
names(raw2)[uncomfortable_pos[1]] <- "discomfort_pre"
names(raw2)[uncomfortable_pos[2]] <- "discomfort_post"
intersect(names(raw1), names(raw2))
## [1] "...1"
## [2] "...2"
## [3] "...3"
## [4] "...4"
## [5] "...5"
## [6] "...6"
## [7] "...7"
## [8] "...8"
## [9] "...9"
## [10] "...10"
## [11] "...11"
## [12] "...12"
## [13] "...13"
## [14] "...14"
## [15] "...15"
## [16] "...16"
## [17] "...17"
## [18] "...18"
## [19] "...19"
## [20] "...20"
## [21] "...21"
## [22] "...22"
## [23] "...23"
## [24] "...24"
## [25] "...25"
## [26] "...26"
## [27] "...27"
## [28] "...28"
## [29] "Age"
## [30] "Please enter your chosen negative self-referential word"
## [31] "believability_pre"
## [32] "discomfort_pre"
## [33] "Gender"
## [34] "believability_post"
## [35] "discomfort_post"
## [36] "**_Saying the word felt noticeably different by the end of the exercise compared to the start._**"
## [37] "**_The sound of the word felt different to me by the end of the exercise compared to the start._**"
## [38] "**_The meaning of the word seemed to shift or change by the end of the exercise compared to the start._**"
## [39] "_**I felt emotionally or mentally distanced from the word after the exercise compared to the start.**_"
## [40] "Please read and respond to the following statement(s) carefully...40"
## [41] "Please read and respond to the following statement(s) carefully...41"
## [42] "Please read and respond to the following statement(s) carefully...42"
## [43] "Please read and respond to the following statement(s) carefully...43"
## [44] "Please read and respond to the following statement(s) carefully...44"
## [45] "Please enter the date:...45"
## [46] "Please enter the date:...46"
## [47] "Please enter the date:...47"
## [48] "Please provide your Unique Participant Number (provided by the researcher):"
##Creating vector for columns needed
cols_needed <- c(
"Age",
"Please enter your chosen negative self-referential word",
"believability_pre",
"discomfort_pre",
"Gender",
"believability_post",
"discomfort_post",
"**_Saying the word felt noticeably different by the end of the exercise compared to the start._**",
"**_The sound of the word felt different to me by the end of the exercise compared to the start._**",
"**_The meaning of the word seemed to shift or change by the end of the exercise compared to the start._**",
"_**I felt emotionally or mentally distanced from the word after the exercise compared to the start.**_",
"Please read and respond to the following statement(s) carefully...40",
"Please read and respond to the following statement(s) carefully...41",
"Please read and respond to the following statement(s) carefully...42",
"Please read and respond to the following statement(s) carefully...43",
"Please read and respond to the following statement(s) carefully...44",
"Please enter the date:...45",
"Please enter the date:...46",
"Please enter the date:...47",
"Please provide your Unique Participant Number (provided by the researcher):"
)
##Rechecking all columns exist
cols_needed[!cols_needed %in% names(raw1)] # should print character(0) if all found
## character(0)
cols_needed[!cols_needed %in% names(raw2)] # should print character(0) if all found
## character(0)
##Combining needed data from raw data
raw_combined <- bind_rows(
raw1 %>% select(all_of(cols_needed)),
raw2 %>% select(all_of(cols_needed))
)
## New names:
## New names:
## • `Please read and respond to the following statement(s) carefully...40` ->
## `Please read and respond to the following statement(s) carefully...12`
## • `Please read and respond to the following statement(s) carefully...41` ->
## `Please read and respond to the following statement(s) carefully...13`
## • `Please read and respond to the following statement(s) carefully...42` ->
## `Please read and respond to the following statement(s) carefully...14`
## • `Please read and respond to the following statement(s) carefully...43` ->
## `Please read and respond to the following statement(s) carefully...15`
## • `Please read and respond to the following statement(s) carefully...44` ->
## `Please read and respond to the following statement(s) carefully...16`
## • `Please enter the date:...45` -> `Please enter the date:...17`
## • `Please enter the date:...46` -> `Please enter the date:...18`
## • `Please enter the date:...47` -> `Please enter the date:...19`
##Remame ppt number in raw to be consistent with tracker
pos <- which(str_detect(names(raw_combined), "Participant Number"))
names(raw_combined)[pos] <- "Participant Number Gorilla"
##track all values in condition column
unique(tracker_combined$Condition)
## [1] "1s" "0.5s" "Control" "Reading" "0.5 s" "control"
##Conistent naming of condition
tracker_combined <- tracker_combined %>%
mutate(Condition = case_when(
str_detect(Condition, regex("0\\.5", ignore_case = TRUE)) ~ "0.5s",
str_detect(Condition, regex("control|reading", ignore_case = TRUE)) ~ "Control",
TRUE ~ Condition
))
##Renaming participant 17 as 29 due to labelling error during data collection
raw_combined <- raw_combined %>%
mutate(
`Participant Number Gorilla` = if_else(
`Participant Number Gorilla` == 17 &
`Please enter your chosen negative self-referential word` == "Stupid",
29,
`Participant Number Gorilla`
)
)
##Renaming participant 35 as 37 due to labelling error during data collection
raw_combined <- raw_combined %>%
mutate(
`Participant Number Gorilla` = if_else(
`Participant Number Gorilla` == 35 &
`Please enter your chosen negative self-referential word` == "spineless",
37,
`Participant Number Gorilla`
)
)
##
##Renaming participant 67 as 68 due to labelling error during data collection
raw_combined <- raw_combined %>%
mutate(
`Participant Number Gorilla` = if_else(
`Participant Number Gorilla` == 67 &
`Please enter your chosen negative self-referential word` == "lazy",
68,
`Participant Number Gorilla`
)
)
##Pulling data from tracker spreadsheet and matching it to participant id in the raw data
raw_combined <- raw_combined %>%
left_join(
tracker_combined %>% select(`Participant Number`, Condition),
by = c("Participant Number Gorilla" = "Participant Number")
)
##Count number in each condition
raw_combined %>%
count(Condition)
## # A tibble: 4 × 2
## Condition n
## <chr> <int>
## 1 0.5s 23
## 2 1s 25
## 3 Control 23
## 4 <NA> 36
##Uploading researchrandomiser spreadsheet for verification
Randomiser<-read_csv("ResearchRandomizer.csv")
## Rows: 24 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (3): 0.5s, 1s, Control
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
##Fixing error: 45 was duplicated in 0.5s column and 1s column; 45 correctly completed 1s.
##the participant intended for 0.5s (42) actually completed 1s, so 42 needs to be moved to the 1s column instead
# Remove the erroneous 45 from 0.5s column
Randomiser$`0.5s`[Randomiser$`0.5s` == 45] <- NA
##check columns
colSums(!is.na(Randomiser[, c("0.5s", "1s", "Control")]))
## 0.5s 1s Control
## 23 24 24
# Add a new blank row so there's a slot to place 42 into
Randomiser <- Randomiser %>% add_row()
# Add 42 into the first empty slot in the 1s column
first_empty_1s <- which(is.na(Randomiser$`1s`))[1]
Randomiser$`1s`[first_empty_1s] <- 42
##Due to the error with participant 42, need to recruit additional participants to allow even allocation across groups
##Code to work out recruitment needed to reach 25 per condition
current_counts <- colSums(!is.na(Randomiser[, c("0.5s", "1s", "Control")]))
target_per_condition <- 25
needed <- target_per_condition - current_counts
print(needed)
## 0.5s 1s Control
## 2 0 1
##Add the new recruit IDs (73-75) into the correct gaps, randomly assigned ----
max_existing_id <- 72 # known valid range is 1-72
new_ids <- (max_existing_id + 1):75 # 73, 74, 75
set.seed(123) # optional: makes the "random" shuffle reproducible if you rerun the code
new_ids <- sample(new_ids) # randomly shuffles 73, 74, 75 before assignment
id_pool <- new_ids
for (cond in c("0.5s", "1s", "Control")) {
n_needed <- needed[[cond]]
if (n_needed > 0) {
ids_to_add <- id_pool[1:n_needed]
id_pool <- id_pool[-(1:n_needed)]
empty_slots <- which(is.na(Randomiser[[cond]]))[1:n_needed]
Randomiser[[cond]][empty_slots] <- ids_to_add
}
}
##Check assignment
colSums(!is.na(Randomiser[, c("0.5s", "1s", "Control")]))
## 0.5s 1s Control
## 25 25 25
##Reshape randomiser from wide to long format
randomiser_long <- Randomiser %>%
pivot_longer(
cols = everything(),
names_to = "Condition_randomiser",
values_to = "Participant Number"
) %>%
filter(!is.na(`Participant Number`))
##ensure numeric
randomiser_long <- randomiser_long %>%
mutate(`Participant Number` = as.numeric(`Participant Number`))
##Join onto raw data for comparison
comparison <- raw_combined %>%
left_join(randomiser_long, by = c("Participant Number Gorilla" = "Participant Number")) %>%
select(`Participant Number Gorilla`, Condition, Condition_randomiser) %>%
distinct()