knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(rstatix)
library(lsr)
library(ggpubr)
library(flextable)
library(emmeans)
grad_double_low <- read_csv("data/grad_data_double_5_10Hz_300_1000ms.csv")
grad_nostim_low <- read_csv("data/grad_data_nostim_5_10Hz_300_1000ms.csv")
grad_double_high <- read_csv("data/grad_data_double_10_15Hz_300_1000ms.csv")
grad_nostim_high <- read_csv("data/grad_data_nostim_10_15Hz_300_1000ms.csv")
#Combining low alpha from parietal contralaterally and high alpha occipital ipsilaterally
#Double
GD_parietal_low <- grad_double_low |>
mutate(
Left_Hem_ROI_Right_Attention_stim_Double = (`Left-parietal_ROI_right_attention`-`Left-parietal_ROI_no_attention`)/(`Left-parietal_ROI_right_attention`+`Left-parietal_ROI_no_attention`),
Right_Hem_ROI_Left_Attention_stim_Double = (`Right-parietal_ROI_left_attention`-`Right-parietal_ROI_no_attention`)/(`Right-parietal_ROI_left_attention`+`Right-parietal_ROI_no_attention`)) |>
select(1,
"Left_Hem_ROI_Right_Attention_stim_Double",
"Right_Hem_ROI_Left_Attention_stim_Double",)
GD_occipital_high <- grad_double_high |>
mutate(
Left_Hem_ROI_Left_Attention_stim_Double =
(`Left-occipital_ROI_left_attention` - `Left-occipital_ROI_no_attention`)/(`Left-occipital_ROI_left_attention`+`Left-occipital_ROI_no_attention`),
Right_Hem_ROI_Right_Attention_stim_Double = (`Right-occipital_ROI_right_attention`-`Right-occipital_ROI_no_attention`)/(`Right-occipital_ROI_right_attention`+`Right-occipital_ROI_no_attention`)) |>
select(1,
"Left_Hem_ROI_Left_Attention_stim_Double",
"Right_Hem_ROI_Right_Attention_stim_Double",)
all_double <-
full_join(GD_parietal_low, GD_occipital_high, by = "...1")
#NoStim
GN_parietal_low <- grad_nostim_low |>
mutate(
Left_Hem_ROI_Right_Attention_stim_NoStim = (`Left-parietal_ROI_right_attention`-`Left-parietal_ROI_no_attention`)/(`Left-parietal_ROI_right_attention`+`Left-parietal_ROI_no_attention`),
Right_Hem_ROI_Left_Attention_stim_NoStim = (`Right-parietal_ROI_left_attention`-`Right-parietal_ROI_no_attention`)/(`Right-parietal_ROI_left_attention`+`Right-parietal_ROI_no_attention`)) |>
select(1,
"Left_Hem_ROI_Right_Attention_stim_NoStim",
"Right_Hem_ROI_Left_Attention_stim_NoStim",)
GN_occipital_high <- grad_nostim_high |>
mutate(
Left_Hem_ROI_Left_Attention_stim_NoStim =
(`Left-occipital_ROI_left_attention` - `Left-occipital_ROI_no_attention`)/(`Left-occipital_ROI_left_attention`+`Left-occipital_ROI_no_attention`),
Right_Hem_ROI_Right_Attention_stim_NoStim = (`Right-occipital_ROI_right_attention`-`Right-occipital_ROI_no_attention`)/(`Right-occipital_ROI_right_attention`+`Right-occipital_ROI_no_attention`)) |>
select(1,
"Left_Hem_ROI_Left_Attention_stim_NoStim",
"Right_Hem_ROI_Right_Attention_stim_NoStim",)
all_nostim <-
full_join(GN_parietal_low, GN_occipital_high, by = "...1")
all_stim <- full_join(all_double, all_nostim, by = "...1")
grad_all <- pivot_longer(all_stim,
cols = c(2:9),
names_to = c("hemisphere", "attention", "stimulus"),
names_pattern = "(.*)_ROI_(.*)_stim_(.*)",
values_to = "alpha")
grad_all|>
group_by(hemisphere, attention, stimulus) |>
get_summary_stats(alpha, type = "mean_sd") |>
flextable(cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(hemisphere = "Hemisphere",
attention = "Attention",
stimulus = "Stimulus",
variable = "Variable")
Hemisphere | Attention | Stimulus | Variable | n | mean | sd |
|---|---|---|---|---|---|---|
Left_Hem | Left_Attention | Double | alpha | 30 | 0.001 | 0.069 |
Left_Hem | Left_Attention | NoStim | alpha | 30 | -0.006 | 0.093 |
Left_Hem | Right_Attention | Double | alpha | 30 | -0.072 | 0.059 |
Left_Hem | Right_Attention | NoStim | alpha | 30 | -0.072 | 0.064 |
Right_Hem | Left_Attention | Double | alpha | 30 | -0.065 | 0.051 |
Right_Hem | Left_Attention | NoStim | alpha | 30 | -0.068 | 0.066 |
Right_Hem | Right_Attention | Double | alpha | 30 | -0.006 | 0.085 |
Right_Hem | Right_Attention | NoStim | alpha | 30 | -0.007 | 0.105 |
grad_all|>
group_by(hemisphere, attention, stimulus) |>
identify_outliers(alpha) |>
flextable(cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(hemisphere = "Hemisphere",
attention = "Attention",
stimulus = "Stimulus",
...1 = "ID",
alpha = "Alpha")
Hemisphere | Attention | Stimulus | ID | Alpha | is.outlier | is.extreme |
|---|---|---|---|---|---|---|
Left_Hem | Left_Attention | NoStim | S024_hyr24 | -0.2210934 | TRUE | FALSE |
Right_Hem | Left_Attention | NoStim | S024_hyr24 | -0.2588716 | TRUE | FALSE |
Right_Hem | Right_Attention | Double | S022_dss19 | 0.2400229 | TRUE | FALSE |
Right_Hem | Right_Attention | NoStim | S004_gto28 | 0.2095850 | TRUE | FALSE |
Right_Hem | Right_Attention | NoStim | S017_mwa29 | 0.2049399 | TRUE | FALSE |
Right_Hem | Right_Attention | NoStim | S024_hyr24 | -0.2527005 | TRUE | FALSE |
#Residual QQ
qq_p <- lm(alpha ~ hemisphere*attention*stimulus, data=grad_all)
ggqqplot(residuals(qq_p))
grad_all|>
group_by(hemisphere, attention, stimulus) |>
shapiro_test(alpha) |> #must be P >.05
flextable(cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(hemisphere = "Hemisphere",
attention = "Attention",
stimulus = "Stimulus",
variable = "Variable",
statistic = "Statistics")
Hemisphere | Attention | Stimulus | Variable | Statistics | p |
|---|---|---|---|---|---|
Left_Hem | Left_Attention | Double | alpha | 0.9761995 | 0.71803433 |
Left_Hem | Left_Attention | NoStim | alpha | 0.9583361 | 0.28070059 |
Left_Hem | Right_Attention | Double | alpha | 0.9765978 | 0.72969973 |
Left_Hem | Right_Attention | NoStim | alpha | 0.9507170 | 0.17669895 |
Right_Hem | Left_Attention | Double | alpha | 0.9090876 | 0.01411348 |
Right_Hem | Left_Attention | NoStim | alpha | 0.9482171 | 0.15142683 |
Right_Hem | Right_Attention | Double | alpha | 0.9571587 | 0.26161226 |
Right_Hem | Right_Attention | NoStim | alpha | 0.9669517 | 0.45948140 |
anova_test(grad_all,
dv = alpha,
wid = ...1,
within = c(hemisphere, attention, stimulus),
effect.size = "pes") |>
flextable(cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(pes = "Effect Size (ƞ2p)")
Effect | DFn | DFd | F | p | p<.05 | Effect Size (ƞ2p) |
|---|---|---|---|---|---|---|
hemisphere | 1 | 29 | 0.083 | 0.7760000 | 0.003 | |
attention | 1 | 29 | 0.988 | 0.3280000 | 0.033 | |
stimulus | 1 | 29 | 0.152 | 0.6990000 | 0.005 | |
hemisphere:attention | 1 | 29 | 25.158 | 0.0000243 | * | 0.465 |
hemisphere:stimulus | 1 | 29 | 0.105 | 0.7480000 | 0.004 | |
attention:stimulus | 1 | 29 | 0.504 | 0.4840000 | 0.017 | |
hemisphere:attention:stimulus | 1 | 29 | 0.062 | 0.8060000 | 0.002 |
#.01: Small effect size
#.06: Medium effect size
#.14 or higher: Large effect size
#Tidy Data
G_all <- all_stim |>
mutate(
Left_Hem_ROI_Left_Attention =
((`Left_Hem_ROI_Left_Attention_stim_Double` + `Left_Hem_ROI_Left_Attention_stim_NoStim`)/2),
Left_Hem_ROI_Right_Attention =
((`Left_Hem_ROI_Right_Attention_stim_Double` + `Left_Hem_ROI_Right_Attention_stim_NoStim`)/2),
Right_Hem_ROI_Left_Attention =
((`Right_Hem_ROI_Left_Attention_stim_Double` + `Right_Hem_ROI_Left_Attention_stim_NoStim`)/2),
Right_Hem_ROI_Right_Attention =
((`Right_Hem_ROI_Right_Attention_stim_Double` + `Right_Hem_ROI_Right_Attention_stim_NoStim`)/2)) |>
select(1,
"Left_Hem_ROI_Left_Attention",
"Left_Hem_ROI_Right_Attention",
"Right_Hem_ROI_Left_Attention",
"Right_Hem_ROI_Right_Attention")
t1 <- t.test(G_all$"Left_Hem_ROI_Left_Attention",
mu = 0,
alternative = "greater")
t1_mean <- mean(G_all$Left_Hem_ROI_Left_Attention)
t1_sd <- sd(G_all$Left_Hem_ROI_Left_Attention)
t1_es <- cohensD(G_all$Left_Hem_ROI_Left_Attention, mu = 0)
t2 <- t.test(G_all$"Left_Hem_ROI_Right_Attention",
mu = 0,
alternative = "less")
t2_mean <- mean(G_all$Left_Hem_ROI_Right_Attention)
t2_sd <- sd(G_all$Left_Hem_ROI_Right_Attention)
t2_es <- cohensD(G_all$Left_Hem_ROI_Right_Attention, mu = 0)
t3 <- t.test(G_all$"Right_Hem_ROI_Left_Attention",
mu = 0,
alternative = "less")
t3_mean <- mean(G_all$Right_Hem_ROI_Left_Attention)
t3_sd <- sd(G_all$Right_Hem_ROI_Left_Attention)
t3_es <- cohensD(G_all$Right_Hem_ROI_Left_Attention, mu = 0)
t4 <- t.test(G_all$"Right_Hem_ROI_Right_Attention",
mu = 0,
alternative = "greater")
t4_mean <- mean(G_all$Right_Hem_ROI_Right_Attention)
t4_sd <- sd(G_all$Right_Hem_ROI_Right_Attention)
t4_es <- cohensD(G_all$Right_Hem_ROI_Right_Attention, mu = 0)
t_table <- map_df(list(t1, t2, t3, t4), tidy)
mutate(t_table,
"t-test Comparison" = c("Left Hemisphere - Left Attention",
"Left Hemisphere - Right Attention",
"Right Hemisphere - Left Attention",
"Right Hemisphere - Right Attention"),
"Standard Deviation" = c(t1_sd,
t2_sd,
t3_sd,
t4_sd),
"Effect Size (d)" = c(t1_es,
t2_es,
t3_es,
t4_es))|>
subset(select=c(9, 1, 10, 2, 3, 4, 5, 6, 7, 8, 11)) |>
flextable (cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(estimate = "Estimate",
statistic = "Statistic",
p.value = "P Value",
parameter = "Parameter")
t-test Comparison | Estimate | Standard Deviation | Statistic | P Value | Parameter | conf.low | conf.high | method | alternative | Effect Size (d) |
|---|---|---|---|---|---|---|---|---|---|---|
Left Hemisphere - Left Attention | -0.002755901 | 0.07674234 | -0.1966931 | 0.57728015610086 | 29 | -0.02656266 | Inf | One Sample t-test | greater | 0.03591108 |
Left Hemisphere - Right Attention | -0.072312987 | 0.05773429 | -6.8602993 | 0.00000007756142 | 29 | -Inf | -0.05440284 | One Sample t-test | less | 1.25251356 |
Right Hemisphere - Left Attention | -0.066102967 | 0.05575788 | -6.4934476 | 0.00000020766493 | 29 | -Inf | -0.04880594 | One Sample t-test | less | 1.18553590 |
Right Hemisphere - Right Attention | -0.006150891 | 0.09069829 | -0.3714493 | 0.64349848517282 | 29 | -0.03428702 | Inf | One Sample t-test | greater | 0.06781706 |
# any significance towards stimulus? (is hemisphere:attention significant in both D/N)
PH_1_parietal <- grad_all |>
group_by(stimulus) |>
anova_test(dv = alpha,
wid = ...1,
within = c(hemisphere, attention),
effect.size = "pes")
flextable(PH_1_parietal,
cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(stimulus = "Stimulus",
pes = "Effect Size (ƞ2p)")
Stimulus | Effect | DFn | DFd | F | p | p<.05 | Effect Size (ƞ2p) |
|---|---|---|---|---|---|---|---|
Double | hemisphere | 1 | 29 | 0.021 | 0.8850000 | 0.000734 | |
Double | attention | 1 | 29 | 2.048 | 0.1630000 | 0.066000 | |
Double | hemisphere:attention | 1 | 29 | 26.600 | 0.0000164 | * | 0.478000 |
NoStim | hemisphere | 1 | 29 | 0.148 | 0.7030000 | 0.005000 | |
NoStim | attention | 1 | 29 | 0.163 | 0.6890000 | 0.006000 | |
NoStim | hemisphere:attention | 1 | 29 | 19.019 | 0.0001490 | * | 0.396000 |
#effect of 2 levels of attention
PH_2_parietal <- grad_all |>
group_by(stimulus, hemisphere) |>
anova_test(dv = alpha,
wid = ...1,
within = attention,
effect.size = "pes")
flextable(PH_2_parietal,
cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(hemisphere = "Hemisphere",
stimulus = "Stimulus",
pes = "Effect Size (ƞ2p)")
Hemisphere | Stimulus | Effect | DFn | DFd | F | p | p<.05 | Effect Size (ƞ2p) |
|---|---|---|---|---|---|---|---|---|
Left_Hem | Double | attention | 1 | 29 | 28.427 | 0.0000101 | * | 0.495 |
Right_Hem | Double | attention | 1 | 29 | 18.522 | 0.0001740 | * | 0.390 |
Left_Hem | NoStim | attention | 1 | 29 | 19.825 | 0.0001160 | * | 0.406 |
Right_Hem | NoStim | attention | 1 | 29 | 12.919 | 0.0010000 | * | 0.308 |
#effect of 2 levels of hemisphere
PH_3_parietal <- grad_all |>
group_by(stimulus, attention) |>
anova_test(dv = alpha,
wid = ...1,
within = hemisphere,
effect.size = "pes")
flextable(PH_3_parietal,
cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(attention = "Attention",
stimulus = "Stimulus",
pes = "Effect Size (ƞ2p)")
Attention | Stimulus | Effect | DFn | DFd | F | p | p<.05 | Effect Size (ƞ2p) |
|---|---|---|---|---|---|---|---|---|
Left_Attention | Double | hemisphere | 1 | 29 | 25.996 | 0.0000193 | * | 0.473 |
Right_Attention | Double | hemisphere | 1 | 29 | 20.374 | 0.0000977 | * | 0.413 |
Left_Attention | NoStim | hemisphere | 1 | 29 | 18.766 | 0.0001610 | * | 0.393 |
Right_Attention | NoStim | hemisphere | 1 | 29 | 15.376 | 0.0004950 | * | 0.346 |
#effect of 2 levels of stimulud
PH_4_parietal <- grad_all |>
group_by(attention, hemisphere) |>
anova_test(dv = alpha,
wid = ...1,
within = stimulus,
effect.size = "pes")
flextable(PH_4_parietal,
cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(hemisphere = "Hemisphere",
attention = "Attention",
pes = "Effect Size (ƞ2p)")
Hemisphere | Attention | Effect | DFn | DFd | F | p | p<.05 | Effect Size (ƞ2p) |
|---|---|---|---|---|---|---|---|---|
Left_Hem | Left_Attention | stimulus | 1 | 29 | 0.38700000 | 0.539 | 0.0130000000 | |
Right_Hem | Left_Attention | stimulus | 1 | 29 | 0.20300000 | 0.656 | 0.0070000000 | |
Left_Hem | Right_Attention | stimulus | 1 | 29 | 0.00000265 | 0.999 | 0.0000000912 | |
Right_Hem | Right_Attention | stimulus | 1 | 29 | 0.00900000 | 0.926 | 0.0003030000 |
# Pairwise comparisons
pw_comp_1 <- grad_all |>
group_by(stimulus, hemisphere) |>
pairwise_t_test(alpha ~ attention,
paired = TRUE,
p.adjust.method = "bonferroni")
flextable(pw_comp_1,
cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(hemisphere = "Hemisphere",
stimulus = "Stimulus",
.y. = "Variable")
Hemisphere | Stimulus | Variable | group1 | group2 | n1 | n2 | statistic | df | p | p.adj | p.adj.signif |
|---|---|---|---|---|---|---|---|---|---|---|---|
Left_Hem | Double | alpha | Left_Attention | Right_Attention | 30 | 30 | 5.331730 | 29 | 0.0000101 | 0.0000101 | **** |
Right_Hem | Double | alpha | Left_Attention | Right_Attention | 30 | 30 | -4.303664 | 29 | 0.0001740 | 0.0001740 | *** |
Left_Hem | NoStim | alpha | Left_Attention | Right_Attention | 30 | 30 | 4.452538 | 29 | 0.0001160 | 0.0001160 | *** |
Right_Hem | NoStim | alpha | Left_Attention | Right_Attention | 30 | 30 | -3.594271 | 29 | 0.0010000 | 0.0010000 | ** |
# Pairwise comparisons
pw_comp_2 <- grad_all |>
group_by(stimulus, attention) |>
pairwise_t_test(alpha ~ hemisphere,
paired = TRUE,
p.adjust.method = "bonferroni")
flextable(pw_comp_2,
cwidth = .95) |>
fontsize(size = 8) |>
fontsize(size = 10, part = "header") |>
set_header_labels(attention = "Attention",
stimulus = "Stimulus",
.y. = "Variable")
Attention | Stimulus | Variable | group1 | group2 | n1 | n2 | statistic | df | p | p.adj | p.adj.signif |
|---|---|---|---|---|---|---|---|---|---|---|---|
Left_Attention | Double | alpha | Left_Hem | Right_Hem | 30 | 30 | 5.098582 | 29 | 0.0000193 | 0.0000193 | **** |
Right_Attention | Double | alpha | Left_Hem | Right_Hem | 30 | 30 | -4.513766 | 29 | 0.0000977 | 0.0000977 | **** |
Left_Attention | NoStim | alpha | Left_Hem | Right_Hem | 30 | 30 | 4.332018 | 29 | 0.0001610 | 0.0001610 | *** |
Right_Attention | NoStim | alpha | Left_Hem | Right_Hem | 30 | 30 | -3.921162 | 29 | 0.0004950 | 0.0004950 | *** |