Functional connectivity
Mean correlation maps
library(abind)
# List to store all 2D matrices
matrices <- list()
# Loop through all .tsv files in the folder
files <- list.files(path = "conmats_filtered_aroma/", pattern = "*.tsv",full.names = TRUE)
for (file in files) {
mat <- read.table(file, sep = "\t", header = FALSE)
matrices[[file]] <- mat
}
# Combine all matrices into a single 3D matrix
result_matrix <- abind(matrices, along = 3)
dim(result_matrix)
## [1] 410 410 54
results_brain_labs <- brainregions$X2
# List to store all 2D matrices
interferon_matrices <- list()
# Loop through all .tsv files in the folder
files <- list.files(path = "conmats_filtered_aroma/", pattern = "ses-I",full.names = TRUE)
for (file in files) {
mat <- read.table(file, sep = "\t", header = FALSE)
interferon_matrices[[file]] <- mat
}
# Combine all matrices into a single 3D matrix
result_interferon_matrix <- abind(interferon_matrices, along = 3)
# List to store all 2D matrices
placebo_matrices <- list()
# Loop through all .tsv files in the folder
files <- list.files(path = "conmats_filtered_aroma/", pattern = "ses-P",full.names = TRUE)
for (file in files) {
mat <- read.table(file, sep = "\t", header = FALSE)
placebo_matrices[[file]] <- mat
}
# Combine all matrices into a single 3D matrix
result_placebo_matrix <- abind(placebo_matrices, along = 3)
# nnodes <- length(brainregions$X2)
# tri_pos <- which(upper.tri(matrix(nrow = nnodes, ncol = nnodes)), arr.ind = T)
# Load the R.matlab package
library(R.matlab)
# Specify the file path and name
file <- "C:\\Users\\saptaf1\\Downloads\\archives\\NBS_benchmarking-master\\interferon_files\\aroma_funccon_54.mat"
# Write the 3D matrix to the .mat file
writeMat(funccon=atanh(result_matrix), file)
file <- "C:\\Users\\saptaf1\\Downloads\\archives\\NBS_benchmarking-master\\interferon_files\\yeo_410.mat"
writeMat(yeo410=adjacency_matrix, file)
n_missing <- sum(is.na(result_placebo_matrix))
mean_placebo_funcconn <- apply(result_placebo_matrix, c(1, 2), function(x) mean(x, na.rm = TRUE))
diag(mean_placebo_funcconn) <- 0
z_mean_placebo_funcconn <- atanh(mean_placebo_funcconn)
z_mean_placebo_funcconn[z_mean_placebo_funcconn == 0] <- .Machine$double.xmin
# problems with 1121023_ses-I,0821008_ses-I,1121022_ses-I
n_missing <- sum(is.na(result_interferon_matrix))
n_missing <- apply(result_interferon_matrix, c(3), function(x) sum(is.na(x)))
print(n_missing)
## conmats_filtered_aroma/sub-0122025_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0122026_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0122027_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0222028_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0222029_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0322030_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0322031_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0322032_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0421002_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0422033_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0422034_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0422035_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0521003_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0522036_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0721005_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0821006_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0821007_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0921009_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0921010_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0921012_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0921014_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0921015_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0921016_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-0921017_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-1021019_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-1121020_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
## conmats_filtered_aroma/sub-1121021_ses-I_task-rest_space-MNI152NLin2009cAsym_atlas-Combined_measure-pearsoncorrelation_conmat.tsv
## 0
mean_interferon_funcconn <- apply(result_interferon_matrix, c(1, 2), function(x) mean(x, na.rm = TRUE))
diag(mean_interferon_funcconn) <- 0
z_mean_interferon_funcconn <- atanh(mean_interferon_funcconn)
z_mean_interferon_funcconn[z_mean_interferon_funcconn == 0] <- .Machine$double.xmin
mean_diff_funcconn <- apply(result_placebo_matrix-result_interferon_matrix, c(1, 2), mean)
diag(mean_diff_funcconn) <- 0
#z_mean_diff_funcconn <- atanh(mean_diff_funcconn)
z_mean_diff_funcconn <- z_mean_placebo_funcconn-z_mean_interferon_funcconn
h1 <- Heatmap(z_mean_placebo_funcconn, name = "Fisher Z", row_split = network.combined$name, column_split = network.combined$name, row_title_rot = 0, show_column_dend = FALSE, show_row_dend = FALSE, show_column_names = FALSE, column_title = "Placebo", column_title_gp = gpar(fontsize = 20, fontface = "bold"), clustering_distance_rows="pearson", clustering_distance_columns ="pearson")
h2 <- Heatmap(z_mean_interferon_funcconn, name = "Fisher Z", row_split= factor(network.combined$name, levels = (names(row_order(h1)))), column_split= factor(network.combined$name, levels = (names(row_order(h1)))), row_title_rot = 0, show_column_dend = FALSE, show_row_dend = FALSE, show_column_names = FALSE, column_title = "Interferon", column_title_gp = gpar(fontsize = 20, fontface = "bold"), cluster_rows = FALSE, cluster_columns = FALSE, cluster_row_slices = FALSE, cluster_column_slices = FALSE, row_order = unlist(row_order(h1)), column_order = unlist(row_order(h1)) )
h3_v2 <- Heatmap(z_mean_diff_funcconn, name = "Fisher Z", row_split= factor(network.combined$name, levels = (names(row_order(h1)))), column_split= factor(network.combined$name, levels = (names(row_order(h1)))), row_title_rot = 0, show_column_dend = FALSE, show_row_dend = FALSE, show_column_names = FALSE, column_title = "Placebo-Interferon", column_title_gp = gpar(fontsize = 20, fontface = "bold"), cluster_rows = FALSE, cluster_columns = FALSE, cluster_row_slices = FALSE, cluster_column_slices = FALSE, row_order = unlist(row_order(h1)), column_order = unlist(row_order(h1)))
h3_v2_adjusted <- Heatmap(z_mean_diff_funcconn, name = "Fisher Z", row_split= factor(network.combined$name, levels = (names(row_order(h1)))), column_split= factor(network.combined$name, levels = (names(row_order(h1)))), row_title_rot = 0, show_column_dend = FALSE, show_row_dend = FALSE, show_column_names = FALSE, column_title = "Placebo-Interferon", column_title_gp = gpar(fontsize = 20, fontface = "bold"), cluster_rows = FALSE, cluster_columns = FALSE, cluster_row_slices = FALSE, cluster_column_slices = FALSE, row_order = unlist(row_order(h1)), column_order = unlist(row_order(h1)), col=colorRamp2(c(-1, 0, 1), c("blue", "white", "red")))
h1+h2+h3_v2_adjusted

h1+h2

h3_v2

hist(z_mean_diff_funcconn[upper.tri(z_mean_diff_funcconn, diag = FALSE)], main = "Histogram of functional connectivity difference values")

g1 <- graph.adjacency(z_mean_placebo_funcconn,weighted=TRUE,mode = "upper", diag = FALSE)
g2 <- graph.adjacency(z_mean_interferon_funcconn,weighted=TRUE,mode = "upper", diag = FALSE)
df <- bind_rows(get.data.frame(g1) %>% mutate(condition="Placebo"), get.data.frame(g2) %>% mutate(condition="Interferon"))
ggplot(df, aes(x=weight, fill=condition)) +
geom_density(alpha=.25)

df %>% mutate(from = gsub("V", "ROI_", from), to = gsub("V", "ROI_", to)) %>% rowwise() %>% mutate(from_network = ifelse(is.na(match(from, network.combined$ROI)), from, network.combined$name[match(from, network.combined$ROI)]), to_network = ifelse(is.na(match(to, network.combined$ROI)), to, network.combined$name[match(to, network.combined$ROI)]), from2to = paste0(sort(c(from_network,to_network))[1],"2",sort(c(from_network,to_network))[2])) -> df_ext
ggplot(df_ext, aes(x=weight, fill=condition)) +
geom_density(alpha=.25) + facet_wrap(~from2to)

df_ext %>% mutate(fromNum=parse_number(from), toNum = parse_number(to)) -> df_ext
df_ext$from2toIndex <- as.integer(factor(df_ext$from2to))
nodes <- unique(c(df_ext$fromNum, df_ext$toNum))
adjacency_matrix <- matrix(0, nrow = length(nodes), ncol = length(nodes))
colnames(adjacency_matrix) <- rownames(adjacency_matrix) <- nodes
adjacency_matrix[cbind(match(df_ext$fromNum, nodes), match(df_ext$toNum, nodes))] <- df_ext$from2toIndex
write.csv(adjacency_matrix, file = "yeo_edge_group.csv", row.names = FALSE)
Wilcoxon
tmp = data.frame()
# run np test within-subject differences in edges
for (i in seq(1,dim(result_placebo_matrix)[3])) {
# print(i)
A <- atanh(result_placebo_matrix[,,i])
A[A == 0] <- .Machine$double.xmin
B <- atanh(result_interferon_matrix[,,i])
B[B == 0] <- .Machine$double.xmin
g1 <- graph.adjacency(A, weighted=TRUE, mode = "upper", diag = FALSE)
g2 <- graph.adjacency(B, weighted=TRUE, mode = "upper", diag = FALSE)
if (nrow(get.data.frame(g1)) != nrow(get.data.frame(g2))) {
break
}
df <- bind_rows(get.data.frame(g1) %>% mutate(condition="Placebo"), get.data.frame(g2) %>% mutate(condition="Interferon")) %>% mutate(sub = i)
tmp = bind_rows(tmp,df)
}
# Perform Wilcoxon signed-rank test
knitr::kable(tmp %>% wilcox_test(weight ~ condition, paired = TRUE, detailed = TRUE, exact=TRUE))
| 0.0035356 |
weight |
Interferon |
Placebo |
2263815 |
2263815 |
1.292945e+12 |
0 |
0.0029513 |
0.0041176 |
Wilcoxon |
two.sided |
# Perform Wilcoxon signed-rank test
print(wilcox.test(tmp %>% filter(condition=="Placebo")%>%.$weight, tmp %>% filter(condition=="Interferon")%>%.$weight, paired = TRUE))
##
## Wilcoxon signed rank test with continuity correction
##
## data: tmp %>% filter(condition == "Placebo") %>% .$weight and tmp %>% filter(condition == "Interferon") %>% .$weight
## V = 1.2694e+12, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
rm(tmp)
List of most Interferon affected connections in graph
Where is the most condition related change happening?
library(igraph)
g_diff_pMinusI <- graph.adjacency(z_mean_diff_funcconn,weighted=TRUE,mode = "upper", diag = FALSE)
df_diff_pMinusI <- get.data.frame(g_diff_pMinusI) %>% mutate(from = gsub("V", "ROI_", from), to = gsub("V", "ROI_", to)) %>% rowwise() %>% mutate(from_network = ifelse(is.na(match(from, network.combined$ROI)), from, network.combined$name[match(from, network.combined$ROI)]), to_network = ifelse(is.na(match(to, network.combined$ROI)), to, network.combined$name[match(to, network.combined$ROI)]), from2to = paste0(sort(c(from_network,to_network))[1],"2",sort(c(from_network,to_network))[2])) %>% mutate(from_roi = ifelse(is.na(match(from, brainregions$ROI_X)), from, brainregions$X2[match(from, brainregions$ROI_X)]), to_roi = ifelse(is.na(match(to, brainregions$ROI_X)), from, brainregions$X2[match(to, brainregions$ROI_X)]), abs_weight = abs(weight))
df_diff_pMinusI$abs_weight_decile <- ntile(df_diff_pMinusI$abs_weight, 10)
DT::datatable(df_diff_pMinusI %>% filter(abs_weight_decile >= 10))
# top 20% of affected edges
df_diff_pMinusI %>% filter(abs_weight_decile >= 9) %>% ggplot(., aes(abs_weight, fill = from2to)) +
geom_histogram(binwidth = 0.07)

