rm(list = ls()) # clean workspace
try(dev.off(), silent = TRUE) # close all plots
library(tidyverse)
library(readxl)
library(afex)
library(emmeans)
library(GGally)
library(ggpubr)my_dodge <- .5
exclude_bad_eeg <- TRUE
theme_set(theme_minimal())
a_posteriori <- function(afex_aov, sig_level = .05) {
factors <- as.list(rownames(afex_aov$anova_table))
for (j in 1:length(factors)) {
if (grepl(":", factors[[j]])) {
factors[[j]] <- unlist(strsplit(factors[[j]], ":"))
}
}
p_values <- afex_aov$anova_table$`Pr(>F)`
for (i in 1:length(p_values)) {
if (p_values[i] <= sig_level) {
cat(rep("_", 100), '\n', sep = "")
print(emmeans(afex_aov, factors[[i]], contr = "pairwise"))
}
}
}eeg_check <- read_excel(file.path('..', '..', 'bad_channels_bqd.xlsx'))
eeg_check <- eeg_check %>%
mutate(badchan_num = ifelse(bad_channels == '0', 0, sapply(strsplit(bad_channels, " "), length)))
bad_eeg <- eeg_check$file[eeg_check$to_kill == 1]
data_dir <- file.path('..', 'results')
aat_n1_name <- file.path(data_dir, 'average_voltage_145_to_175_AAT_infinity_reference_and_personal_choice.txt')
aat_p2_name <- file.path(data_dir, 'average_voltage_210_to_250_AAT_infinity_reference_and_personal_choice.txt')
aat_n1_data <- read.table(aat_n1_name, header = TRUE, strip.white = TRUE, sep = "\t")
aat_p2_data <- read.table(aat_p2_name, header = TRUE, strip.white = TRUE, sep = "\t")
aat_data <- rbind(aat_n1_data, aat_p2_data)
aat_data$worklat <- gsub(".0", "", aat_data$worklat, fixed = TRUE)
names(aat_data)[names(aat_data) == "mlabel"] <- "component"
names(aat_data)[names(aat_data) == "value"] <- "amplitude"
names(aat_data)[names(aat_data) == "binlabel"] <- "stimulus"
aat_data <- aat_data %>% separate(stimulus, c("cue","valence"), sep = "_", remove = FALSE)
aat_data$id_code <- gsub ('_Ctrl_infinity_reference_and_personal_choice', '', aat_data$ERPset)
aat_data$id_code <- gsub ('_Mind_infinity_reference_and_personal_choice', '', aat_data$id_code)
aat_data$num_id <- readr::parse_number(aat_data$id_code)
aat_data <- aat_data %>% separate(id_code, c(NA, NA, "figure", "side"), sep = "_", remove = FALSE)
aat_data$group[grepl("Ctrl", aat_data$ERPset)] <- "Control"
aat_data$group[grepl("Mind", aat_data$ERPset)] <- "Mindfulness"
aat_data$anteroposterior[aat_data$chlabel %in% c('O1' , 'Oz' , 'O2' )] <- 'Occipital'
aat_data$anteroposterior[aat_data$chlabel %in% c('E014', 'E024', 'E027')] <- 'SubOccipital'
aat_data$anteroposterior[aat_data$chlabel %in% c('E013', 'Iz' , 'E026')] <- 'Inion'
aat_data$lateral[aat_data$chlabel %in% c('O1', 'E014', 'E013')] <- 'Left'
aat_data$lateral[aat_data$chlabel %in% c('Oz', 'E024', 'Iz' )] <- 'Central'
aat_data$lateral[aat_data$chlabel %in% c('O2', 'E027', 'E026')] <- 'Right'
aat_data[sapply(aat_data, is.character)] <- lapply(aat_data[sapply(aat_data, is.character)], as.factor)
aat_data$lateral <- factor(aat_data$lateral , levels = c("Left", "Central", "Right"))
aat_data$anteroposterior <- factor(aat_data$anteroposterior, levels = c("Occipital", "SubOccipital", "Inion"))
aat_data$cue <- fct_rev(aat_data$cue)
if (exclude_bad_eeg) {
aat_data <- aat_data[!(aat_data$id_code %in% bad_eeg), ]
}
write.csv(aat_data, file.path(data_dir, 'aat_data_clean_infinity_reference_and_personal_choice.csv'), row.names = FALSE)aat_n1_name_peak <- file.path(data_dir, 'peak_voltage_135_to_215_AAT_infinity_reference_and_personal_choice.txt')
aat_p2_name_peak <- file.path(data_dir, 'peak_voltage_215_to_285_AAT_infinity_reference_and_personal_choice.txt')
aat_n1_data_peak <- read.table(aat_n1_name_peak, header = TRUE, strip.white = TRUE, sep = "\t")
aat_p2_data_peak <- read.table(aat_p2_name_peak, header = TRUE, strip.white = TRUE, sep = "\t")
aat_data_peak <- rbind(aat_n1_data_peak, aat_p2_data_peak)
names(aat_data_peak)[names(aat_data_peak) == "worklat"] <- "latency"
aat_data_peak$latency <- gsub('[', '', aat_data_peak$latency, fixed = TRUE)
aat_data_peak$latency <- gsub(']', '', aat_data_peak$latency, fixed = TRUE)
aat_data_peak$latency <- as.numeric(aat_data_peak$latency)
names(aat_data_peak)[names(aat_data_peak) == "mlabel"] <- "component"
names(aat_data_peak)[names(aat_data_peak) == "value"] <- "amplitude"
names(aat_data_peak)[names(aat_data_peak) == "binlabel"] <- "stimulus"
aat_data_peak <- aat_data_peak %>% separate(stimulus, c("cue","valence"), sep = "_", remove = FALSE)
aat_data_peak$id_code <- gsub ('_Ctrl_infinity_reference_and_personal_choice', '', aat_data_peak$ERPset)
aat_data_peak$id_code <- gsub ('_Mind_infinity_reference_and_personal_choice', '', aat_data_peak$id_code)
aat_data_peak$num_id <- readr::parse_number(aat_data_peak$id_code)
aat_data_peak <- aat_data_peak %>% separate(id_code, c(NA, NA, "figure", "side"), sep = "_", remove = FALSE)
aat_data_peak$group[grepl("Ctrl", aat_data_peak$ERPset)] <- "Control"
aat_data_peak$group[grepl("Mind", aat_data_peak$ERPset)] <- "Mindfulness"
aat_data_peak <- aat_data_peak %>% separate(id_code, c(NA, NA, "figure", "side"), sep = "_", remove = FALSE)
names(aat_data_peak)[names(aat_data_peak) == "binlabel"] <- "stimulus"
aat_data_peak$num_id <- readr::parse_number(aat_data_peak$ERPset)
aat_data_peak$group[grepl("Ctrl", aat_data_peak$ERPset)] <- "Control"
aat_data_peak$group[grepl("Mind", aat_data_peak$ERPset)] <- "Mindfulness"
aat_data_peak <- aat_data_peak %>% separate(stimulus, c("cue","valence"), sep = "_", remove = FALSE)
aat_data_peak[sapply(aat_data_peak, is.character)] <- lapply(aat_data_peak[sapply(aat_data_peak, is.character)], as.factor)
aat_data_peak$cue <- fct_rev(aat_data_peak$cue)
if (exclude_bad_eeg) {
aat_data <- aat_data[!(aat_data$id_code %in% bad_eeg), ]
}
write.csv(aat_data_peak, file.path(data_dir, 'aat_data_peak_clean_infinity_reference_and_personal_choice.csv'), row.names = FALSE)options(width = 100)
mytable <- xtabs(~ group + figure + side, data = aat_data) / length(unique(aat_data$chindex)) / length(unique(aat_data$bini)) / length(unique(aat_data$component))
ftable(addmargins(mytable)) side left right Sum
group figure
Control circ 7 8 15
rect 7 8 15
Sum 14 16 30
Mindfulness circ 9 6 15
rect 8 7 15
Sum 17 13 30
Sum circ 16 14 30
rect 15 15 30
Sum 31 29 60
ggplot(eeg_check, aes(badchan_num)) + geom_histogram(bins = 13, color = 'darkblue', fill = 'lightblue') + scale_x_continuous(breaks=0:12)options(width = 100)
ggplot(
aat_data, aes(x = amplitude, fill = component, color = component)) +
geom_histogram(alpha = .3, position = "identity") +
ggtitle("Average voltages")`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
worklat component amplitude chindex chlabel bini
[145 175]:2160 N1:2160 Min. :-21.4284 Min. :13.00 E013 : 480 Min. :5.00
[210 250]:2160 P2:2160 1st Qu.: -0.5646 1st Qu.:15.00 E014 : 480 1st Qu.:5.75
Median : 2.4152 Median :24.00 E024 : 480 Median :6.50
Mean : 2.2587 Mean :21.67 E026 : 480 Mean :6.50
3rd Qu.: 5.3956 3rd Qu.:26.00 E027 : 480 3rd Qu.:7.25
Max. : 19.2828 Max. :28.00 Iz : 480 Max. :8.00
(Other):1440
stimulus cue valence
Approach_Attractive:1080 Avoid :2160 Attractive:2160
Approach_Neutral :1080 Approach:2160 Neutral :2160
Avoid_Attractive :1080
Avoid_Neutral :1080
ERPset id_code
S01_C1_circ_right_Ctrl_infinity_reference_and_personal_choice: 72 S01_C1_circ_right: 72
S02_C2_circ_left_Mind_infinity_reference_and_personal_choice : 72 S02_C2_circ_left : 72
S03_C1_rect_right_Ctrl_infinity_reference_and_personal_choice: 72 S03_C1_rect_right: 72
S04_C1_rect_left_Ctrl_infinity_reference_and_personal_choice : 72 S04_C1_rect_left : 72
S05_C1_circ_left_Ctrl_infinity_reference_and_personal_choice : 72 S05_C1_circ_left : 72
S06_C2_circ_left_Mind_infinity_reference_and_personal_choice : 72 S06_C2_circ_left : 72
(Other) :3888 (Other) :3888
figure side num_id group anteroposterior lateral
circ:2160 left :2232 Min. : 1.00 Control :2160 Occipital :1440 Left :1440
rect:2160 right:2088 1st Qu.:16.75 Mindfulness:2160 SubOccipital:1440 Central:1440
Median :32.50 Inion :1440 Right :1440
Mean :32.40
3rd Qu.:47.25
Max. :65.00
Electrodes O1, Oz, O2, E014, E024, E027, E013, Iz, E026
options(width = 100)
aat_n1_rep_anova <- aov_ez("num_id", "amplitude", subset(aat_data, component == "N1"), within = c("cue", "valence"), between = c("group"))Warning: More than one observation per design cell, aggregating data using `fun_aggregate = mean`.
To turn off this warning, pass `fun_aggregate = mean` explicitly.
Contrasts set to contr.sum for the following variables: group
cell_means <- aat_n1_rep_anova$data$long |>
group_by(group, valence, cue) |>
summarise(amplitude = mean(amplitude))`summarise()` has grouped output by 'group', 'valence'. You can override using the `.groups`
argument.
aat_n1_afex_plot <-
afex_plot(
aat_n1_rep_anova,
x = "valence",
trace = "cue",
panel = "group",
error = "between",
error_arg = list(width = .2, lwd = .75, col = 'gray30', alpha = .7),
dodge = my_dodge,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .2,
# jitter.height = .1,
dodge.width = my_dodge ## needs to be same as dodge
)),
mapping = c("color"), data_alpha = .3,
# point_arg = list(size = 3)
)Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
Anova Table (Type 3 tests)
Response: amplitude
Effect df MSE F ges p.value
1 group 1, 58 60.93 0.01 <.001 .916
2 cue 1, 58 0.67 9.44 ** .002 .003
3 group:cue 1, 58 0.67 3.88 + <.001 .054
4 valence 1, 58 0.50 59.43 *** .008 <.001
5 group:valence 1, 58 0.50 0.00 <.001 .966
6 cue:valence 1, 58 0.57 0.66 <.001 .421
7 group:cue:valence 1, 58 0.57 0.12 <.001 .733
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
suppressWarnings(print(aat_n1_afex_plot +
geom_point(data = cell_means,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_dodge(my_dodge), size = 2.5) +
facet_grid(~group)
))____________________________________________________________________________________________________
$emmeans
cue emmean SE df lower.CL upper.CL
Avoid -0.0617 0.502 58 -1.07 0.944
Approach -0.3873 0.511 58 -1.41 0.635
Results are averaged over the levels of: group, valence
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Avoid - Approach 0.326 0.106 58 3.073 0.0032
Results are averaged over the levels of: group, valence
____________________________________________________________________________________________________
$emmeans
valence emmean SE df lower.CL upper.CL
Attractive -0.576 0.509 58 -1.59 0.443
Neutral 0.127 0.503 58 -0.88 1.134
Results are averaged over the levels of: group, cue
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Attractive - Neutral -0.703 0.0912 58 -7.709 <.0001
Results are averaged over the levels of: group, cue
afex_plot(
aat_n1_rep_anova,
x = "valence",
trace = "cue",
panel = "group",
error = "between",
data_geom = geom_violin,
error_arg = list(width = .2, lwd = .75, col = 'gray10', alpha = .8),
dodge = my_dodge,
line_arg = list(size = 0),
mapping = c("color")
) +
geom_point(data = aat_n1_rep_anova$data$long,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_jitterdodge(jitter.width = 0.2, dodge.width = my_dodge),
alpha = .4) +
geom_point(data = cell_means,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_dodge(my_dodge), size = 2.5) +
facet_grid(~group)Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
options(width = 100)
aat_n1_topo_rep_anova <- aov_ez("num_id", "amplitude", subset(aat_data, component == "N1"), within = c("anteroposterior", "lateral"))Warning: More than one observation per design cell, aggregating data using `fun_aggregate = mean`.
To turn off this warning, pass `fun_aggregate = mean` explicitly.
aat_n1_topo_afex_plot <-
afex_plot(
aat_n1_topo_rep_anova,
x = "lateral",
trace = "anteroposterior",
error = "between",
error_arg = list(width = .2, lwd = .75, col = 'gray30', alpha = .7),
dodge = my_dodge,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .2,
# jitter.height = .1,
dodge.width = my_dodge ## needs to be same as dodge
)),
mapping = c("color"), data_alpha = .3,
# point_arg = list(size = 2)
)Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
Anova Table (Type 3 tests)
Response: amplitude
Effect df MSE F ges p.value
1 anteroposterior 1.23, 72.73 3.78 3.16 + .002 .071
2 lateral 1.80, 105.98 8.27 49.67 *** .074 <.001
3 anteroposterior:lateral 3.32, 195.97 0.87 11.62 *** .004 <.001
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
Sphericity correction method: GG
____________________________________________________________________________________________________
$emmeans
lateral emmean SE df lower.CL upper.CL
Left 1.0408 0.493 59 0.0538 2.028
Central -1.7790 0.557 59 -2.8927 -0.665
Right 0.0646 0.528 59 -0.9911 1.120
Results are averaged over the levels of: anteroposterior
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Left - Central 2.820 0.238 59 11.861 <.0001
Left - Right 0.976 0.323 59 3.027 0.0101
Central - Right -1.844 0.295 59 -6.246 <.0001
Results are averaged over the levels of: anteroposterior
P value adjustment: tukey method for comparing a family of 3 estimates
____________________________________________________________________________________________________
$emmeans
anteroposterior lateral emmean SE df lower.CL upper.CL
Occipital Left 1.175 0.552 59 0.0694 2.280
SubOccipital Left 1.230 0.534 59 0.1606 2.299
Inion Left 0.718 0.436 59 -0.1539 1.589
Occipital Central -2.284 0.625 59 -3.5341 -1.034
SubOccipital Central -1.730 0.549 59 -2.8296 -0.631
Inion Central -1.322 0.533 59 -2.3882 -0.257
Occipital Right -0.262 0.563 59 -1.3877 0.865
SubOccipital Right 0.121 0.549 59 -0.9768 1.219
Inion Right 0.334 0.496 59 -0.6587 1.327
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Occipital Left - SubOccipital Left -0.055 0.1482 59 -0.371 1.0000
Occipital Left - Inion Left 0.457 0.2894 59 1.579 0.8118
Occipital Left - Occipital Central 3.459 0.3103 59 11.146 <.0001
Occipital Left - SubOccipital Central 2.905 0.3293 59 8.823 <.0001
Occipital Left - Inion Central 2.497 0.3224 59 7.746 <.0001
Occipital Left - Occipital Right 1.436 0.3725 59 3.857 0.0082
Occipital Left - SubOccipital Right 1.054 0.3875 59 2.719 0.1637
Occipital Left - Inion Right 0.841 0.3980 59 2.112 0.4753
SubOccipital Left - Inion Left 0.512 0.2140 59 2.394 0.3067
SubOccipital Left - Occipital Central 3.514 0.3052 59 11.513 <.0001
SubOccipital Left - SubOccipital Central 2.960 0.2883 59 10.268 <.0001
SubOccipital Left - Inion Central 2.552 0.2693 59 9.478 <.0001
SubOccipital Left - Occipital Right 1.491 0.3472 59 4.295 0.0020
SubOccipital Left - SubOccipital Right 1.108 0.3496 59 3.171 0.0567
SubOccipital Left - Inion Right 0.896 0.3348 59 2.675 0.1793
Inion Left - Occipital Central 3.002 0.3583 59 8.378 <.0001
Inion Left - SubOccipital Central 2.448 0.2572 59 9.519 <.0001
Inion Left - Inion Central 2.040 0.2174 59 9.385 <.0001
Inion Left - Occipital Right 0.979 0.3779 59 2.591 0.2125
Inion Left - SubOccipital Right 0.596 0.3780 59 1.578 0.8127
Inion Left - Inion Right 0.384 0.2950 59 1.300 0.9274
Occipital Central - SubOccipital Central -0.554 0.2367 59 -2.339 0.3368
Occipital Central - Inion Central -0.962 0.2604 59 -3.693 0.0134
Occipital Central - Occipital Right -2.023 0.3443 59 -5.874 <.0001
Occipital Central - SubOccipital Right -2.405 0.3688 59 -6.522 <.0001
Occipital Central - Inion Right -2.618 0.3863 59 -6.777 <.0001
SubOccipital Central - Inion Central -0.408 0.1230 59 -3.317 0.0387
SubOccipital Central - Occipital Right -1.469 0.3399 59 -4.321 0.0019
SubOccipital Central - SubOccipital Right -1.852 0.3467 59 -5.341 0.0001
SubOccipital Central - Inion Right -2.065 0.3124 59 -6.610 <.0001
Inion Central - Occipital Right -1.061 0.3134 59 -3.385 0.0322
Inion Central - SubOccipital Right -1.444 0.3171 59 -4.553 0.0009
Inion Central - Inion Right -1.657 0.2728 59 -6.072 <.0001
Occipital Right - SubOccipital Right -0.383 0.0992 59 -3.861 0.0081
Occipital Right - Inion Right -0.596 0.2146 59 -2.776 0.1447
SubOccipital Right - Inion Right -0.213 0.1770 59 -1.202 0.9528
P value adjustment: tukey method for comparing a family of 9 estimates
Electrodes O1, Oz, O2, E014, E024, E027, E013, Iz, E026
options(width = 100)
aat_p2_rep_anova <- aov_ez("num_id", "amplitude", subset(aat_data, component == "P2"), within = c("cue", "valence"), between = c("group"))Warning: More than one observation per design cell, aggregating data using `fun_aggregate = mean`.
To turn off this warning, pass `fun_aggregate = mean` explicitly.
Contrasts set to contr.sum for the following variables: group
cell_means <- aat_p2_rep_anova$data$long |>
group_by(group, valence, cue) |>
summarise(amplitude = mean(amplitude))`summarise()` has grouped output by 'group', 'valence'. You can override using the `.groups`
argument.
aat_p2_afex_plot <-
afex_plot(
aat_p2_rep_anova,
x = "valence",
trace = "cue",
panel = "group",
error = "between",
error_arg = list(width = .2, lwd = .75, col = 'gray30', alpha = .7),
dodge = my_dodge,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .2,
# jitter.height = .1,
dodge.width = my_dodge ## needs to be same as dodge
)),
mapping = c("color"), data_alpha = .3,
point_arg = list(size = 2)
)Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
Anova Table (Type 3 tests)
Response: amplitude
Effect df MSE F ges p.value
1 group 1, 58 43.92 0.02 <.001 .885
2 cue 1, 58 0.86 12.07 *** .004 <.001
3 group:cue 1, 58 0.86 0.00 <.001 .958
4 valence 1, 58 0.72 10.51 ** .003 .002
5 group:valence 1, 58 0.72 0.02 <.001 .893
6 cue:valence 1, 58 0.69 0.17 <.001 .684
7 group:cue:valence 1, 58 0.69 0.17 <.001 .683
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
suppressWarnings(print(aat_p2_afex_plot +
geom_point(data = cell_means,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_dodge(my_dodge), size = 2.5) +
facet_grid(~group)
))____________________________________________________________________________________________________
$emmeans
cue emmean SE df lower.CL upper.CL
Avoid 4.95 0.441 58 4.07 5.83
Approach 4.53 0.423 58 3.69 5.38
Results are averaged over the levels of: group, valence
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Avoid - Approach 0.416 0.12 58 3.474 0.0010
Results are averaged over the levels of: group, valence
____________________________________________________________________________________________________
$emmeans
valence emmean SE df lower.CL upper.CL
Attractive 4.92 0.415 58 4.09 5.75
Neutral 4.56 0.447 58 3.67 5.46
Results are averaged over the levels of: group, cue
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Attractive - Neutral 0.356 0.11 58 3.241 0.0020
Results are averaged over the levels of: group, cue
afex_plot(
aat_p2_rep_anova,
x = "valence",
trace = "cue",
panel = "group",
error = "between",
data_geom = geom_violin,
error_arg = list(width = .2, lwd = .75, col = 'gray10', alpha = .8),
dodge = my_dodge,
line_arg = list(size = 0),
mapping = c("color")
) +
geom_point(data = aat_p2_rep_anova$data$long,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_jitterdodge(jitter.width = 0.2, dodge.width = my_dodge),
alpha = .4) +
geom_point(data = cell_means,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_dodge(my_dodge), size = 2.5) +
facet_grid(~group)Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
options(width = 100)
aat_p2_topo_rep_anova <- aov_ez("num_id", "amplitude", subset(aat_data, component == "P2"), within = c("anteroposterior", "lateral"))Warning: More than one observation per design cell, aggregating data using `fun_aggregate = mean`.
To turn off this warning, pass `fun_aggregate = mean` explicitly.
aat_p2_topo_afex_plot <-
afex_plot(
aat_p2_topo_rep_anova,
x = "lateral",
trace = "anteroposterior",
error = "between",
error_arg = list(width = .2, lwd = .75, col = 'gray30', alpha = .7),
dodge = my_dodge,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .2,
# jitter.height = .1,
dodge.width = my_dodge ## needs to be same as dodge
)),
mapping = c("color"), data_alpha = .3,
point_arg = list(size = 2)
)Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
Anova Table (Type 3 tests)
Response: amplitude
Effect df MSE F ges p.value
1 anteroposterior 1.29, 75.96 2.99 8.12 ** .005 .003
2 lateral 1.65, 97.56 7.51 12.55 *** .022 <.001
3 anteroposterior:lateral 3.34, 197.01 0.77 6.72 *** .003 <.001
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
Sphericity correction method: GG
____________________________________________________________________________________________________
$emmeans
anteroposterior emmean SE df lower.CL upper.CL
Occipital 4.89 0.460 59 3.97 5.81
SubOccipital 4.93 0.440 59 4.05 5.81
Inion 4.40 0.396 59 3.61 5.20
Results are averaged over the levels of: lateral
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Occipital - SubOccipital -0.0394 0.115 59 -0.344 0.9371
Occipital - Inion 0.4894 0.193 59 2.534 0.0366
SubOccipital - Inion 0.5287 0.117 59 4.512 0.0001
Results are averaged over the levels of: lateral
P value adjustment: tukey method for comparing a family of 3 estimates
____________________________________________________________________________________________________
$emmeans
lateral emmean SE df lower.CL upper.CL
Left 4.84 0.431 59 3.97 5.70
Central 4.04 0.443 59 3.16 4.93
Right 5.35 0.477 59 4.39 6.30
Results are averaged over the levels of: anteroposterior
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Left - Central 0.795 0.198 59 4.018 0.0005
Left - Right -0.511 0.305 59 -1.676 0.2229
Central - Right -1.305 0.274 59 -4.766 <.0001
Results are averaged over the levels of: anteroposterior
P value adjustment: tukey method for comparing a family of 3 estimates
____________________________________________________________________________________________________
$emmeans
anteroposterior lateral emmean SE df lower.CL upper.CL
Occipital Left 5.20 0.472 59 4.25 6.14
SubOccipital Left 5.11 0.473 59 4.16 6.05
Inion Left 4.21 0.393 59 3.42 4.99
Occipital Central 3.99 0.488 59 3.01 4.97
SubOccipital Central 4.12 0.444 59 3.23 5.01
Inion Central 4.01 0.426 59 3.16 4.87
Occipital Right 5.49 0.522 59 4.44 6.53
SubOccipital Right 5.57 0.503 59 4.56 6.57
Inion Right 4.99 0.435 59 4.12 5.86
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Occipital Left - SubOccipital Left 0.0933 0.1616 59 0.577 0.9997
Occipital Left - Inion Left 0.9923 0.2684 59 3.698 0.0132
Occipital Left - Occipital Central 1.2090 0.2656 59 4.552 0.0009
Occipital Left - SubOccipital Central 1.0755 0.2631 59 4.088 0.0040
Occipital Left - Inion Central 1.1850 0.2969 59 3.992 0.0054
Occipital Left - Occipital Right -0.2893 0.3643 59 -0.794 0.9966
Occipital Left - SubOccipital Right -0.3672 0.4009 59 -0.916 0.9912
Occipital Left - Inion Right 0.2105 0.3911 59 0.538 0.9998
SubOccipital Left - Inion Left 0.8990 0.1916 59 4.692 0.0005
SubOccipital Left - Occipital Central 1.1157 0.2645 59 4.218 0.0026
SubOccipital Left - SubOccipital Central 0.9822 0.2406 59 4.082 0.0040
SubOccipital Left - Inion Central 1.0917 0.2472 59 4.417 0.0014
SubOccipital Left - Occipital Right -0.3826 0.3299 59 -1.160 0.9617
SubOccipital Left - SubOccipital Right -0.4605 0.3462 59 -1.330 0.9181
SubOccipital Left - Inion Right 0.1172 0.3279 59 0.358 1.0000
Inion Left - Occipital Central 0.2167 0.2866 59 0.756 0.9976
Inion Left - SubOccipital Central 0.0832 0.2011 59 0.414 1.0000
Inion Left - Inion Central 0.1927 0.1775 59 1.086 0.9741
Inion Left - Occipital Right -1.2816 0.3211 59 -3.991 0.0054
Inion Left - SubOccipital Right -1.3595 0.3384 59 -4.017 0.0050
Inion Left - Inion Right -0.7818 0.2667 59 -2.931 0.1020
Occipital Central - SubOccipital Central -0.1335 0.1766 59 -0.756 0.9976
Occipital Central - Inion Central -0.0240 0.2074 59 -0.116 1.0000
Occipital Central - Occipital Right -1.4983 0.3137 59 -4.776 0.0004
Occipital Central - SubOccipital Right -1.5762 0.3516 59 -4.483 0.0011
Occipital Central - Inion Right -0.9985 0.3605 59 -2.770 0.1467
SubOccipital Central - Inion Central 0.1095 0.0991 59 1.105 0.9712
SubOccipital Central - Occipital Right -1.3648 0.2974 59 -4.589 0.0008
SubOccipital Central - SubOccipital Right -1.4427 0.3229 59 -4.468 0.0011
SubOccipital Central - Inion Right -0.8650 0.2906 59 -2.977 0.0916
Inion Central - Occipital Right -1.4743 0.2849 59 -5.175 0.0001
Inion Central - SubOccipital Right -1.5522 0.2965 59 -5.235 0.0001
Inion Central - Inion Right -0.9745 0.2497 59 -3.903 0.0071
Occipital Right - SubOccipital Right -0.0779 0.1540 59 -0.506 0.9999
Occipital Right - Inion Right 0.4998 0.2230 59 2.241 0.3939
SubOccipital Right - Inion Right 0.5777 0.1676 59 3.446 0.0272
P value adjustment: tukey method for comparing a family of 9 estimates
options(width = 100)
ggplot(
na.omit(aat_data_peak), aes(x = amplitude, fill = component, color = component)) +
geom_histogram(alpha = .3, position = "identity") +
ggtitle("Oz peak voltages")`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
p <- ggscatterhist(
na.omit(aat_data_peak), x = "latency", y = "amplitude",
title = "Oz peak positions", legend = "bottom",# add = "reg.line",
color = "component", size = 2, alpha = .5, print = FALSE,
margin.params = list(fill = "component", color = "component", size = .5)
)
p$sp <- p$sp +
geom_hline(yintercept = 0, color = "darkgray")
p latency component amplitude chindex chlabel bini
Min. :138.7 N1:240 Min. :-24.9053 Min. :23 Oz:480 Min. :5.00
1st Qu.:168.0 P2:240 1st Qu.: -3.9044 1st Qu.:23 1st Qu.:5.75
Median :212.9 Median : 1.1885 Median :23 Median :6.50
Mean :211.6 Mean : 0.9324 Mean :23 Mean :6.50
3rd Qu.:252.0 3rd Qu.: 5.7478 3rd Qu.:23 3rd Qu.:7.25
Max. :283.2 Max. : 21.3475 Max. :23 Max. :8.00
NA's :5 NA's :5
stimulus cue valence
Approach_Attractive:120 Avoid :240 Attractive:240
Approach_Neutral :120 Approach:240 Neutral :240
Avoid_Attractive :120
Avoid_Neutral :120
ERPset id_code
S01_C1_circ_right_Ctrl_infinity_reference_and_personal_choice: 8 S01_C1_circ_right: 8
S02_C2_circ_left_Mind_infinity_reference_and_personal_choice : 8 S02_C2_circ_left : 8
S03_C1_rect_right_Ctrl_infinity_reference_and_personal_choice: 8 S03_C1_rect_right: 8
S04_C1_rect_left_Ctrl_infinity_reference_and_personal_choice : 8 S04_C1_rect_left : 8
S05_C1_circ_left_Ctrl_infinity_reference_and_personal_choice : 8 S05_C1_circ_left : 8
S06_C2_circ_left_Mind_infinity_reference_and_personal_choice : 8 S06_C2_circ_left : 8
(Other) :432 (Other) :432
figure side num_id group
circ:240 left :248 Min. : 1.00 Control :240
rect:240 right:232 1st Qu.:16.75 Mindfulness:240
Median :32.50
Mean :32.40
3rd Qu.:47.25
Max. :65.00
options(width = 100)
aat_n1_peak_rep_anova <-
aov_ez("num_id", "amplitude", subset(aat_data_peak, component == "N1"), within = c("cue", "valence"), between = c("group"))Contrasts set to contr.sum for the following variables: group
cell_means <- aat_n1_peak_rep_anova$data$long |>
group_by(group, valence, cue) |>
summarise(amplitude = mean(amplitude))`summarise()` has grouped output by 'group', 'valence'. You can override using the `.groups`
argument.
aat_n1_peak_afex_plot <-
afex_plot(
aat_n1_peak_rep_anova,
x = "valence",
trace = "cue",
panel = "group",
error = "between",
error_arg = list(width = .2, lwd = .75, col = 'gray30', alpha = .7),
dodge = my_dodge,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .2,
# jitter.height = .1,
dodge.width = my_dodge ## needs to be same as dodge
)),
mapping = c("color"), data_alpha = .3,
point_arg = list(size = 2)
)Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
table_data <- aat_n1_peak_rep_anova$data$long
xtabs(~ group , table_data) / length(unique(table_data$cue)) / length(unique(table_data$valence))group
Control Mindfulness
30 30
Anova Table (Type 3 tests)
Response: amplitude
Effect df MSE F ges p.value
1 group 1, 58 89.92 0.38 .006 .539
2 cue 1, 58 1.12 10.60 ** .002 .002
3 group:cue 1, 58 1.12 1.86 <.001 .178
4 valence 1, 58 1.03 31.94 *** .006 <.001
5 group:valence 1, 58 1.03 0.29 <.001 .590
6 cue:valence 1, 58 1.01 1.18 <.001 .282
7 group:cue:valence 1, 58 1.01 0.97 <.001 .330
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
suppressWarnings(print(aat_n1_peak_afex_plot +
geom_point(data = cell_means,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_dodge(my_dodge), size = 2.5) +
facet_grid(~group)
))____________________________________________________________________________________________________
$emmeans
cue emmean SE df lower.CL upper.CL
Avoid -4.06 0.618 58 -5.30 -2.83
Approach -4.51 0.614 58 -5.74 -3.28
Results are averaged over the levels of: group, valence
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Avoid - Approach 0.445 0.137 58 3.255 0.0019
Results are averaged over the levels of: group, valence
____________________________________________________________________________________________________
$emmeans
valence emmean SE df lower.CL upper.CL
Attractive -4.65 0.632 58 -5.92 -3.39
Neutral -3.91 0.598 58 -5.11 -2.72
Results are averaged over the levels of: group, cue
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Attractive - Neutral -0.74 0.131 58 -5.652 <.0001
Results are averaged over the levels of: group, cue
afex_plot(
aat_n1_peak_rep_anova,
x = "valence",
trace = "cue",
panel = "group",
error = "between",
data_geom = geom_violin,
error_arg = list(width = .2, lwd = .75, col = 'gray10', alpha = .8),
dodge = my_dodge,
line_arg = list(size = 0),
mapping = c("color")
) +
geom_point(data = aat_n1_peak_rep_anova$data$long,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_jitterdodge(jitter.width = 0.2, dodge.width = my_dodge),
alpha = .4) +
geom_point(data = cell_means,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_dodge(my_dodge), size = 2.5) +
facet_grid(~group)Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
options(width = 100)
aat_p2_peak_rep_anova <-
aov_ez("num_id", "amplitude", subset(aat_data_peak, component == "P2"), within = c("cue", "valence"), between = c("group"))Warning: Missing values for 2 ID(s), which were removed before analysis:
53, 61
Below the first few rows (in wide format) of the removed cases with missing data.
Contrasts set to contr.sum for the following variables: group
cell_means <- aat_p2_peak_rep_anova$data$long |>
group_by(group, valence, cue) |>
summarise(amplitude = mean(amplitude))`summarise()` has grouped output by 'group', 'valence'. You can override using the `.groups`
argument.
aat_p2_peak_afex_plot <-
afex_plot(
aat_p2_peak_rep_anova,
x = "valence",
trace = "cue",
panel = "group",
error = "between",
error_arg = list(width = .2, lwd = .75, col = 'gray30', alpha = .7),
dodge = my_dodge,
data_arg = list(
position =
position_jitterdodge(
jitter.width = .2,
# jitter.height = .1,
dodge.width = my_dodge ## needs to be same as dodge
)),
mapping = c("color"), data_alpha = .3,
# line_arg = list(size = 0),
point_arg = list(size = 2)
)Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
table_data <- aat_p2_peak_rep_anova$data$long
xtabs(~ group , table_data) / length(unique(table_data$cue)) / length(unique(table_data$valence))group
Control Mindfulness
29 29
Anova Table (Type 3 tests)
Response: amplitude
Effect df MSE F ges p.value
1 group 1, 56 65.09 0.02 <.001 .878
2 cue 1, 56 1.46 9.40 ** .004 .003
3 group:cue 1, 56 1.46 0.00 <.001 .998
4 valence 1, 56 0.94 3.55 + <.001 .065
5 group:valence 1, 56 0.94 0.15 <.001 .702
6 cue:valence 1, 56 1.02 4.99 * .001 .029
7 group:cue:valence 1, 56 1.02 0.92 <.001 .343
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
suppressWarnings(print(aat_p2_peak_afex_plot +
geom_point(data = cell_means,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_dodge(my_dodge), size = 2.5) +
facet_grid(~group)
))____________________________________________________________________________________________________
$emmeans
cue emmean SE df lower.CL upper.CL
Avoid 6.53 0.552 56 5.43 7.64
Approach 6.04 0.519 56 5.00 7.08
Results are averaged over the levels of: group, valence
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Avoid - Approach 0.487 0.159 56 3.066 0.0033
Results are averaged over the levels of: group, valence
____________________________________________________________________________________________________
$emmeans
cue valence emmean SE df lower.CL upper.CL
Avoid Attractive 6.50 0.519 56 5.46 7.54
Approach Attractive 6.31 0.533 56 5.24 7.38
Avoid Neutral 6.56 0.600 56 5.36 7.76
Approach Neutral 5.78 0.517 56 4.74 6.81
Results are averaged over the levels of: group
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Avoid Attractive - Approach Attractive 0.1902 0.187 56 1.016 0.7411
Avoid Attractive - Avoid Neutral -0.0573 0.204 56 -0.281 0.9922
Avoid Attractive - Approach Neutral 0.7266 0.203 56 3.575 0.0040
Approach Attractive - Avoid Neutral -0.2475 0.204 56 -1.215 0.6200
Approach Attractive - Approach Neutral 0.5364 0.161 56 3.328 0.0082
Avoid Neutral - Approach Neutral 0.7839 0.225 56 3.481 0.0052
Results are averaged over the levels of: group
P value adjustment: tukey method for comparing a family of 4 estimates
afex_plot(
aat_p2_peak_rep_anova,
x = "valence",
trace = "cue",
panel = "group",
error = "between",
data_geom = geom_violin,
error_arg = list(width = .2, lwd = .75, col = 'gray10', alpha = .8),
dodge = my_dodge,
line_arg = list(size = 0),
mapping = c("color")
) +
geom_point(data = aat_p2_peak_rep_anova$data$long,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_jitterdodge(jitter.width = 0.2, dodge.width = my_dodge),
alpha = .4) +
geom_point(data = cell_means,
aes(x = valence, y = amplitude, group = cue, color = cue),
position = position_dodge(my_dodge), size = 2.5) +
facet_grid(~group)Warning: Panel(s) show within-subjects factors, but not within-subjects error bars.
For within-subjects error bars use: error = "within"
No significant group effect or interactions found with FMUT Fclust, Fmax, nor Ffdr
No significant group effect or interactions found with FMUT Fclust, Fmax, nor Ffdr