tdata <- read_csv("exp_data.csv")
# Exclude subjects who failed the control questions
tdata <- subset(tdata, intro_check == "2: A little squid swam from the right to the left.")
tdata <- subset(tdata, timing_check_correct == "correct")
tdata <- subset(tdata, learning_check_correct == "correct")
# demographics
min(tdata$age)
## [1] 19
max(tdata$age)
## [1] 70
mean(tdata$age)
## [1] 39.25
sd(tdata$age)
## [1] 12.71393
# 1 = male, 2 = female, 3 = other
table(tdata$gender)
##
## 1: male 2: female
## 55 45
1 = male, 2 = female, 3 = non-binary, 4 = prefer not to say
Check n in each condition:
table(tdata$structure, tdata$first_object)
##
## left right
## irreversible 25 25
## reversible 25 25
Factorize:
tdata$structure <- factor(tdata$structure, levels = c("irreversible", "reversible"), labels = c("irreversible", "reversible"))
Relabel rating columns for red and yellow entity according to “first object” (so that they are called first_obj_rating and second_obj_rating):
left_first <- subset(tdata, first_object == "left")
colnames(left_first)[10] ="first_obj_caused_rating"
colnames(left_first)[11] ="second_obj_caused_rating"
colnames(left_first)[12] ="first_obj_maintained_rating"
colnames(left_first)[13] ="second_obj_maintained_rating"
right_first <- subset(tdata, first_object == "right")
colnames(right_first)[11] ="first_obj_caused_rating"
colnames(right_first)[10] ="second_obj_caused_rating"
colnames(right_first)[13] ="first_obj_maintained_rating"
colnames(right_first)[12] ="second_obj_maintained_rating"
right_first <- right_first[c("subj_code", "condition", "desktop_conf", "attent_conf", "intro_check",
"structure", "first_object", "learn_check_left", "learn_check_right",
"first_obj_caused_rating", "second_obj_caused_rating", "first_obj_maintained_rating", "second_obj_maintained_rating",
"timing_check", "recorded_at",
"age", "gender", "tech_issues", "timing_check_correct", "learning_check_left_correct",
"learning_check_right_correct", "learning_check_correct")]
names(left_first) %in% names(right_first)
## [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
tdata <- rbind(left_first, right_first)
Make a subset containing only the columns relevant for analyses and turn into long format:
# Subset:
tdata_sub <- subset(tdata, select = c("subj_code","structure","first_obj_caused_rating", "second_obj_caused_rating",
"first_obj_maintained_rating", "second_obj_maintained_rating"))
# into long format:
library(tidyr)
tdata_long <- gather(tdata_sub, entity, rating, 3:6)
# factorize entity
tdata_long$entity <- factor(tdata_long$entity, levels = c("first_obj_caused_rating", "second_obj_caused_rating",
"first_obj_maintained_rating", "second_obj_maintained_rating"),
labels = c("first \ncaused", "second \ncaused","first \nmaintained", "second \nmaintained"))
myTheme <- theme(plot.title = element_text(face="bold", size = 22),
axis.title.x = element_text(size = 20),
axis.title.y = element_text(size = 20),
axis.text.x = element_text(size = 14, angle = 0),
axis.text.y = element_text(size = 16, angle = 0),
legend.text = element_text(size = 18),
legend.title = element_text(face = "bold", size = 18),
strip.text.x = element_text(size = 18),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line.x = element_line(colour = "black"),
axis.line.y = element_line(colour = "black"),
axis.text = element_text(colour ="black"),
axis.ticks = element_line(colour ="black"))
tdata_sub <- tdata_long
library(see)
## first, turn sID into a factor
tdata_sub$subj_code <- factor(tdata_sub$subj_code)
pd <- position_dodge(width = 0.3)
tdata_sub$valueJitter <- jitter(tdata_sub$rating, factor = 0.01, amount = 0.004)
theme_set(theme_light(base_size = 20, base_family = "Poppins"))
g <- ggplot(tdata_sub, aes(x = entity, y = valueJitter)) +
guides(fill=FALSE)+
facet_grid( ~ structure,labeller = label_both)+
scale_y_continuous(limits = c(-0.3, 10.3), breaks=seq(0, 10, 1), expand = c(0,0)) +
geom_jitter(aes(color = structure), alpha = 0.5, width = 0.15, height = 0.2) +
stat_summary(aes(y = rating, group=1), fun.data = mean_cl_boot,
geom = "errorbar", width = 0, size = 1) +
stat_summary(aes(y = rating, group=1, color = structure), fun.y=mean, geom="line",
shape = 22, size = 1.5, alpha = .7)+
stat_summary(aes(y = rating, group=1, fill = structure), fun.y=mean, geom="point",
color = "black", shape = 22, size = 3, group=1, alpha = 1)+
stat_summary(aes(y = rating,group=1), fun.y=median, geom="point", color = "black", shape = 3, size = 4,
group=1, alpha = 1, position = position_dodge(width = 0.5))+
labs(x = "Causal Statement", y = "Agreement Rating") +
scale_color_manual(name = "Strength",values=c("#66c2a5", "#e78ac3", "#8da0cb", "#a6d854"))+
scale_fill_manual(name = "Strength",values=c("#66c2a5", "#e78ac3", "#8da0cb", "#a6d854"))+
theme(legend.position = "none")+
myTheme+
theme(panel.grid.major = element_line(color = "lightgrey",
size = 0.5,
linetype = 'dotted'))+
stat_summary(aes(label=round(after_stat(y),2)), fun.y=mean, geom="text", size=5,
vjust = -6)+
annotate("text", x = 0.5, y = 2, label = c("completely disagree"), angle = 90)+
annotate("text", x = 0.5, y = 8.2, label = c("completely agree"), angle = 90)
g
#ggsave("results_means_mainDV.svg",width=12,height=5)
#ggsave("results_means_mainDV.pdf",width=12,height=5)
library(ggridges)
g2 <- ggplot(tdata_long, aes(x = rating, y = entity, fill = structure)) +
facet_grid( ~ structure,labeller = label_both)+
scale_x_continuous(breaks = seq(0, 10, 1))+
geom_density_ridges(alpha = 0.5)+
#stat_summary(aes(x = rating_rec), fun.x=mean, geom="point",
# color = "black", shape = 22, size = 2, group=1, alpha = 1)+
scale_fill_manual(values=c("#66c2a5", "#e78ac3", "#8da0cb", "#a6d854"))+
#scale_fill_viridis_c(name = "Explanation \nRating", option = "C", breaks=c(-5,0,5), labels=c("narrow scope", "no preference", "broad scope"))+
labs(x = "Agreement Rating", y = "Causal Statement") +
scale_y_discrete(limits=rev)+
myTheme+
theme_light(base_family = "Poppins", base_size = 20)+
theme(panel.grid = element_blank(), axis.text = element_text(colour ="black"))+
theme(legend.position="none",
legend.title=element_blank(),legend.key.width = unit(1.95, 'cm'))+
theme(axis.text.y = element_text(size = 14, angle = 0))+
annotate("text", y = 0.7, x = 0, label = c("completely disagree"), angle = 0)+
annotate("text", y = 0.7, x = 10, label = c("completely agree"), angle = 0)
g2
#ggsave("results_dist.svg",width=12,height=5)
#ggsave("results_dist.pdf",width=12,height=5)
library(afex)
library(emmeans)
a1 <- aov_car(rating ~ structure*entity + Error(subj_code/entity), tdata_long, anova_table = list(es = "pes"))
a1
## Anova Table (Type 3 tests)
##
## Response: rating
## Effect df MSE F pes p.value
## 1 structure 1, 98 6.42 19.03 *** .163 <.001
## 2 entity 2.67, 261.83 8.02 168.69 *** .633 <.001
## 3 structure:entity 2.67, 261.83 8.02 52.73 *** .350 <.001
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
##
## Sphericity correction method: GG
Predicted interaction effect was significant-
Visualize also the obtained main effect of “structure” (reversibility)
tdata_sub <- tdata_long
library(see)
## first, turn sID into a factor
tdata_sub$subj_code <- factor(tdata_sub$subj_code)
pd <- position_dodge(width = 0.3)
tdata_sub$valueJitter <- jitter(tdata_sub$rating, factor = 0.01, amount = 0.004)
theme_set(theme_light(base_size = 20, base_family = "Poppins"))
g <- ggplot(tdata_sub, aes(x = structure, y = valueJitter)) +
guides(fill=FALSE)+
scale_y_continuous(limits = c(-0.3, 10.3), breaks=seq(0, 10, 1), expand = c(0,0)) +
geom_jitter(aes(color = structure), alpha = 0.5, width = 0.15, height = 0.2) +
stat_summary(aes(y = rating, group=1), fun.data = mean_cl_boot,
geom = "errorbar", width = 0, size = 1) +
stat_summary(aes(y = rating, group=1, fill = structure), fun.y=mean, geom="point",
color = "black", shape = 22, size = 3, group=1, alpha = 1)+
stat_summary(aes(y = rating,group=1), fun.y=median, geom="point", color = "black", shape = 3, size = 4,
group=1, alpha = 1, position = position_dodge(width = 0.5))+
labs(x = "Causal Statement", y = "Agreement Rating") +
scale_color_manual(name = "Strength",values=c("#66c2a5", "#e78ac3", "#8da0cb", "#a6d854"))+
scale_fill_manual(name = "Strength",values=c("#66c2a5", "#e78ac3", "#8da0cb", "#a6d854"))+
theme(legend.position = "none")+
myTheme+
theme(panel.grid.major = element_line(color = "lightgrey",
size = 0.5,
linetype = 'dotted'))+
stat_summary(aes(label=round(after_stat(y),2)), fun.y=mean, geom="text", size=5,
vjust = -6)+
annotate("text", x = 0.5, y = 2, label = c("completely disagree"), angle = 90)+
annotate("text", x = 0.5, y = 8.2, label = c("completely agree"), angle = 90)
g
Plot main effect of entity (causal statement):
tdata_sub <- tdata_long
library(see)
## first, turn sID into a factor
tdata_sub$subj_code <- factor(tdata_sub$subj_code)
pd <- position_dodge(width = 0.3)
tdata_sub$valueJitter <- jitter(tdata_sub$rating, factor = 0.01, amount = 0.004)
theme_set(theme_light(base_size = 20, base_family = "Poppins"))
g <- ggplot(tdata_sub, aes(x = entity, y = valueJitter)) +
guides(fill=FALSE)+
scale_y_continuous(limits = c(-0.3, 10.3), breaks=seq(0, 10, 1), expand = c(0,0)) +
geom_jitter(aes(color = entity), alpha = 0.5, width = 0.15, height = 0.2) +
stat_summary(aes(y = rating, group=1), fun.data = mean_cl_boot,
geom = "errorbar", width = 0, size = 1) +
stat_summary(aes(y = rating, group=1, fill = entity), fun.y=mean, geom="point",
color = "black", shape = 22, size = 3, group=1, alpha = 1)+
stat_summary(aes(y = rating,group=1), fun.y=median, geom="point", color = "black", shape = 3, size = 4,
group=1, alpha = 1, position = position_dodge(width = 0.5))+
labs(x = "Causal Statement", y = "Agreement Rating") +
scale_color_manual(name = "Strength",values=c("#66c2a5", "#e78ac3", "#8da0cb", "#a6d854"))+
scale_fill_manual(name = "Strength",values=c("#66c2a5", "#e78ac3", "#8da0cb", "#a6d854"))+
theme(legend.position = "none")+
annotate("text", x = 0.5, y = 1.7, label = c("completely disagree"), angle = 90)+
annotate("text", x = 0.5, y = 6.7, label = c("completely agree"), angle = 90)+
myTheme+
theme(panel.grid.major = element_line(color = "lightgrey",
size = 0.5,
linetype = 'dotted'))+
stat_summary(aes(label=round(after_stat(y),2)), fun.y=mean, geom="text", size=5,
vjust = -6)
g
library(lsmeans)
# means
ls2 <- lsmeans(a1, c("structure", "entity"))
ls2
## structure entity lsmean SE df lower.CL upper.CL
## irreversible first..caused 9.64 0.178 98 9.286 9.99
## reversible first..caused 9.40 0.178 98 9.046 9.75
## irreversible second..caused 0.92 0.408 98 0.110 1.73
## reversible second..caused 2.74 0.408 98 1.930 3.55
## irreversible first..maintained 4.60 0.437 98 3.733 5.47
## reversible first..maintained 1.40 0.437 98 0.533 2.27
## irreversible second..maintained 3.32 0.409 98 2.508 4.13
## reversible second..maintained 9.36 0.409 98 8.548 10.17
##
## Confidence level used: 0.95
contrasts <- emmeans(a1, ~ entity|structure)
s <- pairs(contrasts, adjust = "none")
s
## structure = irreversible:
## contrast estimate SE df t.ratio p.value
## first..caused - second..caused 8.72 0.492 98 17.715 <.0001
## first..caused - first..maintained 5.04 0.473 98 10.657 <.0001
## first..caused - second..maintained 6.32 0.443 98 14.272 <.0001
## second..caused - first..maintained -3.68 0.587 98 -6.266 <.0001
## second..caused - second..maintained -2.40 0.571 98 -4.200 0.0001
## first..maintained - second..maintained 1.28 0.617 98 2.073 0.0408
##
## structure = reversible:
## contrast estimate SE df t.ratio p.value
## first..caused - second..caused 6.66 0.492 98 13.530 <.0001
## first..caused - first..maintained 8.00 0.473 98 16.916 <.0001
## first..caused - second..maintained 0.04 0.443 98 0.090 0.9282
## second..caused - first..maintained 1.34 0.587 98 2.282 0.0247
## second..caused - second..maintained -6.62 0.571 98 -11.586 <.0001
## first..maintained - second..maintained -7.96 0.617 98 -12.892 <.0001
confint(s, level = 0.95)
## structure = irreversible:
## contrast estimate SE df lower.CL upper.CL
## first..caused - second..caused 8.72 0.492 98 7.7432 9.697
## first..caused - first..maintained 5.04 0.473 98 4.1015 5.979
## first..caused - second..maintained 6.32 0.443 98 5.4413 7.199
## second..caused - first..maintained -3.68 0.587 98 -4.8455 -2.515
## second..caused - second..maintained -2.40 0.571 98 -3.5339 -1.266
## first..maintained - second..maintained 1.28 0.617 98 0.0547 2.505
##
## structure = reversible:
## contrast estimate SE df lower.CL upper.CL
## first..caused - second..caused 6.66 0.492 98 5.6832 7.637
## first..caused - first..maintained 8.00 0.473 98 7.0615 8.939
## first..caused - second..maintained 0.04 0.443 98 -0.8387 0.919
## second..caused - first..maintained 1.34 0.587 98 0.1745 2.505
## second..caused - second..maintained -6.62 0.571 98 -7.7539 -5.486
## first..maintained - second..maintained -7.96 0.617 98 -9.1853 -6.735
##
## Confidence level used: 0.95
The planned contrasts from the list above are ” first..caused - second..caused” in both “irreversible” and “reversible”. Both are significant.
Get effect standardized effect sizes for the contrasts
First get the SDs that need to be pooled (and also the correlations between measures for the within-comparisons)
library(dplyr)
tdata_long %>%
group_by(structure, entity) %>%
summarise_at(vars(rating), list(name=sd))
## # A tibble: 8 × 3
## # Groups: structure [2]
## structure entity name
## <fct> <fct> <dbl>
## 1 irreversible "first \ncaused" 0.875
## 2 irreversible "second \ncaused" 1.70
## 3 irreversible "first \nmaintained" 3.64
## 4 irreversible "second \nmaintained" 3.66
## 5 reversible "first \ncaused" 1.55
## 6 reversible "second \ncaused" 3.71
## 7 reversible "first \nmaintained" 2.42
## 8 reversible "second \nmaintained" 1.83
library(dplyr)
tdata %>%
group_by(structure) %>%
summarize(cor=cor(first_obj_caused_rating, second_obj_caused_rating))
## # A tibble: 2 × 2
## structure cor
## <fct> <dbl>
## 1 irreversible -0.253
## 2 reversible -0.315
# using the functions from the MOTE package (see https://matthewbjane.quarto.pub/guide-to-effect-sizes-and-confidence-intervals/Standardized-Mean-Differences.html#sec-repeated-measures-drm)
library(MOTE)
# irreversible condition
#structure entity lsmean SE df lower.CL upper.CL
# irreversible first..caused 9.64 0.178 98 9.286 9.99
# irreversible second..caused 0.92 0.408 98 0.110 1.73
#Cor
#irreversible -0.2529154
#reversible -0.3145000
stats <- d.dep.t.rm(
m1 = 9.64,
m2 = 0.92,
sd1 = 0.875051,
sd2 = 1.700420,
n = 50,
a = 0.05,
r = -0.2529154
)
## [1] "The observed noncentrality parameter of the noncentral t-distribution has exceeded 37.62 in magnitude (R's limitation for accurate probabilities from the noncentral t-distribution) in the function's iterative search for the appropriate value(s). The results may be fine, but they might be inaccurate; use caution."
stats$estimate
## [1] "$d_{rm}$ = 6.57, 95\\% CI [5.24, 7.87]"
# reversible condition
#structure entity lsmean SE df lower.CL upper.CL
# reversible first..caused 9.40 0.178 98 9.046 9.75
# reversible second..caused 2.74 0.408 98 1.930 3.55
#Cor
#irreversible -0.2529154
#reversible -0.3145000
stats <- d.dep.t.rm(
m1 = 9.40,
m2 = 2.74,
sd1 = 1.551826,
sd2 = 3.713242,
n = 50,
a = 0.05,
r = -0.3145000
)
stats$estimate
## [1] "$d_{rm}$ = 2.43, 95\\% CI [1.87, 2.98]"
The final planned contrast compares the maintainer ratings for the second cause in “irreversible” and “reversible”. It must be looked up from the long list of contrasts below:
contrasts <- emmeans(a1, ~ entity*structure)
s <- pairs(contrasts, adjust = "none")
s
## contrast estimate
## first..caused irreversible - second..caused irreversible 8.72
## first..caused irreversible - first..maintained irreversible 5.04
## first..caused irreversible - second..maintained irreversible 6.32
## first..caused irreversible - first..caused reversible 0.24
## first..caused irreversible - second..caused reversible 6.90
## first..caused irreversible - first..maintained reversible 8.24
## first..caused irreversible - second..maintained reversible 0.28
## second..caused irreversible - first..maintained irreversible -3.68
## second..caused irreversible - second..maintained irreversible -2.40
## second..caused irreversible - first..caused reversible -8.48
## second..caused irreversible - second..caused reversible -1.82
## second..caused irreversible - first..maintained reversible -0.48
## second..caused irreversible - second..maintained reversible -8.44
## first..maintained irreversible - second..maintained irreversible 1.28
## first..maintained irreversible - first..caused reversible -4.80
## first..maintained irreversible - second..caused reversible 1.86
## first..maintained irreversible - first..maintained reversible 3.20
## first..maintained irreversible - second..maintained reversible -4.76
## second..maintained irreversible - first..caused reversible -6.08
## second..maintained irreversible - second..caused reversible 0.58
## second..maintained irreversible - first..maintained reversible 1.92
## second..maintained irreversible - second..maintained reversible -6.04
## first..caused reversible - second..caused reversible 6.66
## first..caused reversible - first..maintained reversible 8.00
## first..caused reversible - second..maintained reversible 0.04
## second..caused reversible - first..maintained reversible 1.34
## second..caused reversible - second..maintained reversible -6.62
## first..maintained reversible - second..maintained reversible -7.96
## SE df t.ratio p.value
## 0.492 98 17.715 <.0001
## 0.473 98 10.657 <.0001
## 0.443 98 14.272 <.0001
## 0.252 98 0.953 0.3431
## 0.446 98 15.486 <.0001
## 0.472 98 17.459 <.0001
## 0.446 98 0.627 0.5319
## 0.587 98 -6.266 <.0001
## 0.571 98 -4.200 0.0001
## 0.446 98 -19.032 <.0001
## 0.578 98 -3.151 0.0022
## 0.598 98 -0.802 0.4242
## 0.578 98 -14.599 <.0001
## 0.617 98 2.073 0.0408
## 0.472 98 -10.170 <.0001
## 0.598 98 3.109 0.0025
## 0.618 98 5.177 <.0001
## 0.599 98 -7.950 <.0001
## 0.446 98 -13.624 <.0001
## 0.578 98 1.003 0.3182
## 0.599 98 3.207 0.0018
## 0.579 98 -10.438 <.0001
## 0.492 98 13.530 <.0001
## 0.473 98 16.916 <.0001
## 0.443 98 0.090 0.9282
## 0.587 98 2.282 0.0247
## 0.571 98 -11.586 <.0001
## 0.617 98 -12.892 <.0001
confint(s, level = 0.95)
## contrast estimate
## first..caused irreversible - second..caused irreversible 8.72
## first..caused irreversible - first..maintained irreversible 5.04
## first..caused irreversible - second..maintained irreversible 6.32
## first..caused irreversible - first..caused reversible 0.24
## first..caused irreversible - second..caused reversible 6.90
## first..caused irreversible - first..maintained reversible 8.24
## first..caused irreversible - second..maintained reversible 0.28
## second..caused irreversible - first..maintained irreversible -3.68
## second..caused irreversible - second..maintained irreversible -2.40
## second..caused irreversible - first..caused reversible -8.48
## second..caused irreversible - second..caused reversible -1.82
## second..caused irreversible - first..maintained reversible -0.48
## second..caused irreversible - second..maintained reversible -8.44
## first..maintained irreversible - second..maintained irreversible 1.28
## first..maintained irreversible - first..caused reversible -4.80
## first..maintained irreversible - second..caused reversible 1.86
## first..maintained irreversible - first..maintained reversible 3.20
## first..maintained irreversible - second..maintained reversible -4.76
## second..maintained irreversible - first..caused reversible -6.08
## second..maintained irreversible - second..caused reversible 0.58
## second..maintained irreversible - first..maintained reversible 1.92
## second..maintained irreversible - second..maintained reversible -6.04
## first..caused reversible - second..caused reversible 6.66
## first..caused reversible - first..maintained reversible 8.00
## first..caused reversible - second..maintained reversible 0.04
## second..caused reversible - first..maintained reversible 1.34
## second..caused reversible - second..maintained reversible -6.62
## first..maintained reversible - second..maintained reversible -7.96
## SE df lower.CL upper.CL
## 0.492 98 7.7432 9.697
## 0.473 98 4.1015 5.979
## 0.443 98 5.4413 7.199
## 0.252 98 -0.2600 0.740
## 0.446 98 6.0158 7.784
## 0.472 98 7.3034 9.177
## 0.446 98 -0.6056 1.166
## 0.587 98 -4.8455 -2.515
## 0.571 98 -3.5339 -1.266
## 0.446 98 -9.3642 -7.596
## 0.578 98 -2.9662 -0.674
## 0.598 98 -1.6671 0.707
## 0.578 98 -9.5873 -7.293
## 0.617 98 0.0547 2.505
## 0.472 98 -5.7366 -3.863
## 0.598 98 0.6729 3.047
## 0.618 98 1.9734 4.427
## 0.599 98 -5.9481 -3.572
## 0.446 98 -6.9656 -5.194
## 0.578 98 -0.5673 1.727
## 0.599 98 0.7319 3.108
## 0.579 98 -7.1883 -4.892
## 0.492 98 5.6832 7.637
## 0.473 98 7.0615 8.939
## 0.443 98 -0.8387 0.919
## 0.587 98 0.1745 2.505
## 0.571 98 -7.7539 -5.486
## 0.617 98 -9.1853 -6.735
##
## Confidence level used: 0.95
The relevant contrast is: “second..maintained irreversible - second..maintained reversible”, which is significant.
Get effect size:
#structure entity lsmean SE df lower.CL upper.CL
#irreversible second..maintained 3.32 0.409 98 2.508 4.13
#reversible second..maintained 9.36 0.409 98 8.548 10.17
#SDs
#irreversible second \nmaintained 3.661381
#reversible second \nmaintained 1.826785
stats <- d.ind.t(
m1 = 9.36,
m2 = 3.32,
sd1 = 1.826785,
sd2 = 3.661381,
n1 = 50,
n2 = 50,
a = 0.05
)
stats$estimate
## [1] "$d_s$ = 2.09, 95\\% CI [1.60, 2.57]"