df_diff_pMinusI %>% filter(abs_weight_decile >= 9) %>% ggplot(., aes(from2to)) +
geom_bar() + coord_flip()

# top 10% of affected edges
df_diff_pMinusI %>% filter(abs_weight_decile >= 10) %>% ggplot(., aes(abs_weight, fill = from2to)) +
geom_histogram(binwidth = 0.1)

df_diff_pMinusI %>% filter(abs_weight_decile >= 10) %>% ggplot(., aes(from2to)) +
geom_bar() + coord_flip()

library(igraph)
df_list <- list()
for (i in 1:dim(result_matrix)[3]) {
#print(i)
g <- graph.adjacency(result_matrix[,,i],weighted=TRUE,mode = "upper", diag = FALSE)
df_list[[i]] <- get.data.frame(g) %>% mutate(fileIndex=i)
}
data.funccon <- bind_rows(df_list) %>% left_join(.,variables_ext)
Grouped by scale, condition, subject
Unthresholded
data.funccon %>% mutate(weight = atanh(weight)) %>% group_by(Subj_ID,condition) %>% summarise(meanFuncCon = mean(weight)) -> data.aggr
anova_summary <- nice(aov_ez("Subj_ID", "meanFuncCon", data.aggr, within ="condition"))
knitr::kable(anova_summary)
| condition |
1, 26 |
0.00 |
0.63 |
.007 |
.436 |
ggwithinstats(
data = data.aggr,
x = condition,
y = meanFuncCon,
type = "np",
bf.message = FALSE)

Only positive weight > 0
data.funccon %>% mutate(weight = atanh(weight)) %>% group_by(Subj_ID,condition) %>% filter(weight>0) %>% summarise(meanFuncCon = mean(weight))-> data.aggr
anova_summary <- nice(aov_ez("Subj_ID", "meanFuncCon", data.aggr, within ="condition"))
knitr::kable(anova_summary)
| condition |
1, 26 |
0.00 |
11.85 ** |
.078 |
.002 |
ggwithinstats(
data = data.aggr,
x = condition,
y = meanFuncCon,
type = "np",
bf.message = FALSE)

Proportional thresholding based on on weight (not abs_weight)
# total edges per session: EDGES
plots_list <- list()
x <- c(0.1,0.15,0.2,0.25,0.3,0.35)
for (i in 1:6) {
p <- ggwithinstats(
data = data.funccon %>% mutate(weight = atanh(weight), abs_weight = abs(weight)) %>% group_by(Subj_ID,condition) %>% top_n(round(EDGES*x[i]),weight) %>% dplyr::summarise(meanFuncCon = mean(weight)),
x = condition,
y = meanFuncCon,
type = "np",
title =x[i] ,
bf.message = FALSE)
plots_list[[i]] <- p
}
# arrange the plots in a grid using grid.arrange from gridExtra
gridExtra::grid.arrange(grobs = plots_list)

