library(tidyverse) theme_set(theme_minimal()) setwd("~/Desktop/Geneva workshop 2023/Lab 1/Data") data <- read_csv("clean_data.csv") colnames(data) # [1] "ParticipantID" "ListNumber" "TrialNumber" "ReactionTime" # [5] "PictureType" "TrialType" "Scale" "Condition" # [9] "Response" "Block" # Block 1 data %>% filter(Block == 1, Condition == "Baseline") %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ) ) %>% group_by(Scale) %>% summarise(Mean = mean(Response_f)) # Block 2 data %>% filter(Block == 2, TrialType == "Target") %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ) ) %>% group_by(Scale, Condition) %>% summarise(Mean = mean(Response_f)) # Putting the two together data %>% filter(Condition == "Baseline" | TrialType == "Target") %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ) ) %>% group_by(Scale, Condition) %>% summarise(Mean = mean(Response_f)) %>% print() %>% ggplot(aes(x = Condition, y = Mean, fill = Condition)) + geom_col() + geom_text(aes(y = Mean + 0.03, label = format(round(Mean, digits = 2), nsmall=2)), show.legend = FALSE) + facet_wrap(~Scale) + theme(legend.position = "none") # Filtering targets preceded by wrong answers to primes data <- data %>% mutate( PrimeAccuracy = case_when( TrialType == "Target" ~ 2, TrialType == "Prime1" & Scale == "AdHoc" & Condition == "Weak" & str_count(Response, "1") == 2 ~ 1, TrialType == "Prime1" & Scale == "AdHoc" & Condition == "Strong" & str_count(Response, "1") == 1 ~ 1, TrialType == "Prime1" & Scale == "Numeral" & Condition == "Weak" & str_count(Response, "6") == 1 ~ 1, TrialType == "Prime1" & Scale == "Numeral" & Condition == "Strong" & str_count(Response, "4") == 1 ~ 1, TrialType == "Prime1" & Scale == "Some" & Condition == "Weak" & str_count(Response, "9") == 1 ~ 1, TrialType == "Prime1" & Scale == "Some" & Condition == "Strong" & str_count(Response, "6") == 1 ~ 1, # TrialType == "Prime2" & Scale == "AdHoc" & Condition == "Weak" & str_count(Response, "1") == 2 ~ 1, TrialType == "Prime2" & Scale == "AdHoc" & Condition == "Strong" & str_count(Response, "1") == 1 ~ 1, TrialType == "Prime2" & Scale == "Numeral" & Condition == "Weak" & str_count(Response, "6") == 1 ~ 1, TrialType == "Prime2" & Scale == "Numeral" & Condition == "Strong" & str_count(Response, "4") == 1 ~ 1, TrialType == "Prime2" & Scale == "Some" & Condition == "Weak" & str_count(Response, "9") == 1 ~ 1, TrialType == "Prime2" & Scale == "Some" & Condition == "Strong" & str_count(Response, "6") == 1 ~ 1, .default = 0 ), Include = 0 ) for (r in 1:nrow(data)) { if (data[r, "TrialType"] == "Prime1" & data[r, "PrimeAccuracy"] == 1) { if (data[r+1, "TrialType"] == "Prime2" & data[r, "PrimeAccuracy"] == 1) { data[r+2, "Include"] <- 1 } } } data %>% filter((Condition == "Baseline") | (TrialType == "Target" & Include == 1)) %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ) ) %>% group_by(Scale, Condition) %>% summarise(Mean = mean(Response_f)) %>% print() %>% ggplot(aes(x = Condition, y = Mean, fill = Condition)) + geom_col() + geom_text(aes(y = Mean + 0.03, label = format(round(Mean, digits = 2), nsmall=2)), show.legend = FALSE) + facet_wrap(~Scale) + theme(legend.position = "none") library(lme4) data %>% filter(Scale == "AdHoc" & (Condition == "Baseline" | (TrialType == "Target" & Include == 1))) %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ), Condition = factor(Condition, levels = c("Strong", "Weak", "Baseline")) ) %>% glmer(formula = Response_f ~ Condition + (1 | ParticipantID), family = "binomial") %>% summary() data %>% filter(Scale == "AdHoc" & (Condition == "Baseline" | (TrialType == "Target" & Include == 1))) %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ), Condition = factor(Condition, levels = c("Weak", "Strong", "Baseline")) ) %>% glmer(formula = Response_f ~ Condition + (1 | ParticipantID), family = "binomial") %>% summary() data %>% filter(Scale == "Some" & (Condition == "Baseline" | (TrialType == "Target" & Include == 1))) %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ), Condition = factor(Condition, levels = c("Strong", "Weak", "Baseline")) ) %>% glmer(formula = Response_f ~ Condition + (1 | ParticipantID), family = "binomial", control=glmerControl(optimizer="bobyqa")) %>% summary() data %>% filter(Scale == "Some" & (Condition == "Baseline" | (TrialType == "Target" & Include == 1))) %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ), Condition = factor(Condition, levels = c("Weak", "Strong", "Baseline")) ) %>% glmer(formula = Response_f ~ Condition + (1 | ParticipantID), family = "binomial", control=glmerControl(optimizer="bobyqa")) %>% summary() data %>% filter(Scale == "Numeral" & (Condition == "Baseline" | (TrialType == "Target" & Include == 1))) %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ), Condition = factor(Condition, levels = c("Strong", "Weak", "Baseline")) ) %>% glmer(formula = Response_f ~ Condition + (1 | ParticipantID), family = "binomial", control=glmerControl(optimizer="bobyqa")) %>% summary() data %>% filter(Scale == "Numeral" & (Condition == "Baseline" | (TrialType == "Target" & Include == 1))) %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ), Condition = factor(Condition, levels = c("Weak", "Strong", "Baseline")) ) %>% glmer(formula = Response_f ~ Condition + (1 | ParticipantID), family = "binomial", control=glmerControl(optimizer="bobyqa")) %>% summary() # 9 comparisons in total: 3 comparisons x 3 scales # Alpha level = 0.05/9 = 0.00555... # By participant analysis library(ggridges) data %>% filter((Condition == "Baseline") | (TrialType == "Target" & Include == 1)) %>% mutate( Response_f = case_match(Response, "cover.png" ~ 1, .default = 0 ) ) %>% group_by(ParticipantID, Scale, Condition) %>% summarise(Mean = mean(Response_f)) %>% ggplot(aes(x = Mean, y = Condition, height = after_stat(density), fill = Condition, colour = Condition)) + geom_density_ridges(stat = "binline", scale = 0.95, show.legend = FALSE, alpha = 0.2, binwidth = 0.1) + facet_wrap(~Scale) + theme(legend.position = "none")