cat("\014") # clean terminal
rm(list = ls()) # clean workspace
try(dev.off(), silent = TRUE) # close all plots
library(afex)
library(emmeans)
library(ggplot2)
library(GGally)theme_set(
theme_minimal()
)master_dir <- '~/Insync/Drive/00EEG/Proyectos/Huepe/fdcyt_2017/gabormeta_huepe/behavioural'
data_dir <- paste(master_dir, 'results', sep = '/')
gabor_meta_data_name <- paste(data_dir, 'signal_params_r.csv', sep='/')
gabor_meta_data <- read.csv(gabor_meta_data_name, header = TRUE)
gabor_meta_data$Sex <- factor(gabor_meta_data$Sex)
gabor_meta_data$Group <- factor(gabor_meta_data$Group)
gabor_meta_data$Stress <- factor(gabor_meta_data$Stress)
gabor_meta_data$session <- factor(gabor_meta_data$session)
levels(gabor_meta_data$Sex) <- list(female = "F", male = "M")
levels(gabor_meta_data$Group) <- list(non_vulnerable = "CN", vulnerable = "EX")
levels(gabor_meta_data$Stress) <- list(not_stressed = "NS", stressed = "SS")
levels(gabor_meta_data$session) <- list(first = "1", second = "2")
gabor_meta_data_clean <- gabor_meta_data[gabor_meta_data$da > 0, ]
gabor_meta_data_clean <- gabor_meta_data_clean[gabor_meta_data_clean$meta_da > 0, ]
stress_response_name <- paste(master_dir, 'stress_response.csv', sep='/')
stress_response_data <- read.csv(stress_response_name, header = TRUE)
gabor_meta_data_clean <- merge(gabor_meta_data_clean, stress_response_data, by = "full.id")
gabor_meta_data_clean$stress_response <- factor(gabor_meta_data_clean$stress_response)
gabor_meta_data_clean$eliminate <- factor(gabor_meta_data_clean$eliminate)
gabor_meta_data_clean <- gabor_meta_data_clean[gabor_meta_data_clean$eliminate == "no", ]
n_occur <- data.frame(table(gabor_meta_data_clean$full.id))
gabor_meta_data_clean <- gabor_meta_data_clean[gabor_meta_data_clean$full.id %in% n_occur$Var1[n_occur$Freq > 1],]
write.csv(gabor_meta_data_clean, file = paste(data_dir, "signal_params_r_clean.csv", sep = '/'), row.names = FALSE)Observations with negative d’ and/or negative meta-d’ have been eliminated.
Also subjects with weird cortisol levels (according to young Rojas Thomas) were eliminated.
options(width = 100)
mytable <- xtabs(~ Group + stress_response, data = gabor_meta_data_clean) / length(unique(gabor_meta_data_clean$session))
ftable(addmargins(mytable)) stress_response no yes Sum
Group
non_vulnerable 11 5 16
vulnerable 6 12 18
Sum 17 17 34
summary(gabor_meta_data_clean) full.id Subject session da s meta_da
Length:68 Min. :10.00 first :34 Min. :0.04083 Min. :1 Min. :0.08672
Class :character 1st Qu.:23.00 second:34 1st Qu.:1.60497 1st Qu.:1 1st Qu.:1.42272
Mode :character Median :38.50 Median :2.27427 Median :1 Median :2.15641
Mean :38.12 Mean :2.37402 Mean :1 Mean :2.23626
3rd Qu.:50.00 3rd Qu.:3.11005 3rd Qu.:1 3rd Qu.:2.94001
Max. :76.00 Max. :4.97992 Max. :1 Max. :5.78546
M_diff M_ratio meta_ca threshold nR_S1a
Min. :-2.772576 Min. :0.03987 Min. :-0.76953 Min. :0.006576 Min. : 0.0
1st Qu.:-0.459988 1st Qu.:0.80516 1st Qu.:-0.18449 1st Qu.:0.007388 1st Qu.: 62.0
Median :-0.004952 Median :0.99864 Median :-0.09727 Median :0.008121 Median :123.0
Mean :-0.137766 Mean :1.08311 Mean :-0.06619 Mean :0.008546 Mean :129.9
3rd Qu.: 0.388688 3rd Qu.:1.20317 3rd Qu.:-0.03053 3rd Qu.:0.008920 3rd Qu.:198.0
Max. : 1.598223 Max. :5.58541 Max. : 2.45080 Max. :0.014718 Max. :267.0
nR_S1b nR_S1c nR_S1d nR_S2a nR_S2b
Min. : 0.00 Min. : 0.00 Min. : 0.000 Min. : 0.000 Min. : 0.00
1st Qu.: 30.00 1st Qu.: 10.75 1st Qu.: 1.000 1st Qu.: 0.000 1st Qu.: 7.00
Median : 83.00 Median : 23.00 Median : 3.500 Median : 1.500 Median : 21.00
Mean : 78.03 Mean : 34.68 Mean : 7.971 Mean : 8.544 Mean : 26.69
3rd Qu.:126.25 3rd Qu.: 47.50 3rd Qu.: 9.000 3rd Qu.: 6.000 3rd Qu.: 39.00
Max. :200.00 Max. :133.00 Max. :80.000 Max. :229.000 Max. :154.00
nR_S2c nR_S2d name Sex Group
Min. : 0.00 Min. : 1.0 Length:68 female:28 non_vulnerable:32
1st Qu.: 23.00 1st Qu.: 77.5 Class :character male :40 vulnerable :36
Median : 78.00 Median :140.0 Mode :character
Mean : 79.57 Mean :134.6
3rd Qu.:128.75 3rd Qu.:194.5
Max. :238.00 Max. :264.0
Stress stress_response eliminate
not_stressed:30 no :34 no :68
stressed :38 yes:34 yes: 0
options(width = 100)
sdt_params <- c('da', 'meta_da', 'M_diff')
sdt_params_pairs <- ggpairs(gabor_meta_data_clean,
columns = sdt_params,
aes(colour = stress_response, alpha = .25),
progress = FALSE,
lower = list(continuous = wrap("points")))
suppressWarnings(print(sdt_params_pairs))summary(gabor_meta_data_clean[sdt_params]) da meta_da M_diff
Min. :0.04083 Min. :0.08672 Min. :-2.772576
1st Qu.:1.60497 1st Qu.:1.42272 1st Qu.:-0.459988
Median :2.27427 Median :2.15641 Median :-0.004952
Mean :2.37402 Mean :2.23626 Mean :-0.137766
3rd Qu.:3.11005 3rd Qu.:2.94001 3rd Qu.: 0.388688
Max. :4.97992 Max. :5.78546 Max. : 1.598223
options(width = 100)
d_prime_boxplot <- ggplot(gabor_meta_data_clean, aes(x = session, y = da, color = stress_response)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitterdodge()) +
ggtitle("d'")
# d_prime_boxplot
rep_anova_d_prime = aov_ez("Subject", "da", data = gabor_meta_data_clean, within = c("session"), between = c("stress_response", "Group"))Contrasts set to contr.sum for the following variables: stress_response, Group
nice(rep_anova_d_prime)Anova Table (Type 3 tests)
Response: da
Effect df MSE F ges p.value
1 stress_response 1, 30 2.24 0.99 .026 .328
2 Group 1, 30 2.24 1.54 .040 .224
3 stress_response:Group 1, 30 2.24 0.08 .002 .784
4 session 1, 30 0.51 0.77 .005 .387
5 stress_response:session 1, 30 0.51 0.67 .004 .420
6 Group:session 1, 30 0.51 0.02 <.001 .893
7 stress_response:Group:session 1, 30 0.51 0.38 .002 .541
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
d_prime_afex_plot <-
afex_plot(
rep_anova_d_prime,
x = "session",
trace = "stress_response",
error = "between",
error_arg = list(width = .15),
dodge = -.5,
mapping = c("color"),
point_arg = list(size = 4)
)Warning: Panel(s) show a mixed within-between-design.
Error bars do not allow comparisons across all means.
Suppress error bars with: error = "none"
d_prime_afex_plot# emmeans(rep_anova_d_prime, c("stress_response", "session"), contr = "pairwise")options(width = 100)
meta_d_prime_boxplot <- ggplot(gabor_meta_data_clean, aes(x = session, y = meta_da, color = stress_response)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitterdodge()) +
ggtitle("meta d'")
# meta_d_prime_boxplot
rep_anova_meta_d_prime = aov_ez("Subject", "meta_da", data = gabor_meta_data_clean, within = c("session"), between = c("stress_response", "Group"))Contrasts set to contr.sum for the following variables: stress_response, Group
nice(rep_anova_meta_d_prime)Anova Table (Type 3 tests)
Response: meta_da
Effect df MSE F ges p.value
1 stress_response 1, 30 2.21 1.16 .033 .290
2 Group 1, 30 2.21 3.13 + .083 .087
3 stress_response:Group 1, 30 2.21 0.10 .003 .760
4 session 1, 30 0.33 7.50 * .031 .010
5 stress_response:session 1, 30 0.33 0.56 .002 .460
6 Group:session 1, 30 0.33 1.24 .005 .274
7 stress_response:Group:session 1, 30 0.33 0.38 .002 .543
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
meta_d_prime_afex_plot <-
afex_plot(
rep_anova_meta_d_prime,
x = "session",
trace = "stress_response",
panel = "Group",
error = "between",
error_arg = list(width = .15),
dodge = -.5,
mapping = c("color"),
point_arg = list(size = 4)
)Warning: Panel(s) show a mixed within-between-design.
Error bars do not allow comparisons across all means.
Suppress error bars with: error = "none"
meta_d_prime_afex_plot# emmeans(rep_anova_meta_d_prime, c("Group"), contr = "pairwise")
emmeans(rep_anova_meta_d_prime, c("session"), contr = "pairwise")$emmeans
session emmean SE df lower.CL upper.CL
first 2.44 0.223 30 1.98 2.89
second 2.03 0.190 30 1.64 2.42
Results are averaged over the levels of: stress_response, Group
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
first - second 0.407 0.149 30 2.738 0.0103
Results are averaged over the levels of: stress_response, Group
options(width = 100)
mdiff_boxplot <- ggplot(gabor_meta_data_clean, aes(x = session, y = M_diff, color = stress_response)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position = position_jitterdodge()) +
ggtitle("meta-d' minus d'")
# mdiff_boxplot
rep_anova_m_diff = aov_ez("Subject", "M_diff", data = gabor_meta_data_clean, within = c("session"), between = c("stress_response", "Group"))Contrasts set to contr.sum for the following variables: stress_response, Group
nice(rep_anova_m_diff)Anova Table (Type 3 tests)
Response: M_diff
Effect df MSE F ges p.value
1 stress_response 1, 30 1.21 0.01 <.001 .920
2 Group 1, 30 1.21 0.49 .011 .491
3 stress_response:Group 1, 30 1.21 0.00 <.001 .968
4 session 1, 30 0.52 1.68 .017 .205
5 stress_response:session 1, 30 0.52 1.96 .019 .172
6 Group:session 1, 30 0.52 1.03 .010 .318
7 stress_response:Group:session 1, 30 0.52 0.02 <.001 .900
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
m_diff_afex_plot <-
afex_plot(
rep_anova_m_diff,
x = "session",
trace = "stress_response",
error = "within",
error_arg = list(width = .15),
dodge = -.5,
mapping = c("color"),
point_arg = list(size = 4)
)Warning: Panel(s) show a mixed within-between-design.
Error bars do not allow comparisons across all means.
Suppress error bars with: error = "none"
m_diff_afex_plot# emmeans(rep_anova_m_diff, c("stress_response", "session"), contr = "pairwise")