Grouped by scale, condition, subject and age_cat
data.funccon %>% mutate(weight = atanh(weight)) %>% group_by(Subj_ID,condition,Age_cat) %>% summarise(meanFuncCon = mean(weight)) -> data.aggr
anova_summary <- nice(aov_ez("Subj_ID", "meanFuncCon", data.aggr, within ="condition", between="Age_cat"))
knitr::kable(anova_summary)
| Age_cat |
1, 25 |
0.00 |
0.66 |
.018 |
.425 |
| condition |
1, 25 |
0.00 |
0.74 |
.009 |
.398 |
| Age_cat:condition |
1, 25 |
0.00 |
2.06 |
.024 |
.164 |
Grouped by scale, condition, subject and network:yeo
data.funccon %>% mutate(weight = atanh(weight), from = gsub("V", "ROI_", from), to = gsub("V", "ROI_", to)) %>% rowwise() %>% mutate(from_network = ifelse(is.na(match(from, network.combined$ROI)), from, network.combined$name[match(from, network.combined$ROI)]), to_network = ifelse(is.na(match(to, network.combined$ROI)), to, network.combined$name[match(to, network.combined$ROI)]), from2to = paste0(sort(c(from_network,to_network))[1],"2",sort(c(from_network,to_network))[2])) -> data.funccon.ext
data.funccon.ext %>% mutate(abs_weight = abs(weight)) %>% group_by(Subj_ID,condition,from2to) -> tmp
# Calculate the number of occurrences of each network within each condition
df_counts <- table(tmp$from2to, tmp$condition)
knitr::kable(df_counts)
| Default2Default |
89667 |
89667 |
| Default2Dorsal Attention |
97416 |
97416 |
| Default2Frontoparietal |
99630 |
99630 |
| Default2Limbic |
64206 |
64206 |
| Default2Somatomotor |
117342 |
117342 |
| Default2Subcortical |
109962 |
110700 |
| Default2Ventral Attention |
106272 |
106272 |
| Default2Visual |
130626 |
130626 |
| Dorsal Attention2Dorsal Attention |
25542 |
25542 |
| Dorsal Attention2Frontoparietal |
53460 |
53460 |
| Dorsal Attention2Limbic |
34452 |
34452 |
| Dorsal Attention2Somatomotor |
62964 |
62964 |
| Dorsal Attention2Subcortical |
59004 |
59400 |
| Dorsal Attention2Ventral Attention |
57024 |
57024 |
| Dorsal Attention2Visual |
70092 |
70092 |
| Frontoparietal2Frontoparietal |
26730 |
26730 |
| Frontoparietal2Limbic |
35235 |
35235 |
| Frontoparietal2Somatomotor |
64395 |
64395 |
| Frontoparietal2Subcortical |
60345 |
60750 |
| Frontoparietal2Ventral Attention |
58320 |
58320 |
| Frontoparietal2Visual |
71685 |
71685 |
| Limbic2Limbic |
10962 |
10962 |
| Limbic2Somatomotor |
41499 |
41499 |
| Limbic2Subcortical |
38889 |
39150 |
| Limbic2Ventral Attention |
37584 |
37584 |
| Limbic2Visual |
46197 |
46197 |
| Somatomotor2Somatomotor |
37206 |
37206 |
| Somatomotor2Subcortical |
71073 |
71550 |
| Somatomotor2Ventral Attention |
68688 |
68688 |
| Somatomotor2Visual |
84429 |
84429 |
| Subcortical2Subcortical |
32670 |
33075 |
| Subcortical2Ventral Attention |
64368 |
64800 |
| Subcortical2Visual |
79119 |
79650 |
| Ventral Attention2Ventral Attention |
30456 |
30456 |
| Ventral Attention2Visual |
76464 |
76464 |
| Visual2Visual |
46197 |
46197 |
df_counts <- table(tmp$from2to)
# Calculate the number of occurrences of each network within each condition
df_counts <- table(tmp$from2to)
# Convert the counts to a data frame and add column names
df_counts <- as.data.frame(df_counts)
names(df_counts) <- c("network", "count")
# Create pie chart faceted by condition
ggplot(df_counts, aes(x = "", y = count, fill = network)) +
geom_bar(stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_void()

data.funccon.ext %>% group_by(Subj_ID,condition,from2to) %>% summarise(meanFuncConn = mean(weight)) -> data.funccon.aggr
# grouped_ggwithinstats(
# data = data.aggr,
# x = condition,
# y = meanFuncConn,
# grouping.var = from2to,
# type = "p",
# bf.message = FALSE)
# main anova
main_anova_summary <- aov_ez("Subj_ID", "meanFuncConn", data.funccon.aggr,within =c("condition","from2to"))
knitr::kable(nice(main_anova_summary))
| condition |
1, 26 |
0.01 |
0.46 |
<.001 |
.504 |
| from2to |
35, 910 |
0.01 |
94.04 *** |
.682 |
<.001 |
| condition:from2to |
35, 910 |
0.01 |
2.53 *** |
.032 |
<.001 |
emmip(main_anova_summary, from2to ~ condition)

EMM <- emmeans(main_anova_summary, ~ condition | from2to) # where treat has 2 levels
EMM.unadj <- summary(pairs(EMM), by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(pairs(EMM), by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
knitr::kable(left_join(EMM.unadj,EMM.fdr))
| Interferon - Placebo |
Default2Default |
-0.0115062 |
0.0174494 |
26 |
-0.6594067 |
0.5154333 |
0.8127516 |
| Interferon - Placebo |
Default2Dorsal.Attention |
0.0058752 |
0.0176813 |
26 |
0.3322848 |
0.7423383 |
0.8127516 |
| Interferon - Placebo |
Default2Frontoparietal |
0.0049899 |
0.0124984 |
26 |
0.3992413 |
0.6929759 |
0.8127516 |
| Interferon - Placebo |
Default2Limbic |
0.0156683 |
0.0178635 |
26 |
0.8771134 |
0.3884579 |
0.8127516 |
| Interferon - Placebo |
Default2Somatomotor |
0.0116184 |
0.0152453 |
26 |
0.7620945 |
0.4528620 |
0.8127516 |
| Interferon - Placebo |
Default2Subcortical |
0.0061428 |
0.0143315 |
26 |
0.4286237 |
0.6717274 |
0.8127516 |
| Interferon - Placebo |
Default2Ventral.Attention |
-0.0013334 |
0.0192044 |
26 |
-0.0694306 |
0.9451781 |
0.9451781 |
| Interferon - Placebo |
Default2Visual |
0.0079070 |
0.0162587 |
26 |
0.4863247 |
0.6308110 |
0.8127516 |
| Interferon - Placebo |
Dorsal.Attention2Dorsal.Attention |
-0.0245047 |
0.0273831 |
26 |
-0.8948828 |
0.3790598 |
0.8127516 |
| Interferon - Placebo |
Dorsal.Attention2Frontoparietal |
-0.0049723 |
0.0130610 |
26 |
-0.3806954 |
0.7065221 |
0.8127516 |
| Interferon - Placebo |
Dorsal.Attention2Limbic |
0.0606555 |
0.0203700 |
26 |
2.9776862 |
0.0062127 |
0.1118277 |
| Interferon - Placebo |
Dorsal.Attention2Somatomotor |
-0.0498630 |
0.0232124 |
26 |
-2.1481199 |
0.0411953 |
0.2471719 |
| Interferon - Placebo |
Dorsal.Attention2Subcortical |
0.0057870 |
0.0176063 |
26 |
0.3286907 |
0.7450223 |
0.8127516 |
| Interferon - Placebo |
Dorsal.Attention2Ventral.Attention |
-0.0234611 |
0.0189484 |
26 |
-1.2381565 |
0.2267219 |
0.6278452 |
| Interferon - Placebo |
Dorsal.Attention2Visual |
0.0139635 |
0.0235296 |
26 |
0.5934464 |
0.5580103 |
0.8127516 |
| Interferon - Placebo |
Frontoparietal2Frontoparietal |
0.0123844 |
0.0161737 |
26 |
0.7657112 |
0.4507439 |
0.8127516 |
| Interferon - Placebo |
Frontoparietal2Limbic |
0.0307797 |
0.0152877 |
26 |
2.0133594 |
0.0545369 |
0.2699736 |
| Interferon - Placebo |
Frontoparietal2Somatomotor |
0.0081089 |
0.0144743 |
26 |
0.5602266 |
0.5801205 |
0.8127516 |
| Interferon - Placebo |
Frontoparietal2Subcortical |
0.0134101 |
0.0105220 |
26 |
1.2744915 |
0.2137628 |
0.6278452 |
| Interferon - Placebo |
Frontoparietal2Ventral.Attention |
-0.0125953 |
0.0180966 |
26 |
-0.6960015 |
0.4926031 |
0.8127516 |
| Interferon - Placebo |
Frontoparietal2Visual |
0.0030929 |
0.0152130 |
26 |
0.2033043 |
0.8404800 |
0.8765290 |
| Interferon - Placebo |
Limbic2Limbic |
-0.0565078 |
0.0247568 |
26 |
-2.2825205 |
0.0308809 |
0.2409969 |
| Interferon - Placebo |
Limbic2Somatomotor |
0.0589345 |
0.0254405 |
26 |
2.3165596 |
0.0286710 |
0.2409969 |
| Interferon - Placebo |
Limbic2Subcortical |
0.0154161 |
0.0201529 |
26 |
0.7649594 |
0.4511837 |
0.8127516 |
| Interferon - Placebo |
Limbic2Ventral.Attention |
0.0810324 |
0.0187819 |
26 |
4.3143798 |
0.0002051 |
0.0073850 |
| Interferon - Placebo |
Limbic2Visual |
-0.0033502 |
0.0178010 |
26 |
-0.1882002 |
0.8521809 |
0.8765290 |
| Interferon - Placebo |
Somatomotor2Somatomotor |
-0.0793181 |
0.0353259 |
26 |
-2.2453238 |
0.0334718 |
0.2409969 |
| Interferon - Placebo |
Somatomotor2Subcortical |
0.0335466 |
0.0170585 |
26 |
1.9665575 |
0.0599941 |
0.2699736 |
| Interferon - Placebo |
Somatomotor2Ventral.Attention |
-0.0336031 |
0.0254148 |
26 |
-1.3221876 |
0.1976202 |
0.6278452 |
| Interferon - Placebo |
Somatomotor2Visual |
-0.0165790 |
0.0233846 |
26 |
-0.7089722 |
0.4846509 |
0.8127516 |
| Interferon - Placebo |
Subcortical2Subcortical |
0.0087950 |
0.0246437 |
26 |
0.3568855 |
0.7240578 |
0.8127516 |
| Interferon - Placebo |
Subcortical2Ventral.Attention |
0.0148183 |
0.0157127 |
26 |
0.9430742 |
0.3543243 |
0.8127516 |
| Interferon - Placebo |
Subcortical2Visual |
0.0104272 |
0.0184842 |
26 |
0.5641145 |
0.5775104 |
0.8127516 |
| Interferon - Placebo |
Ventral.Attention2Ventral.Attention |
-0.0328725 |
0.0261226 |
26 |
-1.2583928 |
0.2194331 |
0.6278452 |
| Interferon - Placebo |
Ventral.Attention2Visual |
0.0055992 |
0.0167858 |
26 |
0.3335692 |
0.7413800 |
0.8127516 |
| Interferon - Placebo |
Visual2Visual |
0.0475949 |
0.0330474 |
26 |
1.4402019 |
0.1617442 |
0.6278452 |
# aov_test <- aov(meanFuncConn ~ condition*from2to + Error(Subj_ID/(condition*from2to)), data=data.funccon.aggr)
# report(aov_test)
# uncorrected p values
# data.funccon.aggr %>% ungroup() %>%
# nest_by(from2to) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meanFuncConn", data, within ="condition")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# knitr::kable(anova_summary)
data.funccon.ext %>% mutate(abs_weight = abs(weight)) %>% group_by(Subj_ID,condition) %>% top_n(round(EDGES*0.1),weight) %>% group_by(Subj_ID,condition, from2to) %>% dplyr::summarise(meanFuncConn = mean(weight)) -> data.funccon.aggr
data.funccon.ext %>% mutate(abs_weight = abs(weight)) %>% group_by(Subj_ID,condition,from2to) %>% top_n(round(EDGES*0.1),weight) -> tmp
# Calculate the number of occurrences of each network within each condition
df_counts <- table(tmp$from2to, tmp$condition)
knitr::kable(df_counts)
| Default2Default |
89667 |
89667 |
| Default2Dorsal Attention |
97416 |
97416 |
| Default2Frontoparietal |
99630 |
99630 |
| Default2Limbic |
64206 |
64206 |
| Default2Somatomotor |
117342 |
117342 |
| Default2Subcortical |
109962 |
110700 |
| Default2Ventral Attention |
106272 |
106272 |
| Default2Visual |
130626 |
130626 |
| Dorsal Attention2Dorsal Attention |
25542 |
25542 |
| Dorsal Attention2Frontoparietal |
53460 |
53460 |
| Dorsal Attention2Limbic |
34452 |
34452 |
| Dorsal Attention2Somatomotor |
62964 |
62964 |
| Dorsal Attention2Subcortical |
59004 |
59400 |
| Dorsal Attention2Ventral Attention |
57024 |
57024 |
| Dorsal Attention2Visual |
70092 |
70092 |
| Frontoparietal2Frontoparietal |
26730 |
26730 |
| Frontoparietal2Limbic |
35235 |
35235 |
| Frontoparietal2Somatomotor |
64395 |
64395 |
| Frontoparietal2Subcortical |
60345 |
60750 |
| Frontoparietal2Ventral Attention |
58320 |
58320 |
| Frontoparietal2Visual |
71685 |
71685 |
| Limbic2Limbic |
10962 |
10962 |
| Limbic2Somatomotor |
41499 |
41499 |
| Limbic2Subcortical |
38889 |
39150 |
| Limbic2Ventral Attention |
37584 |
37584 |
| Limbic2Visual |
46197 |
46197 |
| Somatomotor2Somatomotor |
37206 |
37206 |
| Somatomotor2Subcortical |
71073 |
71550 |
| Somatomotor2Ventral Attention |
68688 |
68688 |
| Somatomotor2Visual |
84429 |
84429 |
| Subcortical2Subcortical |
32670 |
33075 |
| Subcortical2Ventral Attention |
64368 |
64800 |
| Subcortical2Visual |
79119 |
79650 |
| Ventral Attention2Ventral Attention |
30456 |
30456 |
| Ventral Attention2Visual |
76464 |
76464 |
| Visual2Visual |
46197 |
46197 |
df_counts <- table(tmp$from2to)
# Calculate the number of occurrences of each network within each condition
df_counts <- table(tmp$from2to)
# Convert the counts to a data frame and add column names
df_counts <- as.data.frame(df_counts)
names(df_counts) <- c("network", "count")
# Create pie chart faceted by condition
ggplot(df_counts, aes(x = "", y = count, fill = network)) +
geom_bar(stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_void()

# main anova
main_anova_summary <- aov_ez("Subj_ID", "meanFuncConn", data.funccon.aggr,within =c("condition","from2to"))
knitr::kable(nice(main_anova_summary))
| condition |
1, 26 |
0.26 |
10.71 ** |
.070 |
.003 |
| from2to |
35, 910 |
0.00 |
52.07 *** |
.100 |
<.001 |
| condition:from2to |
35, 910 |
0.00 |
1.16 |
.002 |
.240 |
emmip(main_anova_summary, from2to ~ condition)

EMM <- emmeans(main_anova_summary, ~ condition | from2to) # where treat has 2 levels
EMM.unadj <- summary(pairs(EMM), by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(pairs(EMM), by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
knitr::kable(left_join(EMM.unadj,EMM.fdr))
| Interferon - Placebo |
Default2Default |
-0.0589396 |
0.0206592 |
26 |
-2.852944 |
0.0083847 |
0.0116096 |
| Interferon - Placebo |
Default2Dorsal.Attention |
-0.0735613 |
0.0222787 |
26 |
-3.301865 |
0.0027955 |
0.0093939 |
| Interferon - Placebo |
Default2Frontoparietal |
-0.0686236 |
0.0212679 |
26 |
-3.226626 |
0.0033724 |
0.0093939 |
| Interferon - Placebo |
Default2Limbic |
-0.0669526 |
0.0254463 |
26 |
-2.631134 |
0.0141184 |
0.0169030 |
| Interferon - Placebo |
Default2Somatomotor |
-0.0818709 |
0.0238866 |
26 |
-3.427480 |
0.0020384 |
0.0093939 |
| Interferon - Placebo |
Default2Subcortical |
-0.0689410 |
0.0236654 |
26 |
-2.913157 |
0.0072591 |
0.0115845 |
| Interferon - Placebo |
Default2Ventral.Attention |
-0.0798188 |
0.0234698 |
26 |
-3.400919 |
0.0021797 |
0.0093939 |
| Interferon - Placebo |
Default2Visual |
-0.0748779 |
0.0232476 |
26 |
-3.220890 |
0.0034208 |
0.0093939 |
| Interferon - Placebo |
Dorsal.Attention2Dorsal.Attention |
-0.0722445 |
0.0251699 |
26 |
-2.870276 |
0.0080448 |
0.0115845 |
| Interferon - Placebo |
Dorsal.Attention2Frontoparietal |
-0.0663514 |
0.0216901 |
26 |
-3.059066 |
0.0050968 |
0.0115355 |
| Interferon - Placebo |
Dorsal.Attention2Limbic |
-0.0602085 |
0.0274557 |
26 |
-2.192935 |
0.0374548 |
0.0374548 |
| Interferon - Placebo |
Dorsal.Attention2Somatomotor |
-0.0820076 |
0.0230971 |
26 |
-3.550562 |
0.0014914 |
0.0093939 |
| Interferon - Placebo |
Dorsal.Attention2Subcortical |
-0.0623837 |
0.0246492 |
26 |
-2.530859 |
0.0177688 |
0.0193841 |
| Interferon - Placebo |
Dorsal.Attention2Ventral.Attention |
-0.0728382 |
0.0244924 |
26 |
-2.973916 |
0.0062696 |
0.0115355 |
| Interferon - Placebo |
Dorsal.Attention2Visual |
-0.0700796 |
0.0236368 |
26 |
-2.964854 |
0.0064086 |
0.0115355 |
| Interferon - Placebo |
Frontoparietal2Frontoparietal |
-0.0700674 |
0.0213011 |
26 |
-3.289372 |
0.0028842 |
0.0093939 |
| Interferon - Placebo |
Frontoparietal2Limbic |
-0.1101104 |
0.0257725 |
26 |
-4.272406 |
0.0002291 |
0.0082467 |
| Interferon - Placebo |
Frontoparietal2Somatomotor |
-0.0797478 |
0.0239682 |
26 |
-3.327239 |
0.0026234 |
0.0093939 |
| Interferon - Placebo |
Frontoparietal2Subcortical |
-0.0767858 |
0.0267317 |
26 |
-2.872463 |
0.0080029 |
0.0115845 |
| Interferon - Placebo |
Frontoparietal2Ventral.Attention |
-0.0709281 |
0.0222040 |
26 |
-3.194390 |
0.0036532 |
0.0093939 |
| Interferon - Placebo |
Frontoparietal2Visual |
-0.0779449 |
0.0229678 |
26 |
-3.393665 |
0.0022200 |
0.0093939 |
| Interferon - Placebo |
Limbic2Limbic |
-0.0724899 |
0.0304471 |
26 |
-2.380851 |
0.0248859 |
0.0259270 |
| Interferon - Placebo |
Limbic2Somatomotor |
-0.0873169 |
0.0303709 |
26 |
-2.875020 |
0.0079541 |
0.0115845 |
| Interferon - Placebo |
Limbic2Subcortical |
-0.0697146 |
0.0268323 |
26 |
-2.598162 |
0.0152335 |
0.0171377 |
| Interferon - Placebo |
Limbic2Ventral.Attention |
-0.0755877 |
0.0318255 |
26 |
-2.375065 |
0.0252068 |
0.0259270 |
| Interferon - Placebo |
Limbic2Visual |
-0.0901010 |
0.0302892 |
26 |
-2.974691 |
0.0062579 |
0.0115355 |
| Interferon - Placebo |
Somatomotor2Somatomotor |
-0.1114999 |
0.0298851 |
26 |
-3.730953 |
0.0009392 |
0.0093939 |
| Interferon - Placebo |
Somatomotor2Subcortical |
-0.0843894 |
0.0290090 |
26 |
-2.909074 |
0.0073307 |
0.0115845 |
| Interferon - Placebo |
Somatomotor2Ventral.Attention |
-0.0872196 |
0.0262567 |
26 |
-3.321804 |
0.0026594 |
0.0093939 |
| Interferon - Placebo |
Somatomotor2Visual |
-0.0674193 |
0.0257529 |
26 |
-2.617933 |
0.0145554 |
0.0169030 |
| Interferon - Placebo |
Subcortical2Subcortical |
-0.0761860 |
0.0269132 |
26 |
-2.830806 |
0.0088386 |
0.0117848 |
| Interferon - Placebo |
Subcortical2Ventral.Attention |
-0.0759520 |
0.0282943 |
26 |
-2.684353 |
0.0124779 |
0.0154898 |
| Interferon - Placebo |
Subcortical2Visual |
-0.0710146 |
0.0259422 |
26 |
-2.737411 |
0.0110215 |
0.0141705 |
| Interferon - Placebo |
Ventral.Attention2Ventral.Attention |
-0.0840783 |
0.0238015 |
26 |
-3.532478 |
0.0015617 |
0.0093939 |
| Interferon - Placebo |
Ventral.Attention2Visual |
-0.0738669 |
0.0245242 |
26 |
-3.011999 |
0.0057164 |
0.0115355 |
| Interferon - Placebo |
Visual2Visual |
-0.0686427 |
0.0229487 |
26 |
-2.991141 |
0.0060133 |
0.0115355 |
data.funccon.ext %>% mutate(abs_weight = abs(weight)) %>% group_by(Subj_ID,condition) %>% top_n(round(EDGES*0.35),weight) %>% group_by(Subj_ID,condition, from2to) %>% dplyr::summarise(meanFuncConn = mean(weight)) -> data.funccon.aggr
data.funccon.ext %>% mutate(abs_weight = abs(weight)) %>% group_by(Subj_ID,condition,from2to) %>% top_n(round(EDGES*0.35),weight) -> tmp
# Calculate the number of occurrences of each network within each condition
df_counts <- table(tmp$from2to, tmp$condition)
knitr::kable(df_counts)
| Default2Default |
89667 |
89667 |
| Default2Dorsal Attention |
97416 |
97416 |
| Default2Frontoparietal |
99630 |
99630 |
| Default2Limbic |
64206 |
64206 |
| Default2Somatomotor |
117342 |
117342 |
| Default2Subcortical |
109962 |
110700 |
| Default2Ventral Attention |
106272 |
106272 |
| Default2Visual |
130626 |
130626 |
| Dorsal Attention2Dorsal Attention |
25542 |
25542 |
| Dorsal Attention2Frontoparietal |
53460 |
53460 |
| Dorsal Attention2Limbic |
34452 |
34452 |
| Dorsal Attention2Somatomotor |
62964 |
62964 |
| Dorsal Attention2Subcortical |
59004 |
59400 |
| Dorsal Attention2Ventral Attention |
57024 |
57024 |
| Dorsal Attention2Visual |
70092 |
70092 |
| Frontoparietal2Frontoparietal |
26730 |
26730 |
| Frontoparietal2Limbic |
35235 |
35235 |
| Frontoparietal2Somatomotor |
64395 |
64395 |
| Frontoparietal2Subcortical |
60345 |
60750 |
| Frontoparietal2Ventral Attention |
58320 |
58320 |
| Frontoparietal2Visual |
71685 |
71685 |
| Limbic2Limbic |
10962 |
10962 |
| Limbic2Somatomotor |
41499 |
41499 |
| Limbic2Subcortical |
38889 |
39150 |
| Limbic2Ventral Attention |
37584 |
37584 |
| Limbic2Visual |
46197 |
46197 |
| Somatomotor2Somatomotor |
37206 |
37206 |
| Somatomotor2Subcortical |
71073 |
71550 |
| Somatomotor2Ventral Attention |
68688 |
68688 |
| Somatomotor2Visual |
84429 |
84429 |
| Subcortical2Subcortical |
32670 |
33075 |
| Subcortical2Ventral Attention |
64368 |
64800 |
| Subcortical2Visual |
79119 |
79650 |
| Ventral Attention2Ventral Attention |
30456 |
30456 |
| Ventral Attention2Visual |
76464 |
76464 |
| Visual2Visual |
46197 |
46197 |
df_counts <- table(tmp$from2to)
# Calculate the number of occurrences of each network within each condition
df_counts <- table(tmp$from2to)
# Convert the counts to a data frame and add column names
df_counts <- as.data.frame(df_counts)
names(df_counts) <- c("network", "count")
# Create pie chart faceted by condition
ggplot(df_counts, aes(x = "", y = count, fill = network)) +
geom_bar(stat = "identity", width = 1) +
coord_polar("y", start = 0) +
theme_void()

# main anova
main_anova_summary <- aov_ez("Subj_ID", "meanFuncConn", data.funccon.aggr,within =c("condition","from2to"))
knitr::kable(nice(main_anova_summary))
| condition |
1, 26 |
0.13 |
8.83 ** |
.048 |
.006 |
| from2to |
35, 910 |
0.00 |
63.42 *** |
.256 |
<.001 |
| condition:from2to |
35, 910 |
0.00 |
1.03 |
.003 |
.422 |
emmip(main_anova_summary, from2to ~ condition)

EMM <- emmeans(main_anova_summary, ~ condition | from2to) # where treat has 2 levels
EMM.unadj <- summary(pairs(EMM), by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(pairs(EMM), by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
knitr::kable(left_join(EMM.unadj,EMM.fdr))
| Interferon - Placebo |
Default2Default |
-0.0452756 |
0.0158522 |
26 |
-2.856103 |
0.0083218 |
0.0259050 |
| Interferon - Placebo |
Default2Dorsal.Attention |
-0.0453066 |
0.0160511 |
26 |
-2.822658 |
0.0090115 |
0.0259050 |
| Interferon - Placebo |
Default2Frontoparietal |
-0.0420201 |
0.0147892 |
26 |
-2.841264 |
0.0086214 |
0.0259050 |
| Interferon - Placebo |
Default2Limbic |
-0.0511946 |
0.0169922 |
26 |
-3.012825 |
0.0057049 |
0.0259050 |
| Interferon - Placebo |
Default2Somatomotor |
-0.0552391 |
0.0184712 |
26 |
-2.990549 |
0.0060220 |
0.0259050 |
| Interferon - Placebo |
Default2Subcortical |
-0.0393645 |
0.0165371 |
26 |
-2.380373 |
0.0249123 |
0.0407655 |
| Interferon - Placebo |
Default2Ventral.Attention |
-0.0480927 |
0.0166644 |
26 |
-2.885948 |
0.0077488 |
0.0259050 |
| Interferon - Placebo |
Default2Visual |
-0.0426345 |
0.0158754 |
26 |
-2.685571 |
0.0124426 |
0.0263489 |
| Interferon - Placebo |
Dorsal.Attention2Dorsal.Attention |
-0.0495034 |
0.0221644 |
26 |
-2.233465 |
0.0343383 |
0.0475453 |
| Interferon - Placebo |
Dorsal.Attention2Frontoparietal |
-0.0402500 |
0.0148068 |
26 |
-2.718336 |
0.0115257 |
0.0259328 |
| Interferon - Placebo |
Dorsal.Attention2Limbic |
-0.0418653 |
0.0219521 |
26 |
-1.907119 |
0.0676112 |
0.0737577 |
| Interferon - Placebo |
Dorsal.Attention2Somatomotor |
-0.0585235 |
0.0207325 |
26 |
-2.822787 |
0.0090087 |
0.0259050 |
| Interferon - Placebo |
Dorsal.Attention2Subcortical |
-0.0421641 |
0.0180573 |
26 |
-2.335016 |
0.0275339 |
0.0413008 |
| Interferon - Placebo |
Dorsal.Attention2Ventral.Attention |
-0.0491621 |
0.0166846 |
26 |
-2.946563 |
0.0066981 |
0.0259050 |
| Interferon - Placebo |
Dorsal.Attention2Visual |
-0.0286605 |
0.0217582 |
26 |
-1.317224 |
0.1992549 |
0.2049479 |
| Interferon - Placebo |
Frontoparietal2Frontoparietal |
-0.0368437 |
0.0132807 |
26 |
-2.774216 |
0.0101068 |
0.0259050 |
| Interferon - Placebo |
Frontoparietal2Limbic |
-0.0658801 |
0.0214841 |
26 |
-3.066466 |
0.0050054 |
0.0259050 |
| Interferon - Placebo |
Frontoparietal2Somatomotor |
-0.0481856 |
0.0182876 |
26 |
-2.634877 |
0.0139967 |
0.0279934 |
| Interferon - Placebo |
Frontoparietal2Subcortical |
-0.0425054 |
0.0192832 |
26 |
-2.204276 |
0.0365580 |
0.0487440 |
| Interferon - Placebo |
Frontoparietal2Ventral.Attention |
-0.0490681 |
0.0156623 |
26 |
-3.132883 |
0.0042526 |
0.0259050 |
| Interferon - Placebo |
Frontoparietal2Visual |
-0.0390631 |
0.0166052 |
26 |
-2.352462 |
0.0264971 |
0.0413008 |
| Interferon - Placebo |
Limbic2Limbic |
-0.0524214 |
0.0268639 |
26 |
-1.951372 |
0.0618650 |
0.0695982 |
| Interferon - Placebo |
Limbic2Somatomotor |
-0.0535292 |
0.0222044 |
26 |
-2.410747 |
0.0232867 |
0.0399201 |
| Interferon - Placebo |
Limbic2Subcortical |
-0.0517048 |
0.0248988 |
26 |
-2.076599 |
0.0478611 |
0.0594138 |
| Interferon - Placebo |
Limbic2Ventral.Attention |
-0.0517423 |
0.0228231 |
26 |
-2.267099 |
0.0319321 |
0.0459822 |
| Interferon - Placebo |
Limbic2Visual |
-0.0540915 |
0.0220188 |
26 |
-2.456609 |
0.0210161 |
0.0398200 |
| Interferon - Placebo |
Somatomotor2Somatomotor |
-0.1001769 |
0.0271876 |
26 |
-3.684650 |
0.0010581 |
0.0259050 |
| Interferon - Placebo |
Somatomotor2Subcortical |
-0.0535636 |
0.0220983 |
26 |
-2.423879 |
0.0226145 |
0.0399201 |
| Interferon - Placebo |
Somatomotor2Ventral.Attention |
-0.0617064 |
0.0220224 |
26 |
-2.801982 |
0.0094645 |
0.0259050 |
| Interferon - Placebo |
Somatomotor2Visual |
-0.0429386 |
0.0208614 |
26 |
-2.058281 |
0.0497160 |
0.0596592 |
| Interferon - Placebo |
Subcortical2Subcortical |
-0.0424470 |
0.0240902 |
26 |
-1.761999 |
0.0898247 |
0.0951086 |
| Interferon - Placebo |
Subcortical2Ventral.Attention |
-0.0426144 |
0.0214374 |
26 |
-1.987854 |
0.0574541 |
0.0667208 |
| Interferon - Placebo |
Subcortical2Visual |
-0.0395548 |
0.0190042 |
26 |
-2.081369 |
0.0473883 |
0.0594138 |
| Interferon - Placebo |
Ventral.Attention2Ventral.Attention |
-0.0561329 |
0.0186665 |
26 |
-3.007154 |
0.0057841 |
0.0259050 |
| Interferon - Placebo |
Ventral.Attention2Visual |
-0.0483860 |
0.0176186 |
26 |
-2.746299 |
0.0107937 |
0.0259050 |
| Interferon - Placebo |
Visual2Visual |
-0.0311741 |
0.0242073 |
26 |
-1.287800 |
0.2091602 |
0.2091602 |
Grouped by scale, condition, subject and network:yeo and age
#slow to calc
data.funccon %>% mutate(weight = atanh(weight), from = gsub("V", "ROI_", from), to = gsub("V", "ROI_", to)) %>% rowwise() %>% mutate(from_network = ifelse(is.na(match(from, network.combined$ROI)), from, network.combined$name[match(from, network.combined$ROI)]), to_network = ifelse(is.na(match(to, network.combined$ROI)), to, network.combined$name[match(to, network.combined$ROI)]), from2to = paste0(sort(c(from_network,to_network))[1],"2",sort(c(from_network,to_network))[2])) %>% group_by(Subj_ID,condition,from2to, Age_cat) %>% summarise(meanFuncConn = mean(weight)) -> data.funccon.network.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanFuncConn", data.funccon.network.aggr,within =c("condition","from2to"), between = "Age_cat")
knitr::kable(nice(main_anova_summary))
| Age_cat |
1, 25 |
0.02 |
0.86 |
.001 |
.363 |
| condition |
1, 25 |
0.01 |
0.55 |
<.001 |
.466 |
| Age_cat:condition |
1, 25 |
0.01 |
1.92 |
.002 |
.178 |
| from2to |
35, 875 |
0.01 |
93.19 *** |
.689 |
<.001 |
| Age_cat:from2to |
35, 875 |
0.01 |
0.82 |
.019 |
.765 |
| condition:from2to |
35, 875 |
0.01 |
2.50 *** |
.033 |
<.001 |
| Age_cat:condition:from2to |
35, 875 |
0.01 |
0.91 |
.012 |
.619 |
EMM <- emmeans(main_anova_summary, ~ condition)
EMM.unadj <- summary(pairs(EMM), by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(pairs(EMM), by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
knitr::kable(left_join(EMM.unadj,EMM.fdr))
| Interferon - Placebo |
0.0037629 |
0.0050778 |
25 |
0.7410429 |
0.4655717 |
0.4655717 |
# data.funccon.network.aggr %>% ungroup() %>%
# nest_by(from2to) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meanFuncConn", data, within ="condition", between = "Age_cat")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# knitr::kable(anova_summary)
Summary
Node degree
Grouped by scale, condition, subject
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "degree") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition) %>% summarise(meanDegree = mean(degree)) -> data.aggr
anova_summary <- aov_ez("Subj_ID", "meanDegree", data.aggr, within =c("condition","threshold"))
knitr::kable(nice(anova_summary))
| condition |
1, 26 |
4.25 |
0.01 |
<.001 |
.939 |
| threshold |
1, 26 |
1.57 |
179476.85 *** |
.999 |
<.001 |
| condition:threshold |
1, 26 |
0.51 |
0.04 |
<.001 |
.835 |
emmip(anova_summary, condition~threshold )

grouped_ggwithinstats(
data = data.aggr,
x = condition,
y = meanDegree,
grouping.var = threshold,
type = "np",
bf.message = FALSE,
exact = FALSE
)

Grouped by scale, condition, subject and age_cat
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "degree") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition, Age_cat) %>% summarise(meanDegree = mean(degree)) -> data.aggr
anova_summary <- nice(aov_ez("Subj_ID", "meanDegree", data.aggr, within =c("condition","threshold"), between = "Age_cat"))
knitr::kable(anova_summary)
| Age_cat |
1, 25 |
5.94 |
0.51 |
.010 |
.482 |
| condition |
1, 25 |
4.29 |
0.00 |
<.001 |
.965 |
| Age_cat:condition |
1, 25 |
4.29 |
0.79 |
.011 |
.383 |
| threshold |
1, 25 |
1.57 |
179834.82 *** |
.999 |
<.001 |
| Age_cat:threshold |
1, 25 |
1.57 |
1.08 |
.005 |
.308 |
| condition:threshold |
1, 25 |
0.53 |
0.04 |
<.001 |
.834 |
| Age_cat:condition:threshold |
1, 25 |
0.53 |
0.02 |
<.001 |
.892 |
#
# data.aggr %>% ungroup() %>%
# nest_by(threshold) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meanDegree", data, within ="condition", between="Age_cat")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# knitr::kable(anova_summary)
#
# # aw <- aov_ez("Subj_ID", "meanDegree", data.aggr, within ="condition", between="Age_cat")
# # p_an <- afex_plot(aw, x = "condition", trace = "Age_cat") + ggtitle("test") + theme(legend.position = c(0.87, 0.15),legend.key.size = unit(0.3, "cm"))
#
# # plot anovas
#
# d_nested <- data.aggr %>% ungroup() %>%
# nest_by(threshold)
#
# d_plots <-
# d_nested %>%
# mutate(aov = list(map(data,~aov_ez("Subj_ID", "meanDegree", data, within ="condition", between="Age_cat")))) %>%
# mutate(plot = list(map2(aov,threshold,~afex_plot(., x = "condition", trace = "Age_cat") +ggtitle(paste("threshold:",threshold)) + theme(legend.position = c(0.87, 0.15),legend.key.size = unit(0.3, "cm")))))
#
# d_plots$plot_one <- lapply(d_plots$plot, "[[", 1)
#
# library(gridExtra)
# do.call(grid.arrange, c(d_plots$plot_one))
Grouped by scale, condition, subject and network:yeo
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "degree") %>% left_join(.,network.combined) %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition,name) %>% summarise(meanDegree = mean(degree)) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanDegree", data.aggr,within =c("condition","name","threshold"))
knitr::kable(nice(main_anova_summary))
| condition |
1, 26 |
41.18 |
0.03 |
<.001 |
.856 |
| name |
4.96, 128.90 |
53.83 |
2.02 + |
.026 |
.080 |
| threshold |
1, 26 |
12.59 |
179071.02 *** |
.991 |
<.001 |
| condition:name |
5.05, 131.26 |
56.12 |
0.41 |
.006 |
.840 |
| condition:threshold |
1, 26 |
5.68 |
0.14 |
<.001 |
.709 |
| name:threshold |
5.16, 134.20 |
10.22 |
0.84 |
.002 |
.523 |
| condition:name:threshold |
4.99, 129.85 |
10.90 |
0.30 |
<.001 |
.914 |
#emmip(main_anova_summary, condition~threshold)
# average across threshold
main_anova_summary <- aov_ez("Subj_ID", "meanDegree", data.aggr,within =c("condition","name"))
knitr::kable(nice(main_anova_summary))
| condition |
1, 26 |
20.59 |
0.03 |
<.001 |
.856 |
| name |
4.96, 128.90 |
26.91 |
2.02 + |
.031 |
.080 |
| condition:name |
5.05, 131.26 |
28.06 |
0.41 |
.007 |
.840 |
EMM <- emmeans(main_anova_summary, ~ condition | name) %>% contrast(interaction = c( "consec", "consec"))
EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
knitr::kable(left_join(EMM.unadj,EMM.fdr))
| Placebo - Interferon |
Default |
-0.7170280 |
1.0471181 |
26 |
-0.6847632 |
0.4995527 |
0.799321 |
| Placebo - Interferon |
Dorsal.Attention |
-0.9494949 |
1.0314339 |
26 |
-0.9205582 |
0.3657441 |
0.799321 |
| Placebo - Interferon |
Frontoparietal |
0.8086420 |
1.3979838 |
26 |
0.5784344 |
0.5679480 |
0.799321 |
| Placebo - Interferon |
Limbic |
0.4872286 |
1.6628758 |
26 |
0.2930036 |
0.7718452 |
0.799321 |
| Placebo - Interferon |
Somatomotor |
0.9119497 |
0.8757177 |
26 |
1.0413740 |
0.3072892 |
0.799321 |
| Placebo - Interferon |
Subcortical |
-0.2992593 |
1.1651410 |
26 |
-0.2568438 |
0.7993210 |
0.799321 |
| Placebo - Interferon |
Ventral.Attention |
-0.5385802 |
1.1123413 |
26 |
-0.4841862 |
0.6323074 |
0.799321 |
| Placebo - Interferon |
Visual |
0.9350282 |
1.3330593 |
26 |
0.7014153 |
0.4892750 |
0.799321 |
# focus on threshold=3.5
knitr::kable(nice(aov_ez("Subj_ID", "meanDegree", data.aggr %>% filter(threshold=="3.5"),within =c("condition","name"))))
| condition |
1, 26 |
28.91 |
0.00 |
<.001 |
.971 |
| name |
5.25, 136.39 |
38.86 |
1.61 |
.024 |
.158 |
| condition:name |
5.17, 134.54 |
44.42 |
0.29 |
.005 |
.924 |
main_anova_summary <- aov_ez("Subj_ID", "meanDegree", data.aggr,within =c("condition","name","threshold"))
knitr::kable(nice(main_anova_summary))
| condition |
1, 26 |
41.18 |
0.03 |
<.001 |
.856 |
| name |
4.96, 128.90 |
53.83 |
2.02 + |
.026 |
.080 |
| threshold |
1, 26 |
12.59 |
179071.02 *** |
.991 |
<.001 |
| condition:name |
5.05, 131.26 |
56.12 |
0.41 |
.006 |
.840 |
| condition:threshold |
1, 26 |
5.68 |
0.14 |
<.001 |
.709 |
| name:threshold |
5.16, 134.20 |
10.22 |
0.84 |
.002 |
.523 |
| condition:name:threshold |
4.99, 129.85 |
10.90 |
0.30 |
<.001 |
.914 |
EMM <- emmeans(main_anova_summary, ~ condition | name, at=list(threshold="X3.5"))
EMM.unadj <- summary(pairs(EMM), by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(pairs(EMM), by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
knitr::kable(left_join(EMM.unadj,EMM.fdr))
| Interferon - Placebo |
Default |
0.5790425 |
1.338590 |
26 |
0.4325765 |
0.6688894 |
0.940674 |
| Interferon - Placebo |
Dorsal.Attention |
1.1195286 |
1.337177 |
26 |
0.8372331 |
0.4100916 |
0.940674 |
| Interferon - Placebo |
Frontoparietal |
-0.1308642 |
1.741473 |
26 |
-0.0751457 |
0.9406740 |
0.940674 |
| Interferon - Placebo |
Limbic |
-0.4584930 |
2.144796 |
26 |
-0.2137700 |
0.8323940 |
0.940674 |
| Interferon - Placebo |
Somatomotor |
-1.0230608 |
1.058166 |
26 |
-0.9668245 |
0.3425396 |
0.940674 |
| Interferon - Placebo |
Subcortical |
0.2503704 |
1.565206 |
26 |
0.1599601 |
0.8741488 |
0.940674 |
| Interferon - Placebo |
Ventral.Attention |
0.7199074 |
1.313644 |
26 |
0.5480233 |
0.5883506 |
0.940674 |
| Interferon - Placebo |
Visual |
-1.2059008 |
1.631061 |
26 |
-0.7393352 |
0.4663266 |
0.940674 |
# data.aggr %>% ungroup() %>%
# nest_by(threshold,name) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meanDegree", data, within ="condition")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# knitr::kable(anova_summary)
Grouped by scale, condition, subject, age_cat and network:yeo
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "degree") %>% left_join(.,network.combined) %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition,name,Age_cat) %>% summarise(meanDegree = mean(degree)) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanDegree", data.aggr,within =c("condition","name","threshold"), between = "Age_cat")
knitr::kable(nice(main_anova_summary))
| Age_cat |
1, 25 |
55.68 |
0.23 |
<.001 |
.635 |
| condition |
1, 25 |
40.27 |
0.02 |
<.001 |
.891 |
| Age_cat:condition |
1, 25 |
40.27 |
1.59 |
.003 |
.219 |
| name |
4.84, 121.12 |
55.51 |
2.04 + |
.027 |
.080 |
| Age_cat:name |
4.84, 121.12 |
55.51 |
0.80 |
.011 |
.548 |
| threshold |
1, 25 |
12.86 |
175158.10 *** |
.991 |
<.001 |
| Age_cat:threshold |
1, 25 |
12.86 |
0.46 |
<.001 |
.502 |
| condition:name |
5.06, 126.41 |
56.82 |
0.40 |
.006 |
.850 |
| Age_cat:condition:name |
5.06, 126.41 |
56.82 |
0.64 |
.009 |
.671 |
| condition:threshold |
1, 25 |
5.79 |
0.16 |
<.001 |
.693 |
| Age_cat:condition:threshold |
1, 25 |
5.79 |
0.49 |
<.001 |
.492 |
| name:threshold |
5.10, 127.48 |
10.02 |
0.88 |
.002 |
.498 |
| Age_cat:name:threshold |
5.10, 127.48 |
10.02 |
1.86 |
.005 |
.105 |
| condition:name:threshold |
5.01, 125.33 |
11.00 |
0.31 |
<.001 |
.906 |
| Age_cat:condition:name:threshold |
5.01, 125.33 |
11.00 |
0.67 |
.002 |
.649 |
emmip(main_anova_summary, name~condition | Age_cat)

emmip(main_anova_summary, name~Age_cat)

main_anova_summary <- aov_ez("Subj_ID", "meanDegree", data.aggr,within =c("condition","name"),between = "Age_cat")
knitr::kable(nice(main_anova_summary))
| Age_cat |
1, 25 |
27.84 |
0.23 |
<.001 |
.635 |
| condition |
1, 25 |
20.14 |
0.02 |
<.001 |
.891 |
| Age_cat:condition |
1, 25 |
20.14 |
1.59 |
.004 |
.219 |
| name |
4.84, 121.12 |
27.75 |
2.04 + |
.033 |
.080 |
| Age_cat:name |
4.84, 121.12 |
27.75 |
0.80 |
.013 |
.548 |
| condition:name |
5.06, 126.41 |
28.41 |
0.40 |
.007 |
.850 |
| Age_cat:condition:name |
5.06, 126.41 |
28.41 |
0.64 |
.011 |
.671 |
EMM <- emmeans(main_anova_summary, ~ condition:Age_cat | name) %>% contrast(interaction = c( "consec", "consec"))
EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
knitr::kable(left_join(EMM.unadj,EMM.fdr))
| Placebo - Interferon |
Y - O |
Default |
0.6627915 |
2.133062 |
25 |
0.3107231 |
0.7585871 |
0.9114497 |
| Placebo - Interferon |
Y - O |
Dorsal.Attention |
-0.5104271 |
2.102688 |
25 |
-0.2427498 |
0.8101798 |
0.9114497 |
| Placebo - Interferon |
Y - O |
Frontoparietal |
-2.6672161 |
2.802987 |
25 |
-0.9515619 |
0.3504290 |
0.8063462 |
| Placebo - Interferon |
Y - O |
Limbic |
-4.4489390 |
3.275229 |
25 |
-1.3583595 |
0.1864820 |
0.8063462 |
| Placebo - Interferon |
Y - O |
Somatomotor |
-1.4984450 |
1.762043 |
25 |
-0.8504020 |
0.4031731 |
0.8063462 |
| Placebo - Interferon |
Y - O |
Subcortical |
0.2670879 |
2.377462 |
25 |
0.1123416 |
0.9114497 |
0.9114497 |
| Placebo - Interferon |
Y - O |
Ventral.Attention |
-2.0906021 |
2.231463 |
25 |
-0.9368752 |
0.3577859 |
0.8063462 |
| Placebo - Interferon |
Y - O |
Visual |
1.5773887 |
2.702433 |
25 |
0.5836921 |
0.5646571 |
0.9034514 |
# focus on threshold=3.5
main_anova_summary <- aov_ez("Subj_ID", "meanDegree", data.aggr,within =c("condition","name","threshold"),between = "Age_cat")
knitr::kable(nice(main_anova_summary))
| Age_cat |
1, 25 |
55.68 |
0.23 |
<.001 |
.635 |
| condition |
1, 25 |
40.27 |
0.02 |
<.001 |
.891 |
| Age_cat:condition |
1, 25 |
40.27 |
1.59 |
.003 |
.219 |
| name |
4.84, 121.12 |
55.51 |
2.04 + |
.027 |
.080 |
| Age_cat:name |
4.84, 121.12 |
55.51 |
0.80 |
.011 |
.548 |
| threshold |
1, 25 |
12.86 |
175158.10 *** |
.991 |
<.001 |
| Age_cat:threshold |
1, 25 |
12.86 |
0.46 |
<.001 |
.502 |
| condition:name |
5.06, 126.41 |
56.82 |
0.40 |
.006 |
.850 |
| Age_cat:condition:name |
5.06, 126.41 |
56.82 |
0.64 |
.009 |
.671 |
| condition:threshold |
1, 25 |
5.79 |
0.16 |
<.001 |
.693 |
| Age_cat:condition:threshold |
1, 25 |
5.79 |
0.49 |
<.001 |
.492 |
| name:threshold |
5.10, 127.48 |
10.02 |
0.88 |
.002 |
.498 |
| Age_cat:name:threshold |
5.10, 127.48 |
10.02 |
1.86 |
.005 |
.105 |
| condition:name:threshold |
5.01, 125.33 |
11.00 |
0.31 |
<.001 |
.906 |
| Age_cat:condition:name:threshold |
5.01, 125.33 |
11.00 |
0.67 |
.002 |
.649 |
EMM <- emmeans(main_anova_summary, ~ condition:Age_cat | name, at=list(threshold="X3.5")) %>% contrast(interaction = c( "consec", "consec"))
EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
knitr::kable(left_join(EMM.unadj,EMM.fdr))
| Placebo - Interferon |
Y - O |
Default |
1.3555347 |
2.718588 |
25 |
0.4986172 |
0.6224080 |
0.8082598 |
| Placebo - Interferon |
Y - O |
Dorsal.Attention |
-1.0338412 |
2.721345 |
25 |
-0.3799008 |
0.7072273 |
0.8082598 |
| Placebo - Interferon |
Y - O |
Frontoparietal |
-3.4435897 |
3.486996 |
25 |
-0.9875520 |
0.3328343 |
0.7663910 |
| Placebo - Interferon |
Y - O |
Limbic |
-6.1788556 |
4.199497 |
25 |
-1.4713321 |
0.1536779 |
0.7663910 |
| Placebo - Interferon |
Y - O |
Somatomotor |
-1.5363881 |
2.137754 |
25 |
-0.7186925 |
0.4789944 |
0.7663910 |
| Placebo - Interferon |
Y - O |
Subcortical |
-0.2440659 |
3.194224 |
25 |
-0.0764085 |
0.9397023 |
0.9397023 |
| Placebo - Interferon |
Y - O |
Ventral.Attention |
-2.1596841 |
2.646136 |
25 |
-0.8161650 |
0.4221147 |
0.7663910 |
| Placebo - Interferon |
Y - O |
Visual |
2.7032036 |
3.284815 |
25 |
0.8229394 |
0.4183234 |
0.7663910 |
# data.aggr %>% ungroup() %>%
# nest_by(threshold,name) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meanDegree", data, within ="condition",between="Age_cat")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# knitr::kable(anova_summary)
Hubness?
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "degree") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition) %>% mutate(quartile = ntile(degree, 4)) -> data.aggr
fit1 <- lmer(degree ~ condition*quartile + (1 | Subj_ID), data.aggr )
fit2 <- lmer(degree ~ condition*quartile + Age + (1 | Subj_ID), data.aggr )
fit3 <- lmer(degree ~ condition*quartile*Age + (1 | Subj_ID), data.aggr )
tab_model(fit1,fit2,fit3)
|
Â
|
degree
|
degree
|
degree
|
|
Predictors
|
Estimates
|
CI
|
p
|
Estimates
|
CI
|
p
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
21.06
|
19.35 – 22.76
|
<0.001
|
21.34
|
19.32 – 23.37
|
<0.001
|
22.48
|
18.35 – 26.61
|
<0.001
|
|
condition [Placebo]
|
-0.42
|
-2.83 – 1.99
|
0.733
|
-0.42
|
-2.83 – 1.99
|
0.733
|
-1.47
|
-7.31 – 4.38
|
0.623
|
|
quartile
|
28.44
|
27.81 – 29.06
|
<0.001
|
28.44
|
27.81 – 29.06
|
<0.001
|
28.25
|
26.74 – 29.76
|
<0.001
|
condition [Placebo] × quartile
|
0.18
|
-0.70 – 1.06
|
0.688
|
0.18
|
-0.70 – 1.06
|
0.688
|
0.06
|
-2.08 – 2.20
|
0.958
|
|
Age
|
|
|
|
-0.01
|
-0.03 – 0.02
|
0.608
|
-0.03
|
-0.11 – 0.05
|
0.459
|
|
condition [Placebo] × Age
|
|
|
|
|
|
|
0.02
|
-0.09 – 0.14
|
0.700
|
|
quartile × Age
|
|
|
|
|
|
|
0.00
|
-0.03 – 0.03
|
0.793
|
(condition [Placebo] × quartile) × Age
|
|
|
|
|
|
|
0.00
|
-0.04 – 0.04
|
0.901
|
|
Random Effects
|
|
σ2
|
2803.66
|
2803.71
|
2803.79
|
|
τ00
|
0.00 Subj_ID
|
0.00 Subj_ID
|
0.00 Subj_ID
|
|
N
|
27 Subj_ID
|
27 Subj_ID
|
27 Subj_ID
|
|
Observations
|
44280
|
44280
|
44280
|
|
Marginal R2 / Conditional R2
|
0.266 / NA
|
0.266 / NA
|
0.266 / NA
|
plot_model(fit1, type = "pred", terms = c("quartile[all]","condition") )

fit1 <- lmer(degree ~ condition*quartile + (1 | Subj_ID), data.aggr %>% filter(threshold==3.5))
fit2 <- lmer(degree ~ condition*quartile + Age + (1 | Subj_ID), data.aggr %>% filter(threshold==3.5))
fit3 <- lmer(degree ~ condition*quartile*Age + (1 | Subj_ID), data.aggr %>% filter(threshold==3.5))
tab_model(fit1,fit2,fit3)
|
Â
|
degree
|
degree
|
degree
|
|
Predictors
|
Estimates
|
CI
|
p
|
Estimates
|
CI
|
p
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
59.11
|
58.22 – 60.00
|
<0.001
|
59.66
|
58.00 – 61.33
|
<0.001
|
60.63
|
58.47 – 62.79
|
<0.001
|
|
condition [Placebo]
|
-0.15
|
-1.07 – 0.77
|
0.745
|
-0.15
|
-1.07 – 0.77
|
0.745
|
-0.81
|
-3.04 – 1.42
|
0.475
|
|
quartile
|
33.68
|
33.44 – 33.92
|
<0.001
|
33.68
|
33.44 – 33.92
|
<0.001
|
33.58
|
33.00 – 34.16
|
<0.001
|
condition [Placebo] × quartile
|
0.06
|
-0.27 – 0.40
|
0.718
|
0.06
|
-0.27 – 0.40
|
0.718
|
-0.25
|
-1.06 – 0.57
|
0.553
|
|
Age
|
|
|
|
-0.01
|
-0.04 – 0.02
|
0.438
|
-0.03
|
-0.08 – 0.01
|
0.128
|
|
condition [Placebo] × Age
|
|
|
|
|
|
|
0.01
|
-0.03 – 0.06
|
0.525
|
|
quartile × Age
|
|
|
|
|
|
|
0.00
|
-0.01 – 0.01
|
0.703
|
(condition [Placebo] × quartile) × Age
|
|
|
|
|
|
|
0.01
|
-0.01 – 0.02
|
0.415
|
|
Random Effects
|
|
σ2
|
203.96
|
203.96
|
203.86
|
|
τ00
|
2.57 Subj_ID
|
2.61 Subj_ID
|
2.61 Subj_ID
|
|
ICC
|
0.01
|
0.01
|
0.01
|
|
N
|
27 Subj_ID
|
27 Subj_ID
|
27 Subj_ID
|
|
Observations
|
22140
|
22140
|
22140
|
|
Marginal R2 / Conditional R2
|
0.873 / 0.875
|
0.873 / 0.875
|
0.873 / 0.875
|
plot_model(fit1, type = "pred", terms = c("quartile[all]","condition") )

Summary
Betweenness centrality
Grouped by scale, condition, subject
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "bwc") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition) %>% summarise(meanBWC = mean(bwc)) -> data.aggr
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("condition","threshold"))
DT::datatable(nice(main_anova_summary))
emmip(main_anova_summary, condition~threshold)

