PK ǰ|X Study 1 analysis script.htmlUT ff
library(tidyverse)
library(broom)
library(readbulk)
library(lme4)
library(summarytools)
Reading raw data as logged by psychopy and combinging individual participant files using pck ‘readbulk’. We only analysed responses to trials with commutativity statments (“is equal to”).
raw <- read_bulk(directory = "~/data/", extension = ".csv")
data <-
raw %>%
group_by(participant) %>%
fill(left) %>%
filter(Condition == "is equal to") %>%
mutate(resp_true = case_when(left == TRUE & key_resp_2.keys == "left" ~ 1,
left == FALSE & key_resp_2.keys == "right" ~ 1,
left == TRUE & key_resp_2.keys == "right" ~ 0,
left == FALSE & key_resp_2.keys == "left" ~ 0)) %>%
mutate(Symmetric = if_else(Symmetric == "Y", 1, 0)) %>%
mutate(Symbol = gsub("[^0-9\\.]", "", Symbol) ) %>%
ungroup()
T-test of summary statistics (pre-registered)
summary <- data %>%
group_by(participant, Symmetric, Symbol) %>%
summarize(resp_true = sum(resp_true)/7) #percentage of endorsing commutativity out of the 7 trials per symbol
t_test <- data %>%
group_by(participant, Symmetric) %>%
summarize(resp_true = sum(resp_true)/70) %>%
spread(Symmetric, resp_true) %>%
ungroup()
t_test %>%
summarise_all(list(mean, sd, min, max))
## # A tibble: 1 x 12
## participant_fn1 `0_fn1` `1_fn1` participant_fn2 `0_fn2` `1_fn2`
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 15.5 0.267 0.668 8.80 0.257 0.261
## # … with 6 more variables: participant_fn3 <int>, `0_fn3` <dbl>, `1_fn3` <dbl>,
## # participant_fn4 <int>, `0_fn4` <dbl>, `1_fn4` <dbl>
tidy(t.test(t_test$`0`, t_test$`1`, paired = TRUE, alternative = 'less'))# t(29) = -5.577, p = .000000255
## # A tibble: 1 x 8
## estimate statistic p.value parameter conf.low conf.high method alternative
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr>
## 1 -0.400 -5.58 2.55e-6 29 -Inf -0.278 Paired … less
Further visual data exploration esp. effect within each participant, effect within each symbol
#Plot of symmetry effect by Symbol
ggplot(summary, aes(as.factor(Symmetric), resp_true, color = Symmetric, group = participant)) +
geom_line() +
geom_point() +
facet_wrap(~Symbol)
#Plot of symmetry effect by participant
ggplot(summary, aes(as.factor(Symmetric), resp_true, fill = as.factor(Symmetric))) +
geom_col() +
facet_wrap(~participant)
Modelling the effect as a generalized linear model with mixed effects and binomial link function. Modelling symbols and participants as random factors and comparing symmetry (vertical vs. horizontal) in the fixed factor
full_data_mixed_log <- glmer(resp_true ~ Symmetric + (1|Symbol) + (1|participant), data = data, family = binomial, nAGQ=1)
#using nAGQ=1 --> Laplace approximation algorithm used for estimation. The more accurate Gauss Hermite quadrature is not available for models estimating more than 1 random intercept.
tidy(full_data_mixed_log, conf.int=TRUE, exponentiate=TRUE) %>%
mutate(p.value = round(p.value, digits = 5))
## # A tibble: 4 x 8
## term estimate std.error statistic p.value conf.low conf.high group
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
## 1 (Intercept) -1.18 0.221 -5.33 0 -1.61 -0.747 fixed
## 2 Symmetric 2.01 0.0764 26.3 0 1.86 2.16 fixed
## 3 sd_(Intercept… 1.05 NA NA NA NA NA partic…
## 4 sd_(Intercept… 0.299 NA NA NA NA NA Symbol
#exponentiate TRUE transforms the estimate of the parameter from the log Odds to the odds ratio.
#i.e. there is a 1.73 times higher chance of endorsing commutativity for vertical symmetry given a constant symbol
#i.e. if adding both symbols and participants as random intercepts, the OR increases to 2 times righer risk
#we also see that there is a stronger random effect of participant than symbol
#if we add symbol as a fixed factor, we can see that symbols 10 (OR=0.66) and 6 (OR=0.60) have a significantly lower risk of being endorsed as commutative in general, while symbol 5 (OR=1.46) has a significantly higher risk of being endoresed
#in a simple logistic regression including only symmetry as fixed factor the OR increases to about 5 times higher risk