# demographics
# one participant indicated 3 for age. Needs to be excluded for the age analysis.
tdata_age <- tdata
min(tdata_age$Age)
## [1] 18
max(tdata_age$Age)
## [1] 60
mean(tdata_age$Age)
## [1] 32.16667
sd(tdata_age$Age)
## [1] 10.82118
# 1 = male, 2 = female, 3 = other
table(tdata$Sex)
##
## 1 2 3
## 45 71 4
myTheme <- theme(plot.title = element_text(face="bold", size = 22),
axis.title.x = element_blank(),
axis.title.y = element_text(face = "bold", size = 20),
axis.text.x = element_text(size = 18, 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"))
library(see)
## first, turn sID into a factor
tdata_sub$sID <- factor(tdata_sub$sID)
pd <- position_dodge(width = 0.3)
tdata_sub$valueJitter <- jitter(tdata_sub$value, factor = 1, amount = 0.04)
theme_set(theme_light(base_size = 20, base_family = "Poppins"))
# new labes for the facets
g <- ggplot(tdata_sub, aes(x=variable, y=valueJitter, group = sID)) +
guides(fill=FALSE)+
#facet_grid( ~ Side + Q_order)+
#ggtitle("Subjects' causal srength ratings") +
scale_y_continuous(limits = c(-0.05, 1.05), breaks=seq(0, 1, 0.1), expand = c(0,0)) +
scale_x_discrete(labels=c("single-effect \n cause", "common \n cause")) +
#stat_summary(fun.y = mean, geom = "bar", position = "dodge", colour = "black", alpha =0.5) +
geom_violinhalf(aes(y = value, group = variable, fill = variable), color = NA, position=position_dodge(1), alpha = 0.3)+
geom_line(position = pd, color = "black", size = 1, alpha=0.07) +
geom_point(aes(color = variable), position = pd, alpha = 0.4, size = 2) +
stat_summary(aes(y = value,group=1), fun.data = mean_cl_boot, geom = "errorbar", width = 0, size = 1) +
stat_summary(aes(y = value,group=1), fun.y=mean, colour="black", geom="line",group=1, size = 1.5, linetype = "solid", alpha = 1)+
stat_summary(aes(y = value,group=1, fill = variable), fun.y=mean, geom="point", color = "black", shape = 22, size = 5, group=1, alpha = 1)+
stat_summary(aes(y = value,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 = "Target Cause", y = "Causal Strength Rating") +
scale_color_manual(name = "Entity",values=c("#fc9272", "#3182bd"))+
scale_fill_manual(name = "Entity",values=c("#fc9272", "#3182bd"))+
theme(legend.position = "none")+
myTheme
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.
## Warning: `fun.y` is deprecated. Use `fun` instead.
## `fun.y` is deprecated. Use `fun` instead.
## `fun.y` is deprecated. Use `fun` instead.
g
#ggsave("results_lines_main.svg",width=6,height=5)
#ggsave("results_lines_main.pdf",width=4.5,height=4.3)
Overall, a strong dilution effect. But what about the different counterbalancing conditions?
myTheme <- theme(plot.title = element_text(face="bold", size = 22),
axis.title.x = element_text(face = "bold", size = 20),
axis.title.y = element_text(face = "bold", size = 20),
axis.text.x = element_text(size = 18, angle = 0),
axis.text.y = element_text(size = 14, 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"))
library(see)
## first, turn sID into a factor
tdata_sub$sID <- factor(tdata_sub$sID)
pd <- position_dodge(width = 0.3)
tdata_sub$valueJitter <- jitter(tdata_sub$value, factor = 1, amount = 0.04)
theme_set(theme_light(base_size = 20, base_family = "Poppins"))
# new labes for the facets
g <- ggplot(tdata_sub, aes(x=variable, y=valueJitter, group = sID)) +
guides(fill=FALSE)+
facet_grid( ~ Side + Q_order)+
#ggtitle("Subjects' causal srength ratings") +
scale_y_continuous(limits = c(-0.05, 1.05), breaks=seq(0, 1, 0.1), expand = c(0,0)) +
#scale_x_discrete(labels=c("Single-effect \n cause", "Multiple-effects \n cause")) +
#stat_summary(fun.y = mean, geom = "bar", position = "dodge", colour = "black", alpha =0.5) +
geom_violinhalf(aes(y = value, group = variable, fill = variable), color = NA, position=position_dodge(1), alpha = 0.2)+
geom_line(position = pd, color = "black", size = 1, alpha=0.04) +
geom_point(aes(color = variable), position = pd, alpha = 0.2) +
stat_summary(aes(y = value,group=1), fun.data = mean_cl_boot, geom = "errorbar", width = 0, size = 1) +
stat_summary(aes(y = value,group=1), fun.y=mean, colour="black", geom="line",group=1, size = 1.5, linetype = "solid", alpha = 1)+
stat_summary(aes(y = value,group=1, fill = variable), fun.y=mean, geom="point", color = "black", shape = 22, size = 5, group=1, alpha = 1)+
stat_summary(aes(y = value,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 = "Number of Cause's Effects", y = "Causal Strength Rating") +
scale_color_manual(name = "Entity",values=c("#fc9272", "#3182bd"))+
scale_fill_manual(name = "Entity",values=c("#fc9272", "#3182bd"))+
theme(legend.position = "none")+
myTheme
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.
## Warning: `fun.y` is deprecated. Use `fun` instead.
## `fun.y` is deprecated. Use `fun` instead.
## `fun.y` is deprecated. Use `fun` instead.
g
#ggsave("results_lines.svg",width=15.5,height=9)
#ggsave("results_lines.pdf",width=15.5,height=9)
A quite pronounced dilution effect in all conditions.
## : one
## median mean SE.mean CI.mean.0.95 var std.dev
## 0.99000000 0.87141667 0.02020736 0.04001259 0.04900050 0.22136056
## coef.var
## 0.25402378
## ------------------------------------------------------------
## : three
## median mean SE.mean CI.mean.0.95 var std.dev
## 0.50000000 0.56425000 0.02425404 0.04802543 0.07059103 0.26568972
## coef.var
## 0.47087235
library(afex)
## ************
## Welcome to afex. For support visit: http://afex.singmann.science/
## - Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()
## - Methods for calculating p-values with mixed(): 'S', 'KR', 'LRT', and 'PB'
## - 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
## - NEWS: emmeans() for ANOVA models now uses model = 'multivariate' as default.
## - Get and set global package options with: afex_options()
## - Set orthogonal sum-to-zero contrasts globally: set_sum_contrasts()
## - For example analyses see: browseVignettes("afex")
## ************
##
## Attache Paket: 'afex'
## Das folgende Objekt ist maskiert 'package:lme4':
##
## lmer
library(emmeans)
a1 <- aov_car(value ~ Side*Q_order*Target_effect + Error(sID/(variable)), tdata_sub)
## Contrasts set to contr.sum for the following variables: Side, Q_order, Target_effect
a1
## Anova Table (Type 3 tests)
##
## Response: value
## Effect df MSE F ges p.value
## 1 Side 1, 108 0.06 3.84 + .017 .053
## 2 Q_order 1, 108 0.06 0.28 .001 .597
## 3 Target_effect 2, 108 0.06 0.71 .006 .495
## 4 Side:Q_order 1, 108 0.06 0.93 .004 .338
## 5 Side:Target_effect 2, 108 0.06 1.22 .011 .300
## 6 Q_order:Target_effect 2, 108 0.06 0.24 .002 .785
## 7 Side:Q_order:Target_effect 2, 108 0.06 0.99 .009 .376
## 8 variable 1, 108 0.06 92.09 *** .307 <.001
## 9 Side:variable 1, 108 0.06 0.19 <.001 .666
## 10 Q_order:variable 1, 108 0.06 1.03 .005 .312
## 11 Target_effect:variable 2, 108 0.06 0.98 .009 .380
## 12 Side:Q_order:variable 1, 108 0.06 1.05 .005 .307
## 13 Side:Target_effect:variable 2, 108 0.06 2.49 + .023 .088
## 14 Q_order:Target_effect:variable 2, 108 0.06 1.07 .010 .346
## 15 Side:Q_order:Target_effect:variable 2, 108 0.06 0.83 .008 .437
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
Only a main effect for “variable” (i.e., causal scope)
###############
# a conditional analysis
ls2 <- lsmeans(a1, c("variable")) # group means by between-condition
ls2
## variable lsmean SE df lower.CL upper.CL
## one 0.871 0.0197 108 0.832 0.910
## three 0.564 0.0245 108 0.516 0.613
##
## Results are averaged over the levels of: Side, Q_order, Target_effect
## Confidence level used: 0.95
# simple main effects
t <- pairs(ls2) # compares rep-measure differences separately for each between-factor level
t
## contrast estimate SE df t.ratio p.value
## one - three 0.307 0.032 108 9.596 <.0001
##
## Results are averaged over the levels of: Side, Q_order, Target_effect
confint(t, level = 0.95)
## contrast estimate SE df lower.CL upper.CL
## one - three 0.307 0.032 108 0.244 0.371
##
## Results are averaged over the levels of: Side, Q_order, Target_effect
## Confidence level used: 0.95
A clear dilution effect.
Make a difference plot:
t <- qt(0.975, 108, lower.tail = TRUE, log.p = FALSE)
#t
effect <- "Mdiff"
Mdiff <- 0.307
SE <- 0.032
CI <- SE*t
CI_low <- Mdiff - CI
CI_up <- Mdiff + CI
Mdiff
## [1] 0.307
CI_low
## [1] 0.2435704
CI_up
## [1] 0.3704296
# Plot
myTheme <- theme(plot.title = element_text(face="bold", size = 22),
axis.title.x = element_text(face = "bold", size = 20),
axis.title.y = element_blank(),
axis.text.x = element_text(size = 18, angle = 0),
axis.text.y = element_text(size = 40, angle = 0),
legend.text = element_text(size = 18),
legend.title = element_text(size = 22),
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"))
theme_set(theme_light(base_size = 30, base_family = "Poppins"))
barchart <- ggplot()+
myTheme+
#guides(fill=FALSE)+
#facet_wrap(~Latency + SampleSize, ncol=2)+
#ggtitle("Mean difference (95% CI)") +
#coord_cartesian(ylim=c(-0.1,2)) +
scale_y_continuous(limits = c(-0.1, 0.5), breaks=seq(-0.1, 0.5, 0.1), expand = c(0,0)) +
scale_x_discrete(labels=c("r")) +
#annotate("rect", xmin=1.7, xmax=2.3, ymin=0.95, ymax=1.05, color="#31a354", fill = "white", size = 1) +
#stat_summary(fun.y=mean, colour="grey20", geom="point", shape = 21, size = 3)+
#stat_summary(fun.y = mean, geom = "bar", position = "dodge", colour = "black")+
#stat_summary(fun.data = mean_cl_boot, geom = "errorbar", position = position_dodge(width = 0.90), width = 0.2) +
#geom_jitter(width = 0.3, height = 0.02, alpha = 0.6, colour = "red") +
#ggtitle("Means (95% bootstr. CIs)") +
#theme(axis.text.x = element_text(size = 10, angle = 0, hjust = 0.5))+
labs(x= "", y = "Mean change") +
#scale_color_manual(values=c("#005083", "#f0b64d"))# +
#scale_fill_manual(values=c("#969696", "#969696"))
#annotate("point", x = 1, y = 100, colour = "firebrick", size = 2)+
#annotate(xmin = -Inf, xmax = Inf, ymin = 4.77-1.96*0.297, ymax = 4.77+1.96*0.297, geom = "rect", alpha = 0.2, fill = "firebrick")+
#annotate(xmin = -Inf, xmax = Inf, ymin = 5.02-1.96*0.372, ymax = 5.02+1.96*0.372, geom = "rect", alpha = 0.2, fill = "blue")+
#annotate(geom = "hline",yintercept = 100, y = 100, color = "red")+
annotate("pointrange", x = 1, y = Mdiff, ymin = CI_low, ymax = CI_up, colour = "black", size = 2, shape = 24, fill = "darkgrey")+
#annotate("pointrange", x = 2, y = 5.02, ymin = 5.02-1.96*0.372, ymax = 5.02+1.96*0.372, colour = "blue", size = 0.8, shape = 15)+
#annotate("text", x = 0.5, y = 2.6, family = "Poppins", size = 6, color = "gray20", label = "Impfeffekt")+
#geom_curve(aes(x = 0.5, y = 3, xend = 0.9, yend = 4),arrow = arrow(length = unit(0.03, "npc")),color = "gray20", curvature = +0.2)+
#annotate("text", x = 1.8, y = 2.6, family = "Poppins", size = 6, color = "gray20", label = "Dosierungseffekt")+
#geom_curve(aes(x = 1.8, y = 3, xend = 2, yend = 4),arrow = arrow(length = unit(0.03, "npc")),color = "gray20", curvature = +0.2)+
annotate(geom = "hline",yintercept = 0, y = 0, color = "red", size = 1.2)+
theme(plot.background = element_rect(
fill = "white",
colour = "white",
size = 1
))
## Warning: Ignoring unknown aesthetics: y
barchart
#ggsave("delta_1st_vs_4th.svg",width=2.5,height=4)
#ggsave("delta.pdf",width=2.5,height=4)
What value for Cohen’s d is this?
library(effsize)
cohen.d(tdata_sub$value, tdata_sub$variable, paired = T)
##
## Cohen's d
##
## d estimate: 1.256598 (large)
## 95 percent confidence interval:
## lower upper
## 0.9086239 1.6045715
A large effect.
data_cluster <- tdata[-c(7:13)]
# append absolut deviations as new columns
data_cluster$Delta_Rating <- data_cluster$single - data_cluster$multiple
crit = 3
data_cluster$Change[data_cluster$Delta_Rating > crit] <- "Dilution"
data_cluster$Change[data_cluster$Delta_Rating >= -crit & data_cluster$Delta_Rating <= crit] <- "Invariance"
data_cluster$Change[data_cluster$Delta_Rating < -crit] <- "Strengthening"
data_cluster %>% count(Change)
## Change n
## 1 Dilution 82
## 2 Invariance 26
## 3 Strengthening 12
# now append the clustering results to the main data frame
data_cluster <- subset(data_cluster, select = c(1,8))
tdata_sub <- merge(tdata_sub, data_cluster, by = c("sID"))
# get CIs for the proportions
prop.test(82,120,correct=FALSE)
##
## 1-sample proportions test without continuity correction
##
## data: 82 out of 120, null probability 0.5
## X-squared = 16.133, df = 1, p-value = 5.904e-05
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.5955213 0.7597717
## sample estimates:
## p
## 0.6833333
prop.test(26,120,correct=FALSE)
##
## 1-sample proportions test without continuity correction
##
## data: 26 out of 120, null probability 0.5
## X-squared = 38.533, df = 1, p-value = 5.383e-10
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.1523672 0.2985436
## sample estimates:
## p
## 0.2166667
prop.test(12,120,correct=FALSE)
##
## 1-sample proportions test without continuity correction
##
## data: 12 out of 120, null probability 0.5
## X-squared = 76.8, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.05813359 0.16668174
## sample estimates:
## p
## 0.1
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.
## Warning: `fun.y` is deprecated. Use `fun` instead.
## `fun.y` is deprecated. Use `fun` instead.