grouped_ggwithinstats(
data = data.aggr,
x = condition,
y = meanBWC,
grouping.var = threshold,
type = "np",
bf.message = FALSE,
)

Grouped by scale, condition, subject and age_cat
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "bwc") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition, Age_cat) %>% summarise(meanBWC = mean(bwc)) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("condition","threshold"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
emmip(main_anova_summary, condition~Age_cat)

# looking at threshold = 3.5
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("condition","threshold"), between = "Age_cat")
EMM <- emmeans(main_anova_summary, ~condition:Age_cat, at=list(threshold="X3.5")) %>% contrast(interaction = c( "consec", "consec"))
DT::datatable(EMM %>% as.data.frame())
# data.aggr %>% ungroup() %>%
# nest_by(threshold) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meanBWC", data, within ="condition", between="Age_cat")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# DT::datatable(anova_summary)
#
# # aw <- aov_ez("Subj_ID", "meanDegree", data.aggr, within ="condition", between="Age_cat")
# # p_an <- afex_plot(aw, x = "condition", trace = "Age_cat") + ggtitle("test") + theme(legend.position = c(0.87, 0.15),legend.key.size = unit(0.3, "cm"))
#
# # plot anovas
#
# d_nested <- data.aggr %>% ungroup() %>%
# nest_by(threshold)
#
# d_plots <-
# d_nested %>%
# mutate(aov = list(map(data,~aov_ez("Subj_ID", "meanBWC", data, within ="condition", between="Age_cat")))) %>%
# mutate(plot = list(map2(aov,threshold,~afex_plot(., x = "condition", trace = "Age_cat") +ggtitle(paste("threshold:",threshold)) + theme(legend.position = c(0.87, 0.15),legend.key.size = unit(0.3, "cm")))))
#
# d_plots$plot_one <- lapply(d_plots$plot, "[[", 1)
#
# library(gridExtra)
# do.call(grid.arrange, c(d_plots$plot_one))
Grouped by scale, condition, subject and network:yeo
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "bwc") %>% left_join(.,network.combined) %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition,name) %>% summarise(meanBWC = mean(bwc)) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("condition","name","threshold"))
DT::datatable(nice(main_anova_summary))
#emmip(main_anova_summary, condition~threshold)
# average across threshold
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("condition","name"))
DT::datatable(nice(main_anova_summary))
EMM <- emmeans(main_anova_summary, ~ condition | name) %>% contrast(interaction = c( "consec", "consec"))
EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
# focus on threshold=3.5
DT::datatable(nice(aov_ez("Subj_ID", "meanBWC", data.aggr %>% filter(threshold=="3.5"),within =c("condition","name"))))
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("condition","name","threshold"))
DT::datatable(nice(main_anova_summary))
EMM <- emmeans(main_anova_summary, ~ condition | name, at=list(threshold="X3.5"))
EMM.unadj <- summary(pairs(EMM), by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(pairs(EMM), by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
# data.aggr %>% ungroup() %>%
# nest_by(threshold,name) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meanBWC", data, within ="condition")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# DT::datatable(anova_summary)
Grouped by scale, condition, subject, age_cat and network:yeo
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "bwc") %>% left_join(.,network.combined) %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition,name,Age_cat) %>% summarise(meanBWC = mean(bwc)) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("condition","name","threshold"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
emmip(main_anova_summary, name~Age_cat | threshold)

emmip(main_anova_summary, ~condition | Age_cat)

# average across threshold
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("condition","name"),between = "Age_cat")
DT::datatable(nice(main_anova_summary))
EMM <- emmeans(main_anova_summary, ~ condition:Age_cat | name) %>% contrast(interaction = c( "consec", "consec"))
EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
# focus on threshold=3.5
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("condition","name","threshold"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
EMM <- emmeans(main_anova_summary, ~ condition:Age_cat | name, at=list(threshold="X3.5")) %>% contrast(interaction = c( "consec", "consec"))
EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
Subgroup analysis: Placebo condition only
# testing
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "bwc") %>% left_join(.,network.combined) %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition,Age_cat) %>% summarise(meanBWC = mean(bwc)) %>% filter(condition=="Placebo") -> data.aggr.age
# regular anova
main_anova_summary_a <- aov_ez("Subj_ID", "meanBWC", data.aggr.age, between = "Age_cat")
nice(main_anova_summary_a)
## Anova Table (Type 3 tests)
##
## Response: meanBWC
## Effect df MSE F ges p.value
## 1 Age_cat 1, 25 458.00 1.94 .072 .176
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
afex_plot(main_anova_summary_a, "Age_cat")

data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "bwc") %>% left_join(.,network.combined) %>% left_join(.,variables_ext) %>% group_by(Subj_ID,condition,Age_cat) %>% summarise(meanBWC = mean(bwc)) %>% filter(condition=="Placebo") -> data.aggr.age
ggbetweenstats(
data = data.aggr.age,
x = Age_cat,
y = meanBWC,
type = "p",
bf.message = FALSE,
)

data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "bwc") %>% left_join(.,network.combined) %>% left_join(.,variables_ext) %>% group_by(Subj_ID,condition,Age) %>% summarise(meanBWC = mean(bwc)) %>% filter(condition=="Placebo") -> data.aggr.age
ggscatterstats(
data = data.aggr.age, ## data frame from which variables are taken
x = Age, ## predictor/independent variable
y = meanBWC ## dependent variabl
)

grouped_ggbetweenstats(
data = data.aggr,
x = Age_cat,
y = meanBWC,
grouping.var = threshold,
type = "p",
bf.message = FALSE,
)

# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("threshold"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "bwc") %>% left_join(.,network.combined) %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition,name,Age_cat) %>% summarise(meanBWC = mean(bwc)) %>% filter(condition=="Placebo") -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("name","threshold"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
emmip(main_anova_summary, name~Age_cat | threshold)

emmip(main_anova_summary, ~ Age_cat)

# average across threshold
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("name"),between = "Age_cat")
DT::datatable(nice(main_anova_summary))
EMM <- emmeans(main_anova_summary, ~ Age_cat | name) %>% contrast(interaction = c( "consec", "consec"))
EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
# focus on threshold=3.5
main_anova_summary <- aov_ez("Subj_ID", "meanBWC", data.aggr,within =c("name","threshold"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
EMM <- emmeans(main_anova_summary, ~ Age_cat | name, at=list(threshold="X3.5")) %>% contrast(interaction = c( "consec", "consec"))
EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
Summary
Global efficiency
Grouped by scale, condition, subject
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "geff") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition) %>% summarise(meangeff = mean(geff)) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meangeff", data.aggr,within =c("condition","threshold"))
DT::datatable(nice(main_anova_summary) )
emmip(main_anova_summary, condition~threshold )

grouped_ggwithinstats(
data = data.aggr,
x = condition,
y = meangeff,
grouping.var = threshold,
type = "np",
bf.message = FALSE,
)

Grouped by scale, condition, subject and age_cat
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "geff") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition, Age_cat) %>% summarise(meangeff = mean(geff)) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meangeff", data.aggr,within =c("condition","threshold"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
# anova averaging across threshold
main_anova_summary <- aov_ez("Subj_ID", "meangeff", data.aggr,within =c("condition"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
# looking at threshold = 3.5
main_anova_summary <- aov_ez("Subj_ID", "meangeff", data.aggr,within =c("condition","threshold"), between = "Age_cat")
EMM <- emmeans(main_anova_summary, ~condition:Age_cat, at=list(threshold="X3.5")) %>% contrast(interaction = c( "consec", "consec"))
DT::datatable(EMM %>% as.data.frame())
# data.aggr %>% ungroup() %>%
# nest_by(threshold) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meangeff", data, within ="condition", between="Age_cat")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# DT::datatable(anova_summary)
# aw <- aov_ez("Subj_ID", "meanDegree", data.aggr, within ="condition", between="Age_cat")
# p_an <- afex_plot(aw, x = "condition", trace = "Age_cat") + ggtitle("test") + theme(legend.position = c(0.87, 0.15),legend.key.size = unit(0.3, "cm"))
# plot anovas
#
# d_nested <- data.aggr %>% ungroup() %>%
# nest_by(threshold)
#
# d_plots <-
# d_nested %>%
# mutate(aov = list(map(data,~aov_ez("Subj_ID", "meangeff", data, within ="condition", between="Age_cat")))) %>%
# mutate(plot = list(map2(aov,threshold,~afex_plot(., x = "condition", trace = "Age_cat") +ggtitle(paste("threshold:",threshold)) + theme(legend.position = c(0.87, 0.15),legend.key.size = unit(0.3, "cm")))))
#
# d_plots$plot_one <- lapply(d_plots$plot, "[[", 1)
#
# library(gridExtra)
# do.call(grid.arrange, c(d_plots$plot_one))
Grouped by scale, condition, subject and network:yeo
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "n_geff") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "n_geff", data.aggr,within =c("network","condition","threshold"))
DT::datatable(nice(main_anova_summary))
emmip(main_anova_summary, network~threshold)

emmip(main_anova_summary, condition~threshold)

emmip(main_anova_summary, condition~threshold | network)

# anova averaging across threshold
main_anova_summary <- aov_ez("Subj_ID", "n_geff", data.aggr,within =c("network","condition"))
DT::datatable(nice(main_anova_summary))
main_anova_summary <- aov_ez("Subj_ID", "n_geff", data.aggr,within =c("network","condition"))
EMM <- emmeans(main_anova_summary, ~ condition | network)
EMM.unadj <- summary(pairs(EMM), by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(pairs(EMM), by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
# looking at threshold = 3.5
main_anova_summary <- aov_ez("Subj_ID", "n_geff", data.aggr,within =c("network","condition","threshold"))
EMM <- emmeans(main_anova_summary, ~ condition | network, at=list(threshold="X3.5"))
EMM.unadj <- summary(pairs(EMM), by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(pairs(EMM), by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
Grouped by scale, condition, subject, age_cat and network:yeo
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "n_geff") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "n_geff", data.aggr,within =c("network","condition","threshold"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
emmip(main_anova_summary, condition~Age_cat | network)

# anova averaging across threshold
main_anova_summary <- aov_ez("Subj_ID", "n_geff", data.aggr,within =c("network","condition"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
main_anova_summary <- aov_ez("Subj_ID", "n_geff", data.aggr,within =c("network","condition"))
EMM <- emmeans(main_anova_summary, ~ condition | network)
EMM.unadj <- summary(pairs(EMM), by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(pairs(EMM), by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
# looking at threshold = 3.5
main_anova_summary <- aov_ez("Subj_ID", "n_geff", data.aggr,within =c("condition","threshold","network"), between = "Age_cat")
EMM <- emmeans(main_anova_summary, ~condition:Age_cat | network, at=list(threshold="X3.5")) %>% contrast(interaction = c( "consec", "consec"))
DT::datatable(EMM %>% as.data.frame())
Summary
Local efficiency
Grouped by scale, condition, subject
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "leff") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition) %>% summarise(meanleff = mean(leff)) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanleff", data.aggr,within =c("condition","threshold"))
DT::datatable(nice(main_anova_summary))
emmip(main_anova_summary, condition~threshold)

grouped_ggwithinstats(
data = data.aggr,
x = condition,
y = meanleff,
grouping.var = threshold,
type = "np",
bf.message = FALSE,
)

Grouped by scale, condition, subject and age_cat
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "leff") %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition, Age_cat) %>% summarise(meanleff = mean(leff)) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanleff", data.aggr,within =c("condition","threshold"), between = "Age_cat")
DT::datatable(nice(main_anova_summary))
main_anova_summary <- aov_ez("Subj_ID", "meanleff", data.aggr,within =c("condition","threshold"), between = "Age_cat")
EMM <- emmeans(main_anova_summary, ~condition:Age_cat, at=list(threshold="X1")) %>% contrast(interaction = c( "consec", "consec"))
EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
# data.aggr %>% ungroup() %>%
# nest_by(threshold) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meanleff", data, within ="condition", between="Age_cat")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# DT::datatable(anova_summary)
# aw <- aov_ez("Subj_ID", "meanDegree", data.aggr, within ="condition", between="Age_cat")
# p_an <- afex_plot(aw, x = "condition", trace = "Age_cat") + ggtitle("test") + theme(legend.position = c(0.87, 0.15),legend.key.size = unit(0.3, "cm"))
# plot anovas
# d_nested <- data.aggr %>% ungroup() %>%
# nest_by(threshold)
#
# d_plots <-
# d_nested %>%
# mutate(aov = list(map(data,~aov_ez("Subj_ID", "meanleff", data, within ="condition", between="Age_cat")))) %>%
# mutate(plot = list(map2(aov,threshold,~afex_plot(., x = "condition", trace = "Age_cat") +ggtitle(paste("threshold:",threshold)) + theme(legend.position = c(0.87, 0.15),legend.key.size = unit(0.3, "cm")))))
#
# d_plots$plot_one <- lapply(d_plots$plot, "[[", 1)
#
# library(gridExtra)
# do.call(grid.arrange, c(d_plots$plot_one))
Grouped by scale, condition, subject and network:yeo
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "leff") %>% left_join(.,network.combined) %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition,name) %>% summarise(meanleff = mean(leff)) -> data.aggr
# # regular anova
main_anova_summary <- afex::aov_ez("Subj_ID", "meanleff", data.aggr,within =c("condition","name","threshold"))
# DT::datatable(nice(main_anova_summary) )
#
# # anova averaging across threshold
# main_anova_summary <- aov_ez("Subj_ID", "meanleff", data.aggr,within =c("condition","name"))
# DT::datatable(nice(main_anova_summary))
#
# # looking at threshold = 1
# main_anova_summary <- aov_ez("Subj_ID", "meanleff", data.aggr,within =c("condition","name","threshold"))
# EMM <- emmeans(main_anova_summary, ~condition | name, at=list(threshold="X1")) %>% contrast(interaction = c( "consec", "consec"))
# EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
# EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
#
# # corrected and uncorrected
# DT::datatable(left_join(EMM.unadj,EMM.fdr))
# data.aggr %>% ungroup() %>%
# nest_by(threshold,name) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meanleff", data, within ="condition")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# DT::datatable(anova_summary)
Grouped by scale, condition, subject, age_cat and network:yeo
data %>% pivot_longer(
cols = starts_with("ROI"),
names_to = "ROI",
values_to = "leff") %>% left_join(.,network.combined) %>% left_join(.,variables_ext) %>% group_by(threshold,Subj_ID,condition,name,Age_cat) %>% summarise(meanleff = mean(leff)) -> data.aggr
# regular anova
main_anova_summary <- aov_ez("Subj_ID", "meanleff", data.aggr,within =c("condition","name","threshold"), between = "Age_cat")
emmip(main_anova_summary, condition~Age_cat | name)

DT::datatable(nice(main_anova_summary))
# anova averaging across threshold
main_anova_summary <- aov_ez("Subj_ID", "meanleff", data.aggr,within =c("condition","name"),between = "Age_cat")
DT::datatable(nice(main_anova_summary) )
# looking at threshold = 1
main_anova_summary <- aov_ez("Subj_ID", "meanleff", data.aggr,within =c("condition","name","threshold"),between = "Age_cat")
EMM <- emmeans(main_anova_summary, ~condition:Age_cat | name, at=list(threshold="X1")) %>% contrast(interaction = c( "consec", "consec"))
EMM.unadj <- summary(EMM, by = NULL, adjust = "none") %>% as.data.frame() %>% dplyr::rename(.,p.value.unadj = p.value)
EMM.fdr <- summary(EMM, by = NULL, adjust = "fdr") %>% as.data.frame() %>% dplyr::rename(.,p.value.fdr = p.value)
# corrected and uncorrected
DT::datatable(left_join(EMM.unadj,EMM.fdr))
# data.aggr %>% ungroup() %>%
# nest_by(threshold,name) %>%
# mutate(Model = list(nice(aov_ez("Subj_ID", "meanleff", data, within ="condition",between="Age_cat")))) %>% select(-data) %>% unnest(Model) -> anova_summary
#
# DT::datatable(anova_summary)
Summary