8_em_net_analysis

#1. Setup

rm(list = ls())

# Sets pseudo random number generator seed to fixed value for reproducibility
set.seed(1)

renv::restore(project = here::here())
- The library is already synchronized with the lockfile.
options(pkgType = "binary")

# Check if package 'here' is installed; if not, install. 
if (!require("here")) 
{ 
  install.packages("here")
  library(here)
}
Loading required package: here
here() starts at C:/Users/Gaming/Desktop/empathy_network
if (!require("pacman")) 
{ 
  install.packages("pacman")
  library(here)
}
Loading required package: pacman
# Increase timeout for downloading packages in case of slow download speed
options(timeout = 300)

# Load all required packages and update to ensure compatibility
pacman::p_load(
  here,
  tidyverse,
  devtools,
  rmarkdown,
  bootnet,
  huge,
  qgraph,
  igraph,
  networktools,
  NetworkComparisonTest,
  EGAnet,
  glue,
  gt,
  cowplot
)

#renv::snapshot()

options(scipen = 999) # Remove scientific notations

options(es.use_symbols = TRUE)

#2. Data Load

# load analysis-ready data
data <- read.csv(here("data",
                      "data_clean",
                      "em_net_analysis_data.csv"))

age_group_t1 <- data %>% 
  select(id, age_group_t1)

age_group_t2 <- data %>% 
  select(id, age_group_t2)

data_long <- data %>% 
  pivot_longer(
    cols = matches("_t[12]$"),
    names_to = c(".value", "time"),
    names_pattern = "(.*)_t([12])"
  ) %>% 
  arrange(id, time) %>% 
  mutate(time = factor(time, levels = c("1", "2"), labels = c("T1", "T2")))

id_vars <- c("id", "site", "language", "gender", "time", "age_group")
vars_to_transform <- setdiff(names(data_long), id_vars)

data_long_npn <- data_long  %>% 
  mutate(
    across(
      all_of(vars_to_transform),
      ~ as.numeric(huge.npn(matrix(.x, ncol = 1), verbose = FALSE))
    )
  )

data_t1 <- data %>% 
  dplyr::select(ends_with("t1"), -c(age_group_t1)) %>%
  huge::huge.npn() %>% 
  as.data.frame() %>%
  rename_with(~ str_remove(., "_t1$"))
Conducting the nonparanormal (npn) transformation via shrunkun ECDF....done.
data_t2 <- data %>% 
  select(ends_with("t2"), -c(age_group_t2)) %>% 
  huge::huge.npn() %>% 
  as.data.frame() %>%
  rename_with(~ str_remove(., "_t2$"))
Conducting the nonparanormal (npn) transformation via shrunkun ECDF....done.

#3. Network Model Estimation

network_ebicglasso_t1 <- estimateNetwork(data_t1,
                                corMethod = "cor_auto",
                                corArgs = list(detectOrdinal = FALSE),
                               default = "EBICglasso", 
                               tuning = 0.5,
                               missing = "fiml"
                           )
Estimating Network. Using package::function:
  - qgraph::EBICglasso for EBIC model selection
    - using glasso::glasso
  - qgraph::cor_auto for correlation computation
    - using lavaan::lavCor
network_ebicglasso_t2 <- estimateNetwork(data_t2,
                                corMethod = "cor_auto",
                                corArgs = list(detectOrdinal = FALSE),
                               default = "EBICglasso", 
                               tuning = 0.5,
                               missing = "fiml"
                           )
Estimating Network. Using package::function:
  - qgraph::EBICglasso for EBIC model selection
    - using glasso::glasso
  - qgraph::cor_auto for correlation computation
    - using lavaan::lavCor

#4. Post-Modeling Assumption Checks

???

#5. Network Description

print(network_ebicglasso_t1)

=== Estimated network ===
Number of nodes: 17 
Number of non-zero edges: 43 / 136 
Mean weight: 0.01928795 
Network stored in object$graph 
 
Default set used: EBICglasso 
 
Use plot(object) to plot estimated network 
Use bootnet(object) to bootstrap edge weights and centrality indices 

Relevant references:

    Friedman, J. H., Hastie, T., & Tibshirani, R. (2008). Sparse inverse covariance estimation with the graphical lasso. Biostatistics, 9 (3), 432-441.
    Foygel, R., & Drton, M. (2010). Extended Bayesian information criteria for Gaussian graphical models. 
    Friedman, J. H., Hastie, T., & Tibshirani, R. (2014). glasso: Graphical lasso estimation of gaussian graphical models. Retrieved from https://CRAN.R-project.org/package=glasso
    Epskamp, S., Cramer, A., Waldorp, L., Schmittmann, V. D., & Borsboom, D. (2012). qgraph: Network visualizations of relationships in psychometric data. Journal of Statistical Software, 48 (1), 1-18.
    Epskamp, S., Borsboom, D., & Fried, E. I. (2018). Estimating psychological networks and their accuracy: a tutorial paper. Multivariate Behavioral Research, 50(1), 195-212.
print(network_ebicglasso_t2)

=== Estimated network ===
Number of nodes: 17 
Number of non-zero edges: 34 / 136 
Mean weight: 0.0180876 
Network stored in object$graph 
 
Default set used: EBICglasso 
 
Use plot(object) to plot estimated network 
Use bootnet(object) to bootstrap edge weights and centrality indices 

Relevant references:

    Friedman, J. H., Hastie, T., & Tibshirani, R. (2008). Sparse inverse covariance estimation with the graphical lasso. Biostatistics, 9 (3), 432-441.
    Foygel, R., & Drton, M. (2010). Extended Bayesian information criteria for Gaussian graphical models. 
    Friedman, J. H., Hastie, T., & Tibshirani, R. (2014). glasso: Graphical lasso estimation of gaussian graphical models. Retrieved from https://CRAN.R-project.org/package=glasso
    Epskamp, S., Cramer, A., Waldorp, L., Schmittmann, V. D., & Borsboom, D. (2012). qgraph: Network visualizations of relationships in psychometric data. Journal of Statistical Software, 48 (1), 1-18.
    Epskamp, S., Borsboom, D., & Fried, E. I. (2018). Estimating psychological networks and their accuracy: a tutorial paper. Multivariate Behavioral Research, 50(1), 195-212.
ei_t1 <- qgraph::centralityTable(network_ebicglasso_t1) %>% 
  filter(measure == "ExpectedInfluence")

#what scale is expected influence on?
ei_t1
     graph type     node           measure       value
1  graph 1   NA       ht ExpectedInfluence  0.36488269
2  graph 1   NA       ec ExpectedInfluence  0.62674678
3  graph 1   NA       pa ExpectedInfluence -0.05301127
4  graph 1   NA       sd ExpectedInfluence -1.90847666
5  graph 1   NA        a ExpectedInfluence -1.12829547
6  graph 1   NA      tom ExpectedInfluence  1.10566140
7  graph 1   NA  flanker ExpectedInfluence  0.22127117
8  graph 1   NA      tec ExpectedInfluence  0.68335732
9  graph 1   NA       wm ExpectedInfluence  0.97001505
10 graph 1   NA     dccs ExpectedInfluence -0.12202181
11 graph 1   NA   cbq_na ExpectedInfluence -1.86619954
12 graph 1   NA  cbq_att ExpectedInfluence -0.59539243
13 graph 1   NA  cbq_shy ExpectedInfluence -1.27002424
14 graph 1   NA emque_ec ExpectedInfluence  0.42878068
15 graph 1   NA emque_af ExpectedInfluence  0.66378850
16 graph 1   NA emque_pa ExpectedInfluence  0.83488181
17 graph 1   NA  csus_pt ExpectedInfluence  1.04403601
qgraph::centralityPlot(network_ebicglasso_t1,
                       include = "ExpectedInfluence")
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_path()`).
Warning: Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).

qgraph::centralityPlot(network_ebicglasso_t2,
                       include = "ExpectedInfluence")
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_path()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).

ei_t2 <- qgraph::centralityTable(network_ebicglasso_t2) %>% 
  filter(measure == "ExpectedInfluence")

ei_t2
     graph type     node           measure       value
1  graph 1   NA       ht ExpectedInfluence  0.55234513
2  graph 1   NA       ec ExpectedInfluence  0.73855876
3  graph 1   NA       pa ExpectedInfluence -0.02689061
4  graph 1   NA       sd ExpectedInfluence -2.06919741
5  graph 1   NA        a ExpectedInfluence -1.34068770
6  graph 1   NA      tom ExpectedInfluence  0.70307530
7  graph 1   NA  flanker ExpectedInfluence  0.17433138
8  graph 1   NA      tec ExpectedInfluence  0.62986172
9  graph 1   NA       wm ExpectedInfluence  1.44827525
10 graph 1   NA     dccs ExpectedInfluence  0.03534386
11 graph 1   NA   cbq_na ExpectedInfluence -1.68538427
12 graph 1   NA  cbq_att ExpectedInfluence -0.56954032
13 graph 1   NA  cbq_shy ExpectedInfluence -1.12018275
14 graph 1   NA emque_ec ExpectedInfluence  0.69784023
15 graph 1   NA emque_af ExpectedInfluence  0.55222052
16 graph 1   NA emque_pa ExpectedInfluence  0.73656857
17 graph 1   NA  csus_pt ExpectedInfluence  0.54346236
centrality_t1 <- qgraph::centrality(network_ebicglasso_t1, R2 = TRUE)
predictability_t1 <- centrality_t1$R2

centrality_t2 <- qgraph::centrality(network_ebicglasso_t2, R2 = TRUE)
predictability_t2 <- centrality_t2$R2
density_manual_t1 <- mean(network_ebicglasso_t1$graph[upper.tri(network_ebicglasso_t1$graph)] != 0)

density_manual_t1
[1] 0.3161765
density_function_t1 <- (NetworkToolbox::conn(getWmat(network_ebicglasso_t1)))$density

density_function_t1
[1] 0.3161765
density_manual_t2 <- mean(network_ebicglasso_t2$graph[upper.tri(network_ebicglasso_t2$graph)] != 0)

density_manual_t2
[1] 0.25
density_function_t2 <- (NetworkToolbox::conn(getWmat(network_ebicglasso_t2)))$density

density_function_t2
[1] 0.25
global_strength_t1 <- (NetworkToolbox::conn(getWmat(network_ebicglasso_t1)))$total

global_ei_t1 <- sum(abs(network_ebicglasso_t1$graph[upper.tri(network_ebicglasso_t1$graph)]))

global_strength_t2 <- (NetworkToolbox::conn(getWmat(network_ebicglasso_t2)))$total

global_ei_t2 <- sum(abs(network_ebicglasso_t2$graph[upper.tri(network_ebicglasso_t2$graph)]))
avg_edge_t1 <- mean(network_ebicglasso_t1$graph[upper.tri(network_ebicglasso_t1$graph)])

avg_edge_t2 <- mean(network_ebicglasso_t2$graph[upper.tri(network_ebicglasso_t2$graph)])

#6. Network Plotting

labels <- c("HT", "EC", "PA", "SD", "AV", "ToM", "Flank", "TEC", "WM", "DCCS", "NA", "ATT", "EXT", "EC", "AF", "PA", "PT")

names <- c("Hypothesis Testing",
           "Empathic Concern", 
           "Prosocial Acts",
           "Self-Distress",
           "Avoidance",
           "Theory of Mind",
           "Flanker",
           "Test of Emotion Comprehension",
           "Working Memory",
           "Dimensional Change Card Sort",
           "Negative Affectivity",
           "Effortful Control of Attention",
           "Extraversion",
           "Emotion Contagion",
           "Attention to Others' Feelings",
           "Prosocial Actions",
           "Perspective-Taking"
           )

groups <- structure(list("Pain Simulation Task" = (1:5), # Assigning groupings (domains) to node/column numbers
                             "Executive Functioning Battery" = c(7, 9, 10),
                             "Perspective-Taking Battery" = c(6, 8),
                             "Children's Behavior Questionnaire" = c(11:13),
                             "Empathy Questionnaire" = c(14:16),
                             "Children's Social Understanding Scale" = c(17)
                         ))
colors <- c("#f8766d", #Sociodemo
              "#c77cff", #Premorbid
              "#00bfc4", #EF
              "#7cae00", #VF
              "#cd9600",
              "#cd3") #Visuo ##Customized ordering of ggplot2 palette

avg_layout <- averageLayout(network_ebicglasso_t1, network_ebicglasso_t2, layout = "spring")
# jpeg(file = here("output", "figures", "em_net_ebicglasso_mds_t1.jpg"),
#     width = 1200, # The width of the plot in inches
#     height = 1200) # The height of the plot in inches
# 
# L <- layout_with_mds(graph_from_adjacency_matrix(abs(getWmat(network_ebicglasso_t1)),
#                                                  mode = "undirected",
#                                                  weighted = TRUE,
#                                                  diag = FALSE))
# 
# plot(network_ebicglasso_t1,
#      layout = L,
#      minimum = 0.05,
#      labels = labels,
#      pie = predictability_t1,
#      groups = groups,
#      nodeNames = names,
#      color = colors,
#      legend.mode = "style1",
#      borders = TRUE,
#      title = "Empathy Network Time 1",
#      title.cex = 1.5,
#      theme = "colorblind",
#      normalize = TRUE,
#      repulsion = 1.5, curveAll = TRUE, curveDefault = .25)
# 
# # run dev.off() to create the file
# dev.off()

jpeg(file = here("output", "figures", "em_net_ebicglasso_fr_t1.jpg"),
     width = 15,
     height = 9,
     units = "in",
     res = 500)

network_ebicglasso_t1_plot <- plot(network_ebicglasso_t1,
     layout = avg_layout,
     labels = labels,
     minimum = 0.00, 
     pie = predictability_t1,
     groups = groups,
     nodeNames = names,
     color = colors,
     legend.mode = "style1",
     legend.cex = 0.7,
     borders = TRUE,
     title = "Empathy Network Time 1",
     title.cex = 1.5,
     theme = "colorblind",
     normalize = TRUE
     )

# run dev.off() to create the file
dev.off()
png 
  2 
# jpeg(file = here("output", "figures", "em_net_ebicglasso_mds_t2.jpg"),
#      width = 15,
#      height = 9,
#      units = "in",
#      res = 500)
# 
# L <- layout_with_mds(graph_from_adjacency_matrix(abs(getWmat(network_ebicglasso_t2)),
#                                                  mode = "undirected",
#                                                  weighted = TRUE,
#                                                  diag = FALSE))
# 
# plot(network_ebicglasso_t2,
#      layout = L,
#      minimum = 0.05,
#      labels = labels,
#      minimum = 0.05, 
#      pie = predictability_t1,
#      groups = groups,
#      nodeNames = names,
#      color = colors,
#      legend.mode = "style1",
#      borders = TRUE,
#      title = "Empathy Network Time 2",
#      title.cex = 1.5,
#      theme = "colorblind",
#      normalize = TRUE,
#      repel = 1,
#      curveAll = TRUE)
# 
# # run dev.off() to create the file
# dev.off()

jpeg(file = here("output", "figures", "em_net_ebicglasso_fr_t2.jpg"),
     width = 15,
     height = 9,
     units = "in",
     res = 500)

network_ebicglasso_t2_plot <- plot(network_ebicglasso_t2,
     layout = avg_layout,
     labels = labels,
     minimum = 0.00, 
     pie = predictability_t2,
     groups = groups,
     nodeNames = names,
     color = colors,
     legend.mode = "style1",
     legend.cex = 0.7,
     borders = TRUE,
     title = "Empathy Network Time 2",
     title.cex = 1.5,
     theme = "colorblind",
     normalize = TRUE
     )

# run dev.off() to create the file
dev.off()
png 
  2 

#7. Network Stability

if (file.exists(here("output", "models", "networks", "boot_edge_t1.rds"))) {
# load saved file
boot_edge_t1 <- readRDS(here("output", "models", "networks", "boot_edge_t1.rds"))

# summary results
print(summary(boot_edge_t1))

# Plot bootstrapped edge CIs:
plot(boot_edge_t1, order = "sample", labels = FALSE)
} else {
# bootstrap 100 values, using 8 cores:
boot_edge_t1 <- bootnet(network_ebicglasso_t1,
                        type = "nonparametric",
                        nCores = 6,
                        nBoots = 2500)

# save results
saveRDS(boot_edge_t1, file = here("output", "models", "networks", "boot_edge_t1.rds"))  

# summary results
print(summary(boot_edge_t1))

# Plot bootstrapped edge CIs:
plot(boot_edge_t1, order = "sample", labels = FALSE)
}
# A tibble: 153 × 17
# Groups:   type, node1, node2 [153]
   type  id         node1 node2 sample     mean      sd  CIlower CIupper    q2.5
   <chr> <chr>      <chr> <chr>  <dbl>    <dbl>   <dbl>    <dbl>   <dbl>   <dbl>
 1 edge  a--cbq_att a     cbq_… 0      -8.41e-4 0.00601 -0.0120  0.0120  -0.0134
 2 edge  a--cbq_na  a     cbq_… 0      -3.24e-3 0.0119  -0.0238  0.0238  -0.0461
 3 edge  a--cbq_shy a     cbq_… 0       1.62e-3 0.00855 -0.0171  0.0171   0     
 4 edge  a--csus_pt a     csus… 0       5.27e-4 0.00455 -0.00909 0.00909  0     
 5 edge  a--dccs    a     dccs  0.0406  3.04e-2 0.0385  -0.0364  0.118    0     
 6 edge  a--emque_… a     emqu… 0      -3.12e-4 0.00394 -0.00787 0.00787  0     
 7 edge  a--emque_… a     emqu… 0      -2.46e-4 0.00299 -0.00597 0.00597  0     
 8 edge  a--emque_… a     emqu… 0       1.25e-3 0.00678 -0.0136  0.0136   0     
 9 edge  a--flanker a     flan… 0       5.90e-4 0.00510 -0.0102  0.0102   0     
10 edge  a--tec     a     tec   0      -2.36e-4 0.00307 -0.00615 0.00615  0     
# ℹ 143 more rows
# ℹ 7 more variables: q97.5 <dbl>, q2.5_non0 <dbl>, mean_non0 <dbl>,
#   q97.5_non0 <dbl>, var_non0 <dbl>, sd_non0 <dbl>, prop0 <dbl>

if (file.exists(here("output", "models", "networks", "boot_edge_t2.rds"))) {
# load saved file
boot_edge_t2 <- readRDS(here("output", "models", "networks", "boot_edge_t2.rds"))

# summary results
print(summary(boot_edge_t2))

# Plot bootstrapped edge CIs:
plot(boot_edge_t2, order = "sample", labels = FALSE)
} else {
# bootstrap 100 values, using 8 cores:
boot_edge_t2 <- bootnet(network_ebicglasso_t2,
                        type = "nonparametric",
                        nCores = 6,
                        nBoots = 2500)

# save results
saveRDS(boot_edge_t2, file = here("output", "models", "networks", "boot_edge_t2.rds"))  

# summary results
print(summary(boot_edge_t2))

# Plot bootstrapped edge CIs:
plot(boot_edge_t2, order = "sample", labels = FALSE)
}
# A tibble: 153 × 17
# Groups:   type, node1, node2 [153]
   type  id         node1 node2 sample     mean      sd  CIlower CIupper    q2.5
   <chr> <chr>      <chr> <chr>  <dbl>    <dbl>   <dbl>    <dbl>   <dbl>   <dbl>
 1 edge  a--cbq_att a     cbq_…      0  5.14e-4 0.00639 -0.0128  0.0128   0     
 2 edge  a--cbq_na  a     cbq_…      0  4.72e-5 0.00506 -0.0101  0.0101   0     
 3 edge  a--cbq_shy a     cbq_…      0  6.52e-4 0.00539 -0.0108  0.0108   0     
 4 edge  a--csus_pt a     csus…      0 -1.01e-3 0.00609 -0.0122  0.0122  -0.0180
 5 edge  a--dccs    a     dccs       0  1.62e-3 0.00873 -0.0175  0.0175   0     
 6 edge  a--emque_… a     emqu…      0 -1.26e-3 0.00711 -0.0142  0.0142  -0.0219
 7 edge  a--emque_… a     emqu…      0 -7.16e-4 0.00555 -0.0111  0.0111  -0.0101
 8 edge  a--emque_… a     emqu…      0 -9.61e-5 0.00270 -0.00539 0.00539  0     
 9 edge  a--flanker a     flan…      0 -5.71e-3 0.0162  -0.0323  0.0323  -0.0624
10 edge  a--tec     a     tec        0 -2.86e-4 0.00407 -0.00814 0.00814  0     
# ℹ 143 more rows
# ℹ 7 more variables: q97.5 <dbl>, q2.5_non0 <dbl>, mean_non0 <dbl>,
#   q97.5_non0 <dbl>, var_non0 <dbl>, sd_non0 <dbl>, prop0 <dbl>

if (file.exists(here("output", "models", "networks", "boot_ei_t1.rds"))) {
# load saved file
boot_ei_t1 <- readRDS(here("output", "models", "networks", "boot_ei_t1.rds"))

# Compute CS-coefficient
print(corStability(boot_ei_t1))

# Plot centrality stability:
plot(boot_ei_t1, statistics = "expectedInfluence")
} else {
# Bootstrap 1000 values, using 8 cores:
boot_ei_t1 <- bootnet(network_ebicglasso_t1, nBoots = 2500, nCores = 6,
type = "case", statistics = "expectedInfluence")

# save results
saveRDS(boot_ei_t1, file = here("output", "models", "networks", "boot_ei_t1.rds"))

# Compute CS-coefficient
print(corStability(boot_ei_t1))

# Plot centrality stability:
plot(boot_ei_t1, statistics = "expectedInfluence")
}
=== Correlation Stability Analysis === 

Sampling levels tested:
   nPerson Drop%   n
1      120  75.0 245
2      157  67.3 248
3      195  59.4 214
4      232  51.7 253
5      269  44.0 261
6      307  36.0 251
7      344  28.3 246
8      381  20.6 267
9      419  12.7 265
10     456   5.0 250

Maximum drop proportions to retain correlation of 0.7 in at least 95% of the samples:

expectedInfluence: 0.594 
  - For more accuracy, run bootnet(..., caseMin = 0.517, caseMax = 0.673) 

Accuracy can also be increased by increasing both 'nBoots' and 'caseN'.expectedInfluence 
          0.59375 

if (file.exists(here("output", "models", "networks", "boot_ei_t2.rds"))) {
# load saved file
boot_ei_t2 <- readRDS(here("output", "models", "networks", "boot_ei_t2.rds"))

# Compute CS-coefficient
print(corStability(boot_ei_t2))

# Plot centrality stability:
plot(boot_ei_t2, statistics = "expectedInfluence")
} else {
# Bootstrap 1000 values, using 8 cores:
boot_ei_t2 <- bootnet(network_ebicglasso_t2, nBoots = 2500, nCores = 6,
type = "case", statistics = "expectedInfluence")

# save results
saveRDS(boot_ei_t2, file = here("output", "models", "networks", "boot_ei_t2.rds"))

# Compute CS-coefficient
print(corStability(boot_ei_t2))

# Plot centrality stability:
plot(boot_ei_t2, statistics = "expectedInfluence")
}
=== Correlation Stability Analysis === 

Sampling levels tested:
   nPerson Drop%   n
1      120  75.0 231
2      157  67.3 245
3      195  59.4 261
4      232  51.7 247
5      269  44.0 260
6      307  36.0 263
7      344  28.3 248
8      381  20.6 238
9      419  12.7 259
10     456   5.0 248

Maximum drop proportions to retain correlation of 0.7 in at least 95% of the samples:

expectedInfluence: 0.594 
  - For more accuracy, run bootnet(..., caseMin = 0.517, caseMax = 0.673) 

Accuracy can also be increased by increasing both 'nBoots' and 'caseN'.expectedInfluence 
          0.59375 

#8. Within-Time Network Comparison

data_t1_4 <- data %>% 
  filter(age_group_t1 == 4) %>% 
  select(ends_with("_t1"), -c(id, site, language, gender, age_group_t1, age_group_t2))

data_t1_5 <- data %>% 
  filter(age_group_t1 == 5) %>% 
  select(ends_with("_t1"), -c(id, site, language, gender, age_group_t1, age_group_t2))

data_t1_6 <- data %>% 
  filter(age_group_t1 == 6) %>% 
  select(ends_with("_t1"), -c(id, site, language, gender, age_group_t1, age_group_t2))
data_t2_5 <- data %>% 
  filter(age_group_t2 == 5) %>% 
  select(ends_with("_t2"), -c(id, site, language, gender, age_group_t1, age_group_t2))

data_t2_6 <- data %>% 
  filter(age_group_t2 == 6) %>% 
  select(ends_with("_t2"), -c(id, site, language, gender, age_group_t1, age_group_t2))

data_t2_7 <- data %>% 
  filter(age_group_t2 == 7) %>% 
  select(ends_with("_t2"), -c(id, site, language, gender, age_group_t1, age_group_t2))
network_ebicglasso_t1_4 <- estimateNetwork(data_t1_4,
                                corMethod = "cor_auto", 
                               default = "EBICglasso", 
                               tuning = 0.5,
                               missing = "fiml",
                               corArgs = list(detectOrdinal = FALSE)
                           )
Estimating Network. Using package::function:
  - qgraph::EBICglasso for EBIC model selection
    - using glasso::glasso
  - qgraph::cor_auto for correlation computation
    - using lavaan::lavCor
network_ebicglasso_t1_5 <- estimateNetwork(data_t1_5,
                                corMethod = "cor_auto", 
                               default = "EBICglasso", 
                               tuning = 0.5,
                               missing = "fiml",
                               corArgs = list(detectOrdinal = FALSE)
                           )
Estimating Network. Using package::function:
  - qgraph::EBICglasso for EBIC model selection
    - using glasso::glasso
  - qgraph::cor_auto for correlation computation
    - using lavaan::lavCor
network_ebicglasso_t1_6 <- estimateNetwork(data_t1_6,
                                corMethod = "cor_auto", 
                               default = "EBICglasso", 
                               tuning = 0.5,
                               missing = "fiml",
                               corArgs = list(detectOrdinal = FALSE)
                           )
Estimating Network. Using package::function:
  - qgraph::EBICglasso for EBIC model selection
    - using glasso::glasso
  - qgraph::cor_auto for correlation computation
    - using lavaan::lavCor
network_ebicglasso_t2_5 <- estimateNetwork(data_t2_5,
                                corMethod = "cor_auto", 
                               default = "EBICglasso", 
                               tuning = 0.5,
                               missing = "fiml",
                               corArgs = list(detectOrdinal = FALSE)
                           )
Estimating Network. Using package::function:
  - qgraph::EBICglasso for EBIC model selection
    - using glasso::glasso
  - qgraph::cor_auto for correlation computation
    - using lavaan::lavCor
network_ebicglasso_t2_6 <- estimateNetwork(data_t2_6,
                                corMethod = "cor_auto", 
                               default = "EBICglasso", 
                               tuning = 0.5,
                               missing = "fiml",
                               corArgs = list(detectOrdinal = FALSE)
                           )
Estimating Network. Using package::function:
  - qgraph::EBICglasso for EBIC model selection
    - using glasso::glasso
  - qgraph::cor_auto for correlation computation
    - using lavaan::lavCor
network_ebicglasso_t2_7 <- estimateNetwork(data_t2_7,
                                corMethod = "cor_auto", 
                               default = "EBICglasso", 
                               tuning = 0.5,
                               missing = "fiml",
                               corArgs = list(detectOrdinal = FALSE)
                           )
Estimating Network. Using package::function:
  - qgraph::EBICglasso for EBIC model selection
    - using glasso::glasso
  - qgraph::cor_auto for correlation computation
    - using lavaan::lavCor

Network Comparison T1

if (file.exists(here("output", "models", "networks", "nct_4vs5_t1.rds"))) {
  
  nct_4vs5_t1 <- readRDS(here("output", "models", "networks", "nct_4vs5_t1.rds"))
  
  summary(nct_4vs5_t1)

  plot(nct_4vs5_t1, what = "strength" )

  plot(nct_4vs5_t1, what = "network")

  #plot(nct_4vs5_t1, what = "centrality")

  #plot(nct_4vs5_t1, what = "edge")
  
} else {nct_4vs5_t1 <- NetworkComparisonTest::NCT(network_ebicglasso_t1_4,
                           network_ebicglasso_t1_5,
                           gamma = 0.5,
                           it = 5000,
                           abs = TRUE, 
                           edges = "yes",
                           test.edges = TRUE,
                           test.centrality = TRUE,
                           centrality = "expectedInfluence",
                           p.adjust.methods = "BH")

saveRDS(nct_4vs5_t1,
        file = here("output", "models", "networks", "nct_4vs5_t1.rds"))

summary(nct_4vs5_t1)

plot(nct_4vs5_t1, what = "strength" )

plot(nct_4vs5_t1, what = "network")

#plot(nct_4vs5_t1, what = "centrality")

#plot(nct_4vs5_t1, what = "edge")
}
 INDEPENDENT GROUPS GAUSSIAN NETWORK COMPARISON TEST 

 P-VALUE CORRECTION: BH 

 NETWORK INVARIANCE TEST 
 Test statistic M: 0.1678017 
 p-value 0.6314737 

 GLOBAL STRENGTH INVARIANCE TEST 
 Global strength per group:  1.627663 0.8833639 
 Test statistic S:  0.7442992 
 p-value 0.4613077

 EDGE INVARIANCE TEST 
           Var1        Var2 p-value Test statistic E
18        ht_t1       ec_t1       1       0.07223540
35        ht_t1       pa_t1       1       0.07614103
36        ec_t1       pa_t1       1       0.09192608
52        ht_t1       sd_t1       1       0.00000000
53        ec_t1       sd_t1       1       0.02392299
54        pa_t1       sd_t1       1       0.02856591
69        ht_t1        a_t1       1       0.00000000
70        ec_t1        a_t1       1       0.00000000
71        pa_t1        a_t1       1       0.00000000
72        sd_t1        a_t1       1       0.00000000
86        ht_t1      tom_t1       1       0.00000000
87        ec_t1      tom_t1       1       0.00000000
88        pa_t1      tom_t1       1       0.00000000
89        sd_t1      tom_t1       1       0.00000000
90         a_t1      tom_t1       1       0.00000000
103       ht_t1  flanker_t1       1       0.00000000
104       ec_t1  flanker_t1       1       0.00000000
105       pa_t1  flanker_t1       1       0.00000000
106       sd_t1  flanker_t1       1       0.00000000
107        a_t1  flanker_t1       1       0.00000000
108      tom_t1  flanker_t1       1       0.00000000
120       ht_t1      tec_t1       1       0.00000000
121       ec_t1      tec_t1       1       0.00000000
122       pa_t1      tec_t1       1       0.00000000
123       sd_t1      tec_t1       1       0.00000000
124        a_t1      tec_t1       1       0.00000000
125      tom_t1      tec_t1       1       0.04285243
126  flanker_t1      tec_t1       1       0.00000000
137       ht_t1       wm_t1       1       0.00000000
138       ec_t1       wm_t1       1       0.00000000
139       pa_t1       wm_t1       1       0.00000000
140       sd_t1       wm_t1       1       0.00000000
141        a_t1       wm_t1       1       0.00000000
142      tom_t1       wm_t1       1       0.00000000
143  flanker_t1       wm_t1       1       0.00000000
144      tec_t1       wm_t1       1       0.00000000
154       ht_t1     dccs_t1       1       0.00000000
155       ec_t1     dccs_t1       1       0.00000000
156       pa_t1     dccs_t1       1       0.00000000
157       sd_t1     dccs_t1       1       0.00000000
158        a_t1     dccs_t1       1       0.00000000
159      tom_t1     dccs_t1       1       0.00000000
160  flanker_t1     dccs_t1       1       0.00000000
161      tec_t1     dccs_t1       1       0.00000000
162       wm_t1     dccs_t1       1       0.00000000
171       ht_t1   cbq_na_t1       1       0.00000000
172       ec_t1   cbq_na_t1       1       0.00000000
173       pa_t1   cbq_na_t1       1       0.00000000
174       sd_t1   cbq_na_t1       1       0.00000000
175        a_t1   cbq_na_t1       1       0.00000000
176      tom_t1   cbq_na_t1       1       0.00000000
177  flanker_t1   cbq_na_t1       1       0.00000000
178      tec_t1   cbq_na_t1       1       0.00000000
179       wm_t1   cbq_na_t1       1       0.00000000
180     dccs_t1   cbq_na_t1       1       0.00000000
188       ht_t1  cbq_att_t1       1       0.00000000
189       ec_t1  cbq_att_t1       1       0.00000000
190       pa_t1  cbq_att_t1       1       0.00000000
191       sd_t1  cbq_att_t1       1       0.00000000
192        a_t1  cbq_att_t1       1       0.00000000
193      tom_t1  cbq_att_t1       1       0.00000000
194  flanker_t1  cbq_att_t1       1       0.00000000
195      tec_t1  cbq_att_t1       1       0.00000000
196       wm_t1  cbq_att_t1       1       0.00000000
197     dccs_t1  cbq_att_t1       1       0.00000000
198   cbq_na_t1  cbq_att_t1       1       0.00000000
205       ht_t1  cbq_shy_t1       1       0.00000000
206       ec_t1  cbq_shy_t1       1       0.00000000
207       pa_t1  cbq_shy_t1       1       0.00000000
208       sd_t1  cbq_shy_t1       1       0.00000000
209        a_t1  cbq_shy_t1       1       0.00000000
210      tom_t1  cbq_shy_t1       1       0.00000000
211  flanker_t1  cbq_shy_t1       1       0.00000000
212      tec_t1  cbq_shy_t1       1       0.00000000
213       wm_t1  cbq_shy_t1       1       0.00000000
214     dccs_t1  cbq_shy_t1       1       0.00000000
215   cbq_na_t1  cbq_shy_t1       1       0.12855704
216  cbq_att_t1  cbq_shy_t1       1       0.00000000
222       ht_t1 emque_ec_t1       1       0.00000000
223       ec_t1 emque_ec_t1       1       0.00000000
224       pa_t1 emque_ec_t1       1       0.00000000
225       sd_t1 emque_ec_t1       1       0.00000000
226        a_t1 emque_ec_t1       1       0.00000000
227      tom_t1 emque_ec_t1       1       0.00000000
228  flanker_t1 emque_ec_t1       1       0.00000000
229      tec_t1 emque_ec_t1       1       0.00000000
230       wm_t1 emque_ec_t1       1       0.00000000
231     dccs_t1 emque_ec_t1       1       0.00000000
232   cbq_na_t1 emque_ec_t1       1       0.00000000
233  cbq_att_t1 emque_ec_t1       1       0.00000000
234  cbq_shy_t1 emque_ec_t1       1       0.00000000
239       ht_t1 emque_af_t1       1       0.00000000
240       ec_t1 emque_af_t1       1       0.00000000
241       pa_t1 emque_af_t1       1       0.00000000
242       sd_t1 emque_af_t1       1       0.00000000
243        a_t1 emque_af_t1       1       0.00000000
244      tom_t1 emque_af_t1       1       0.00000000
245  flanker_t1 emque_af_t1       1       0.00000000
246      tec_t1 emque_af_t1       1       0.00000000
247       wm_t1 emque_af_t1       1       0.00000000
248     dccs_t1 emque_af_t1       1       0.00000000
249   cbq_na_t1 emque_af_t1       1       0.00000000
250  cbq_att_t1 emque_af_t1       1       0.00000000
251  cbq_shy_t1 emque_af_t1       1       0.00000000
252 emque_ec_t1 emque_af_t1       1       0.05317371
256       ht_t1 emque_pa_t1       1       0.00000000
257       ec_t1 emque_pa_t1       1       0.00000000
258       pa_t1 emque_pa_t1       1       0.00000000
259       sd_t1 emque_pa_t1       1       0.00000000
260        a_t1 emque_pa_t1       1       0.00000000
261      tom_t1 emque_pa_t1       1       0.00000000
262  flanker_t1 emque_pa_t1       1       0.00000000
263      tec_t1 emque_pa_t1       1       0.00000000
264       wm_t1 emque_pa_t1       1       0.00000000
265     dccs_t1 emque_pa_t1       1       0.00000000
266   cbq_na_t1 emque_pa_t1       1       0.00000000
267  cbq_att_t1 emque_pa_t1       1       0.00000000
268  cbq_shy_t1 emque_pa_t1       1       0.00000000
269 emque_ec_t1 emque_pa_t1       1       0.16780171
270 emque_af_t1 emque_pa_t1       1       0.10887133
273       ht_t1  csus_pt_t1       1       0.00000000
274       ec_t1  csus_pt_t1       1       0.00000000
275       pa_t1  csus_pt_t1       1       0.00000000
276       sd_t1  csus_pt_t1       1       0.00000000
277        a_t1  csus_pt_t1       1       0.00000000
278      tom_t1  csus_pt_t1       1       0.00000000
279  flanker_t1  csus_pt_t1       1       0.00000000
280      tec_t1  csus_pt_t1       1       0.00000000
281       wm_t1  csus_pt_t1       1       0.04029740
282     dccs_t1  csus_pt_t1       1       0.00000000
283   cbq_na_t1  csus_pt_t1       1       0.00000000
284  cbq_att_t1  csus_pt_t1       1       0.00000000
285  cbq_shy_t1  csus_pt_t1       1       0.00000000
286 emque_ec_t1  csus_pt_t1       1       0.00000000
287 emque_af_t1  csus_pt_t1       1       0.00000000
288 emque_pa_t1  csus_pt_t1       1       0.01493197


 CENTRALITY INVARIANCE TEST 
 Nodes tested: ht_t1 ec_t1 pa_t1 sd_t1 a_t1 tom_t1 flanker_t1 tec_t1 wm_t1 dccs_t1 cbq_na_t1 cbq_att_t1 cbq_shy_t1 emque_ec_t1 emque_af_t1 emque_pa_t1 csus_pt_t1 
 Centralities tested: expectedInfluence
 Test statistics C: 
            expectedInfluence
ht_t1              0.14837643
ec_t1              0.18808448
pa_t1              0.19663302
sd_t1              0.05248890
a_t1               0.00000000
tom_t1             0.04285243
flanker_t1         0.00000000
tec_t1             0.04285243
wm_t1              0.04029740
dccs_t1            0.00000000
cbq_na_t1         -0.12855704
cbq_att_t1         0.00000000
cbq_shy_t1        -0.12855704
emque_ec_t1        0.22097542
emque_af_t1        0.16204504
emque_pa_t1        0.29160501
csus_pt_t1         0.05522937

 p-values: 
            expectedInfluence
ht_t1               0.7225444
ec_t1               0.7225444
pa_t1               0.7225444
sd_t1               1.0000000
a_t1                1.0000000
tom_t1              0.7676798
flanker_t1          1.0000000
tec_t1              0.7225444
wm_t1               0.7561942
dccs_t1             1.0000000
cbq_na_t1           0.7225444
cbq_att_t1          1.0000000
cbq_shy_t1          0.7225444
emque_ec_t1         0.7225444
emque_af_t1         0.7561942
emque_pa_t1         0.7225444
csus_pt_t1          0.7225444

if (file.exists(here("output", "models", "networks", "nct_5vs6_t1.rds"))) {
  
  nct_5vs6_t1 <- readRDS(here("output", "models", "networks", "nct_5vs6_t1.rds"))
  
  summary(nct_5vs6_t1)

  plot(nct_5vs6_t1, what = "strength" )

  plot(nct_5vs6_t1, what = "network")

  #plot(nct_4vs6, what = "centrality")

  #plot(nct_4vs6, what = "edge")
  
} else {nct_5vs6_t1 <- NetworkComparisonTest::NCT(network_ebicglasso_t1_5,
                           network_ebicglasso_t1_6,
                           gamma = 0.5,
                           it = 5000,
                           abs = TRUE, 
                           edges = "yes",
                           test.edges = TRUE,
                           test.centrality = TRUE,
                           centrality = "expectedInfluence",
                           p.adjust.methods = "BH")

saveRDS(nct_5vs6_t1,
        file = here("output", "models", "networks", "nct_5vs6_t1.rds"))

summary(nct_5vs6_t1)

plot(nct_5vs6_t1, what = "strength" )

plot(nct_5vs6_t1, what = "network")

#plot(nct_5vs6, what = "centrality")

#plot(nct_5vs6, what = "edge")

}
 INDEPENDENT GROUPS GAUSSIAN NETWORK COMPARISON TEST 

 P-VALUE CORRECTION: BH 

 NETWORK INVARIANCE TEST 
 Test statistic M: 0.2757188 
 p-value 0.1119776 

 GLOBAL STRENGTH INVARIANCE TEST 
 Global strength per group:  0.8833639 2.756422 
 Test statistic S:  1.873059 
 p-value 0.06178764

 EDGE INVARIANCE TEST 
           Var1        Var2    p-value Test statistic E
18        ht_t1       ec_t1 1.00000000       0.05152787
35        ht_t1       pa_t1 0.70705859       0.08418545
36        ec_t1       pa_t1 0.72820991       0.23646091
52        ht_t1       sd_t1 1.00000000       0.00000000
53        ec_t1       sd_t1 1.00000000       0.11408036
54        pa_t1       sd_t1 1.00000000       0.08142363
69        ht_t1        a_t1 1.00000000       0.00000000
70        ec_t1        a_t1 0.71482846       0.13591175
71        pa_t1        a_t1 1.00000000       0.00000000
72        sd_t1        a_t1 1.00000000       0.00000000
86        ht_t1      tom_t1 0.17676465       0.03342778
87        ec_t1      tom_t1 1.00000000       0.00000000
88        pa_t1      tom_t1 1.00000000       0.00000000
89        sd_t1      tom_t1 1.00000000       0.00000000
90         a_t1      tom_t1 1.00000000       0.00000000
103       ht_t1  flanker_t1 1.00000000       0.00000000
104       ec_t1  flanker_t1 1.00000000       0.00000000
105       pa_t1  flanker_t1 1.00000000       0.00000000
106       sd_t1  flanker_t1 1.00000000       0.00000000
107        a_t1  flanker_t1 1.00000000       0.00000000
108      tom_t1  flanker_t1 1.00000000       0.00000000
120       ht_t1      tec_t1 1.00000000       0.00000000
121       ec_t1      tec_t1 1.00000000       0.00000000
122       pa_t1      tec_t1 1.00000000       0.00000000
123       sd_t1      tec_t1 1.00000000       0.00000000
124        a_t1      tec_t1 1.00000000       0.00000000
125      tom_t1      tec_t1 1.00000000       0.00000000
126  flanker_t1      tec_t1 1.00000000       0.00000000
137       ht_t1       wm_t1 1.00000000       0.00000000
138       ec_t1       wm_t1 1.00000000       0.00000000
139       pa_t1       wm_t1 1.00000000       0.00000000
140       sd_t1       wm_t1 1.00000000       0.00000000
141        a_t1       wm_t1 1.00000000       0.00000000
142      tom_t1       wm_t1 1.00000000       0.14910245
143  flanker_t1       wm_t1 1.00000000       0.00000000
144      tec_t1       wm_t1 1.00000000       0.05448537
154       ht_t1     dccs_t1 1.00000000       0.00000000
155       ec_t1     dccs_t1 1.00000000       0.00000000
156       pa_t1     dccs_t1 1.00000000       0.00000000
157       sd_t1     dccs_t1 1.00000000       0.00000000
158        a_t1     dccs_t1 1.00000000       0.00000000
159      tom_t1     dccs_t1 1.00000000       0.00000000
160  flanker_t1     dccs_t1 1.00000000       0.00000000
161      tec_t1     dccs_t1 1.00000000       0.00000000
162       wm_t1     dccs_t1 1.00000000       0.00000000
171       ht_t1   cbq_na_t1 1.00000000       0.00000000
172       ec_t1   cbq_na_t1 1.00000000       0.00000000
173       pa_t1   cbq_na_t1 1.00000000       0.00000000
174       sd_t1   cbq_na_t1 1.00000000       0.00000000
175        a_t1   cbq_na_t1 1.00000000       0.00000000
176      tom_t1   cbq_na_t1 0.08158368       0.03597011
177  flanker_t1   cbq_na_t1 1.00000000       0.00000000
178      tec_t1   cbq_na_t1 1.00000000       0.00000000
179       wm_t1   cbq_na_t1 1.00000000       0.00000000
180     dccs_t1   cbq_na_t1 1.00000000       0.00000000
188       ht_t1  cbq_att_t1 1.00000000       0.00000000
189       ec_t1  cbq_att_t1 1.00000000       0.00000000
190       pa_t1  cbq_att_t1 1.00000000       0.00000000
191       sd_t1  cbq_att_t1 1.00000000       0.00000000
192        a_t1  cbq_att_t1 1.00000000       0.00000000
193      tom_t1  cbq_att_t1 1.00000000       0.00000000
194  flanker_t1  cbq_att_t1 1.00000000       0.00000000
195      tec_t1  cbq_att_t1 1.00000000       0.00000000
196       wm_t1  cbq_att_t1 1.00000000       0.00000000
197     dccs_t1  cbq_att_t1 1.00000000       0.00000000
198   cbq_na_t1  cbq_att_t1 1.00000000       0.00000000
205       ht_t1  cbq_shy_t1 1.00000000       0.00000000
206       ec_t1  cbq_shy_t1 1.00000000       0.09906200
207       pa_t1  cbq_shy_t1 1.00000000       0.03466039
208       sd_t1  cbq_shy_t1 1.00000000       0.00000000
209        a_t1  cbq_shy_t1 1.00000000       0.00000000
210      tom_t1  cbq_shy_t1 1.00000000       0.00000000
211  flanker_t1  cbq_shy_t1 1.00000000       0.00000000
212      tec_t1  cbq_shy_t1 1.00000000       0.00000000
213       wm_t1  cbq_shy_t1 1.00000000       0.00000000
214     dccs_t1  cbq_shy_t1 1.00000000       0.00000000
215   cbq_na_t1  cbq_shy_t1 0.71725655       0.27571878
216  cbq_att_t1  cbq_shy_t1 1.00000000       0.00000000
222       ht_t1 emque_ec_t1 1.00000000       0.00000000
223       ec_t1 emque_ec_t1 1.00000000       0.00000000
224       pa_t1 emque_ec_t1 1.00000000       0.00000000
225       sd_t1 emque_ec_t1 1.00000000       0.00000000
226        a_t1 emque_ec_t1 1.00000000       0.00000000
227      tom_t1 emque_ec_t1 1.00000000       0.00000000
228  flanker_t1 emque_ec_t1 1.00000000       0.00000000
229      tec_t1 emque_ec_t1 1.00000000       0.00000000
230       wm_t1 emque_ec_t1 1.00000000       0.00000000
231     dccs_t1 emque_ec_t1 1.00000000       0.00000000
232   cbq_na_t1 emque_ec_t1 1.00000000       0.00000000
233  cbq_att_t1 emque_ec_t1 1.00000000       0.00000000
234  cbq_shy_t1 emque_ec_t1 1.00000000       0.00000000
239       ht_t1 emque_af_t1 1.00000000       0.00000000
240       ec_t1 emque_af_t1 1.00000000       0.00000000
241       pa_t1 emque_af_t1 1.00000000       0.00000000
242       sd_t1 emque_af_t1 1.00000000       0.00000000
243        a_t1 emque_af_t1 1.00000000       0.00000000
244      tom_t1 emque_af_t1 1.00000000       0.00000000
245  flanker_t1 emque_af_t1 1.00000000       0.00000000
246      tec_t1 emque_af_t1 1.00000000       0.00000000
247       wm_t1 emque_af_t1 1.00000000       0.00000000
248     dccs_t1 emque_af_t1 1.00000000       0.00000000
249   cbq_na_t1 emque_af_t1 1.00000000       0.00000000
250  cbq_att_t1 emque_af_t1 1.00000000       0.00000000
251  cbq_shy_t1 emque_af_t1 1.00000000       0.00000000
252 emque_ec_t1 emque_af_t1 1.00000000       0.07376341
256       ht_t1 emque_pa_t1 1.00000000       0.00000000
257       ec_t1 emque_pa_t1 1.00000000       0.00000000
258       pa_t1 emque_pa_t1 1.00000000       0.00000000
259       sd_t1 emque_pa_t1 1.00000000       0.00000000
260        a_t1 emque_pa_t1 1.00000000       0.00000000
261      tom_t1 emque_pa_t1 1.00000000       0.00000000
262  flanker_t1 emque_pa_t1 1.00000000       0.00000000
263      tec_t1 emque_pa_t1 1.00000000       0.00000000
264       wm_t1 emque_pa_t1 1.00000000       0.00000000
265     dccs_t1 emque_pa_t1 1.00000000       0.00000000
266   cbq_na_t1 emque_pa_t1 1.00000000       0.00000000
267  cbq_att_t1 emque_pa_t1 1.00000000       0.00000000
268  cbq_shy_t1 emque_pa_t1 1.00000000       0.00000000
269 emque_ec_t1 emque_pa_t1 0.39160168       0.12431940
270 emque_af_t1 emque_pa_t1 1.00000000       0.14042100
273       ht_t1  csus_pt_t1 1.00000000       0.00000000
274       ec_t1  csus_pt_t1 1.00000000       0.00000000
275       pa_t1  csus_pt_t1 1.00000000       0.00000000
276       sd_t1  csus_pt_t1 1.00000000       0.00000000
277        a_t1  csus_pt_t1 1.00000000       0.00000000
278      tom_t1  csus_pt_t1 1.00000000       0.00000000
279  flanker_t1  csus_pt_t1 1.00000000       0.00000000
280      tec_t1  csus_pt_t1 1.00000000       0.00000000
281       wm_t1  csus_pt_t1 1.00000000       0.00000000
282     dccs_t1  csus_pt_t1 1.00000000       0.00000000
283   cbq_na_t1  csus_pt_t1 0.39160168       0.10539442
284  cbq_att_t1  csus_pt_t1 1.00000000       0.00000000
285  cbq_shy_t1  csus_pt_t1 0.39160168       0.11155080
286 emque_ec_t1  csus_pt_t1 1.00000000       0.00000000
287 emque_af_t1  csus_pt_t1 1.00000000       0.05410490
288 emque_pa_t1  csus_pt_t1 1.00000000       0.10564847


 CENTRALITY INVARIANCE TEST 
 Nodes tested: ht_t1 ec_t1 pa_t1 sd_t1 a_t1 tom_t1 flanker_t1 tec_t1 wm_t1 dccs_t1 cbq_na_t1 cbq_att_t1 cbq_shy_t1 emque_ec_t1 emque_af_t1 emque_pa_t1 csus_pt_t1 
 Centralities tested: expectedInfluence
 Test statistics C: 
            expectedInfluence
ht_t1             -0.10228553
ec_t1             -0.36521938
pa_t1             -0.27388311
sd_t1             -0.03265673
a_t1               0.13591175
tom_t1            -0.07970455
flanker_t1         0.00000000
tec_t1            -0.05448537
wm_t1             -0.20358782
dccs_t1            0.00000000
cbq_na_t1          0.41708332
cbq_att_t1         0.00000000
cbq_shy_t1         0.03044560
emque_ec_t1       -0.19808281
emque_af_t1       -0.26828931
emque_pa_t1       -0.37038887
csus_pt_t1        -0.16590974

 p-values: 
            expectedInfluence
ht_t1              0.67578484
ec_t1              0.28282344
pa_t1              0.22888756
sd_t1              1.00000000
a_t1               0.22888756
tom_t1             0.98693595
flanker_t1         1.00000000
tec_t1             0.98693595
wm_t1              0.67578484
dccs_t1            1.00000000
cbq_na_t1          0.03059388
cbq_att_t1         1.00000000
cbq_shy_t1         1.00000000
emque_ec_t1        0.55125642
emque_af_t1        0.59105679
emque_pa_t1        0.24135173
csus_pt_t1         0.59105679

if (file.exists(here("output", "models", "networks", "nct_4vs6_t1.rds"))) {
  
  nct_4vs6_t1 <- readRDS(here("output", "models", "networks", "nct_4vs6_t1.rds"))
  
  summary(nct_4vs6_t1)

  plot(nct_4vs6_t1, what = "strength" )

  plot(nct_4vs6_t1, what = "network")

  #plot(nct_4vs6, what = "centrality")

  #plot(nct_4vs6, what = "edge")
} else {
  nct_4vs6_t1 <- NetworkComparisonTest::NCT(network_ebicglasso_t1_4,
                           network_ebicglasso_t1_6,
                           gamma = 0.5,
                           it = 5000,
                           abs = TRUE, 
                           edges = "yes",
                           test.edges = TRUE,
                           test.centrality = TRUE,
                           centrality = "expectedInfluence",
                           p.adjust.methods = "none")

  saveRDS(nct_4vs6_t1,
        file = here("output", "models", "networks", "nct_4vs6_t1.rds"))

  summary(nct_4vs6_t1)

  plot(nct_4vs6_t1, what = "strength" )

  plot(nct_4vs6_t1, what = "network")

  #plot(nct_4vs6, what = "centrality")

#  plot(nct_4vs6, what = "edge")
}
 INDEPENDENT GROUPS GAUSSIAN NETWORK COMPARISON TEST 

 P-VALUE CORRECTION: none 

 NETWORK INVARIANCE TEST 
 Test statistic M: 0.1491025 
 p-value 0.914817 

 GLOBAL STRENGTH INVARIANCE TEST 
 Global strength per group:  1.627663 2.756422 
 Test statistic S:  1.128759 
 p-value 0.3983203

 EDGE INVARIANCE TEST 
           Var1        Var2    p-value Test statistic E
18        ht_t1       ec_t1 0.82583483       0.02070753
35        ht_t1       pa_t1 0.93761248       0.00804442
36        ec_t1       pa_t1 0.09178164       0.14453482
52        ht_t1       sd_t1 1.00000000       0.00000000
53        ec_t1       sd_t1 0.35952809       0.09015738
54        pa_t1       sd_t1 0.24715057       0.10998954
69        ht_t1        a_t1 1.00000000       0.00000000
70        ec_t1        a_t1 0.10937812       0.13591175
71        pa_t1        a_t1 1.00000000       0.00000000
72        sd_t1        a_t1 1.00000000       0.00000000
86        ht_t1      tom_t1 0.00019996       0.03342778
87        ec_t1      tom_t1 1.00000000       0.00000000
88        pa_t1      tom_t1 1.00000000       0.00000000
89        sd_t1      tom_t1 1.00000000       0.00000000
90         a_t1      tom_t1 1.00000000       0.00000000
103       ht_t1  flanker_t1 1.00000000       0.00000000
104       ec_t1  flanker_t1 1.00000000       0.00000000
105       pa_t1  flanker_t1 1.00000000       0.00000000
106       sd_t1  flanker_t1 1.00000000       0.00000000
107        a_t1  flanker_t1 1.00000000       0.00000000
108      tom_t1  flanker_t1 1.00000000       0.00000000
120       ht_t1      tec_t1 1.00000000       0.00000000
121       ec_t1      tec_t1 1.00000000       0.00000000
122       pa_t1      tec_t1 1.00000000       0.00000000
123       sd_t1      tec_t1 1.00000000       0.00000000
124        a_t1      tec_t1 1.00000000       0.00000000
125      tom_t1      tec_t1 0.65926815       0.04285243
126  flanker_t1      tec_t1 1.00000000       0.00000000
137       ht_t1       wm_t1 1.00000000       0.00000000
138       ec_t1       wm_t1 1.00000000       0.00000000
139       pa_t1       wm_t1 1.00000000       0.00000000
140       sd_t1       wm_t1 1.00000000       0.00000000
141        a_t1       wm_t1 1.00000000       0.00000000
142      tom_t1       wm_t1 0.14137173       0.14910245
143  flanker_t1       wm_t1 1.00000000       0.00000000
144      tec_t1       wm_t1 0.57168566       0.05448537
154       ht_t1     dccs_t1 1.00000000       0.00000000
155       ec_t1     dccs_t1 1.00000000       0.00000000
156       pa_t1     dccs_t1 1.00000000       0.00000000
157       sd_t1     dccs_t1 1.00000000       0.00000000
158        a_t1     dccs_t1 1.00000000       0.00000000
159      tom_t1     dccs_t1 1.00000000       0.00000000
160  flanker_t1     dccs_t1 1.00000000       0.00000000
161      tec_t1     dccs_t1 1.00000000       0.00000000
162       wm_t1     dccs_t1 1.00000000       0.00000000
171       ht_t1   cbq_na_t1 1.00000000       0.00000000
172       ec_t1   cbq_na_t1 1.00000000       0.00000000
173       pa_t1   cbq_na_t1 1.00000000       0.00000000
174       sd_t1   cbq_na_t1 1.00000000       0.00000000
175        a_t1   cbq_na_t1 1.00000000       0.00000000
176      tom_t1   cbq_na_t1 0.01479704       0.03597011
177  flanker_t1   cbq_na_t1 1.00000000       0.00000000
178      tec_t1   cbq_na_t1 1.00000000       0.00000000
179       wm_t1   cbq_na_t1 1.00000000       0.00000000
180     dccs_t1   cbq_na_t1 1.00000000       0.00000000
188       ht_t1  cbq_att_t1 1.00000000       0.00000000
189       ec_t1  cbq_att_t1 1.00000000       0.00000000
190       pa_t1  cbq_att_t1 1.00000000       0.00000000
191       sd_t1  cbq_att_t1 1.00000000       0.00000000
192        a_t1  cbq_att_t1 1.00000000       0.00000000
193      tom_t1  cbq_att_t1 1.00000000       0.00000000
194  flanker_t1  cbq_att_t1 1.00000000       0.00000000
195      tec_t1  cbq_att_t1 1.00000000       0.00000000
196       wm_t1  cbq_att_t1 1.00000000       0.00000000
197     dccs_t1  cbq_att_t1 1.00000000       0.00000000
198   cbq_na_t1  cbq_att_t1 1.00000000       0.00000000
205       ht_t1  cbq_shy_t1 1.00000000       0.00000000
206       ec_t1  cbq_shy_t1 0.05418916       0.09906200
207       pa_t1  cbq_shy_t1 0.25374925       0.03466039
208       sd_t1  cbq_shy_t1 1.00000000       0.00000000
209        a_t1  cbq_shy_t1 1.00000000       0.00000000
210      tom_t1  cbq_shy_t1 1.00000000       0.00000000
211  flanker_t1  cbq_shy_t1 1.00000000       0.00000000
212      tec_t1  cbq_shy_t1 1.00000000       0.00000000
213       wm_t1  cbq_shy_t1 1.00000000       0.00000000
214     dccs_t1  cbq_shy_t1 1.00000000       0.00000000
215   cbq_na_t1  cbq_shy_t1 0.19616077       0.14716175
216  cbq_att_t1  cbq_shy_t1 1.00000000       0.00000000
222       ht_t1 emque_ec_t1 1.00000000       0.00000000
223       ec_t1 emque_ec_t1 1.00000000       0.00000000
224       pa_t1 emque_ec_t1 1.00000000       0.00000000
225       sd_t1 emque_ec_t1 1.00000000       0.00000000
226        a_t1 emque_ec_t1 1.00000000       0.00000000
227      tom_t1 emque_ec_t1 1.00000000       0.00000000
228  flanker_t1 emque_ec_t1 1.00000000       0.00000000
229      tec_t1 emque_ec_t1 1.00000000       0.00000000
230       wm_t1 emque_ec_t1 1.00000000       0.00000000
231     dccs_t1 emque_ec_t1 1.00000000       0.00000000
232   cbq_na_t1 emque_ec_t1 1.00000000       0.00000000
233  cbq_att_t1 emque_ec_t1 1.00000000       0.00000000
234  cbq_shy_t1 emque_ec_t1 1.00000000       0.00000000
239       ht_t1 emque_af_t1 1.00000000       0.00000000
240       ec_t1 emque_af_t1 1.00000000       0.00000000
241       pa_t1 emque_af_t1 1.00000000       0.00000000
242       sd_t1 emque_af_t1 1.00000000       0.00000000
243        a_t1 emque_af_t1 1.00000000       0.00000000
244      tom_t1 emque_af_t1 1.00000000       0.00000000
245  flanker_t1 emque_af_t1 1.00000000       0.00000000
246      tec_t1 emque_af_t1 1.00000000       0.00000000
247       wm_t1 emque_af_t1 1.00000000       0.00000000
248     dccs_t1 emque_af_t1 1.00000000       0.00000000
249   cbq_na_t1 emque_af_t1 1.00000000       0.00000000
250  cbq_att_t1 emque_af_t1 1.00000000       0.00000000
251  cbq_shy_t1 emque_af_t1 1.00000000       0.00000000
252 emque_ec_t1 emque_af_t1 0.84863027       0.02058970
256       ht_t1 emque_pa_t1 1.00000000       0.00000000
257       ec_t1 emque_pa_t1 1.00000000       0.00000000
258       pa_t1 emque_pa_t1 1.00000000       0.00000000
259       sd_t1 emque_pa_t1 1.00000000       0.00000000
260        a_t1 emque_pa_t1 1.00000000       0.00000000
261      tom_t1 emque_pa_t1 1.00000000       0.00000000
262  flanker_t1 emque_pa_t1 1.00000000       0.00000000
263      tec_t1 emque_pa_t1 1.00000000       0.00000000
264       wm_t1 emque_pa_t1 1.00000000       0.00000000
265     dccs_t1 emque_pa_t1 1.00000000       0.00000000
266   cbq_na_t1 emque_pa_t1 1.00000000       0.00000000
267  cbq_att_t1 emque_pa_t1 1.00000000       0.00000000
268  cbq_shy_t1 emque_pa_t1 1.00000000       0.00000000
269 emque_ec_t1 emque_pa_t1 0.68546291       0.04348231
270 emque_af_t1 emque_pa_t1 0.76664667       0.03154967
273       ht_t1  csus_pt_t1 1.00000000       0.00000000
274       ec_t1  csus_pt_t1 1.00000000       0.00000000
275       pa_t1  csus_pt_t1 1.00000000       0.00000000
276       sd_t1  csus_pt_t1 1.00000000       0.00000000
277        a_t1  csus_pt_t1 1.00000000       0.00000000
278      tom_t1  csus_pt_t1 1.00000000       0.00000000
279  flanker_t1  csus_pt_t1 1.00000000       0.00000000
280      tec_t1  csus_pt_t1 1.00000000       0.00000000
281       wm_t1  csus_pt_t1 0.70665867       0.04029740
282     dccs_t1  csus_pt_t1 1.00000000       0.00000000
283   cbq_na_t1  csus_pt_t1 0.04959008       0.10539442
284  cbq_att_t1  csus_pt_t1 1.00000000       0.00000000
285  cbq_shy_t1  csus_pt_t1 0.07498500       0.11155080
286 emque_ec_t1  csus_pt_t1 1.00000000       0.00000000
287 emque_af_t1  csus_pt_t1 0.04079184       0.05410490
288 emque_pa_t1  csus_pt_t1 0.44071186       0.09071650


 CENTRALITY INVARIANCE TEST 
 Nodes tested: ht_t1 ec_t1 pa_t1 sd_t1 a_t1 tom_t1 flanker_t1 tec_t1 wm_t1 dccs_t1 cbq_na_t1 cbq_att_t1 cbq_shy_t1 emque_ec_t1 emque_af_t1 emque_pa_t1 csus_pt_t1 
 Centralities tested: expectedInfluence
 Test statistics C: 
            expectedInfluence
ht_t1              0.04609090
ec_t1             -0.17713491
pa_t1             -0.07725009
sd_t1              0.01983217
a_t1               0.13591175
tom_t1            -0.03685212
flanker_t1         0.00000000
tec_t1            -0.01163294
wm_t1             -0.16329042
dccs_t1            0.00000000
cbq_na_t1          0.28852629
cbq_att_t1         0.00000000
cbq_shy_t1        -0.09811144
emque_ec_t1        0.02289261
emque_af_t1       -0.10624427
emque_pa_t1       -0.07878386
csus_pt_t1        -0.11068038

 p-values: 
            expectedInfluence
ht_t1              0.73365327
ec_t1              0.29154169
pa_t1              0.62567487
sd_t1              0.89402120
a_t1               0.11737652
tom_t1             0.89402120
flanker_t1         1.00000000
tec_t1             0.95800840
wm_t1              0.51869626
dccs_t1            1.00000000
cbq_na_t1          0.04079184
cbq_att_t1         1.00000000
cbq_shy_t1         0.48690262
emque_ec_t1        0.89182164
emque_af_t1        0.55188962
emque_pa_t1        0.77464507
csus_pt_t1         0.75064987

Network Comparison T2

if (file.exists(here("output", "models", "networks", "nct_5vs6_t2.rds"))) {
  
  nct_5vs6_t2 <- readRDS(here("output", "models", "networks", "nct_5vs6_t2.rds"))
  
  summary(nct_5vs6_t2)

  plot(nct_5vs6_t2, what = "strength" )

  plot(nct_5vs6_t2, what = "network")

  #plot(nct_4vs6, what = "centrality")

  #plot(nct_4vs6, what = "edge") 
  
} else { nct_5vs6_t2 <- NetworkComparisonTest::NCT(network_ebicglasso_t2_5,
                           network_ebicglasso_t2_6,
                           gamma = 0.5,
                           it = 5000,
                           abs = TRUE, 
                           edges = "yes",
                           test.edges = TRUE,
                           test.centrality = TRUE,
                           centrality = "expectedInfluence",
                           p.adjust.methods = "BH")

saveRDS(nct_5vs6_t2,
        file = here("output", "models", "networks", "nct_5vs6_t2.rds"))

summary(nct_5vs6_t2)

plot(nct_5vs6_t2, what = "strength" )

plot(nct_5vs6_t2, what = "network")

#plot(nct_5vs6_t2, what = "centrality")

#plot(nct_5vs6_t2, what = "edge")

}
 INDEPENDENT GROUPS GAUSSIAN NETWORK COMPARISON TEST 

 P-VALUE CORRECTION: BH 

 NETWORK INVARIANCE TEST 
 Test statistic M: 0.116441 
 p-value 0.9580084 

 GLOBAL STRENGTH INVARIANCE TEST 
 Global strength per group:  1.234407 1.558107 
 Test statistic S:  0.3236996 
 p-value 0.7676465

 EDGE INVARIANCE TEST 
           Var1        Var2 p-value Test statistic E
18        ht_t2       ec_t2       1       0.01864101
35        ht_t2       pa_t2       1       0.01346907
36        ec_t2       pa_t2       1       0.07568362
52        ht_t2       sd_t2       1       0.00000000
53        ec_t2       sd_t2       1       0.02182476
54        pa_t2       sd_t2       1       0.05674066
69        ht_t2        a_t2       1       0.00000000
70        ec_t2        a_t2       1       0.06076482
71        pa_t2        a_t2       1       0.00000000
72        sd_t2        a_t2       1       0.00000000
86        ht_t2      tom_t2       1       0.00000000
87        ec_t2      tom_t2       1       0.00000000
88        pa_t2      tom_t2       1       0.00000000
89        sd_t2      tom_t2       1       0.00000000
90         a_t2      tom_t2       1       0.00000000
103       ht_t2  flanker_t2       1       0.00000000
104       ec_t2  flanker_t2       1       0.00000000
105       pa_t2  flanker_t2       1       0.00000000
106       sd_t2  flanker_t2       1       0.00000000
107        a_t2  flanker_t2       1       0.00000000
108      tom_t2  flanker_t2       1       0.00000000
120       ht_t2      tec_t2       1       0.00000000
121       ec_t2      tec_t2       1       0.00000000
122       pa_t2      tec_t2       1       0.00000000
123       sd_t2      tec_t2       1       0.00000000
124        a_t2      tec_t2       1       0.00000000
125      tom_t2      tec_t2       1       0.00000000
126  flanker_t2      tec_t2       1       0.00000000
137       ht_t2       wm_t2       1       0.00000000
138       ec_t2       wm_t2       1       0.00000000
139       pa_t2       wm_t2       1       0.00000000
140       sd_t2       wm_t2       1       0.00000000
141        a_t2       wm_t2       1       0.00000000
142      tom_t2       wm_t2       1       0.11644105
143  flanker_t2       wm_t2       1       0.00000000
144      tec_t2       wm_t2       1       0.00000000
154       ht_t2     dccs_t2       1       0.00000000
155       ec_t2     dccs_t2       1       0.00000000
156       pa_t2     dccs_t2       1       0.00000000
157       sd_t2     dccs_t2       1       0.00000000
158        a_t2     dccs_t2       1       0.00000000
159      tom_t2     dccs_t2       1       0.00000000
160  flanker_t2     dccs_t2       1       0.00000000
161      tec_t2     dccs_t2       1       0.00000000
162       wm_t2     dccs_t2       1       0.00000000
171       ht_t2   cbq_na_t2       1       0.00000000
172       ec_t2   cbq_na_t2       1       0.00000000
173       pa_t2   cbq_na_t2       1       0.00000000
174       sd_t2   cbq_na_t2       1       0.00000000
175        a_t2   cbq_na_t2       1       0.00000000
176      tom_t2   cbq_na_t2       1       0.00000000
177  flanker_t2   cbq_na_t2       1       0.00000000
178      tec_t2   cbq_na_t2       1       0.00000000
179       wm_t2   cbq_na_t2       1       0.00000000
180     dccs_t2   cbq_na_t2       1       0.00000000
188       ht_t2  cbq_att_t2       1       0.00000000
189       ec_t2  cbq_att_t2       1       0.00000000
190       pa_t2  cbq_att_t2       1       0.00000000
191       sd_t2  cbq_att_t2       1       0.00000000
192        a_t2  cbq_att_t2       1       0.00000000
193      tom_t2  cbq_att_t2       1       0.00000000
194  flanker_t2  cbq_att_t2       1       0.00000000
195      tec_t2  cbq_att_t2       1       0.00000000
196       wm_t2  cbq_att_t2       1       0.00000000
197     dccs_t2  cbq_att_t2       1       0.00000000
198   cbq_na_t2  cbq_att_t2       1       0.00000000
205       ht_t2  cbq_shy_t2       1       0.00000000
206       ec_t2  cbq_shy_t2       1       0.00000000
207       pa_t2  cbq_shy_t2       1       0.00000000
208       sd_t2  cbq_shy_t2       1       0.00000000
209        a_t2  cbq_shy_t2       1       0.00000000
210      tom_t2  cbq_shy_t2       1       0.00000000
211  flanker_t2  cbq_shy_t2       1       0.00000000
212      tec_t2  cbq_shy_t2       1       0.00000000
213       wm_t2  cbq_shy_t2       1       0.00000000
214     dccs_t2  cbq_shy_t2       1       0.00000000
215   cbq_na_t2  cbq_shy_t2       1       0.05347205
216  cbq_att_t2  cbq_shy_t2       1       0.00000000
222       ht_t2 emque_ec_t2       1       0.00000000
223       ec_t2 emque_ec_t2       1       0.00000000
224       pa_t2 emque_ec_t2       1       0.00000000
225       sd_t2 emque_ec_t2       1       0.00000000
226        a_t2 emque_ec_t2       1       0.00000000
227      tom_t2 emque_ec_t2       1       0.00000000
228  flanker_t2 emque_ec_t2       1       0.00000000
229      tec_t2 emque_ec_t2       1       0.00000000
230       wm_t2 emque_ec_t2       1       0.00000000
231     dccs_t2 emque_ec_t2       1       0.00000000
232   cbq_na_t2 emque_ec_t2       1       0.00000000
233  cbq_att_t2 emque_ec_t2       1       0.00000000
234  cbq_shy_t2 emque_ec_t2       1       0.00000000
239       ht_t2 emque_af_t2       1       0.00000000
240       ec_t2 emque_af_t2       1       0.00000000
241       pa_t2 emque_af_t2       1       0.00000000
242       sd_t2 emque_af_t2       1       0.00000000
243        a_t2 emque_af_t2       1       0.00000000
244      tom_t2 emque_af_t2       1       0.00000000
245  flanker_t2 emque_af_t2       1       0.00000000
246      tec_t2 emque_af_t2       1       0.00000000
247       wm_t2 emque_af_t2       1       0.00000000
248     dccs_t2 emque_af_t2       1       0.00000000
249   cbq_na_t2 emque_af_t2       1       0.00000000
250  cbq_att_t2 emque_af_t2       1       0.00000000
251  cbq_shy_t2 emque_af_t2       1       0.00000000
252 emque_ec_t2 emque_af_t2       1       0.05358032
256       ht_t2 emque_pa_t2       1       0.00000000
257       ec_t2 emque_pa_t2       1       0.00000000
258       pa_t2 emque_pa_t2       1       0.00000000
259       sd_t2 emque_pa_t2       1       0.00000000
260        a_t2 emque_pa_t2       1       0.00000000
261      tom_t2 emque_pa_t2       1       0.00000000
262  flanker_t2 emque_pa_t2       1       0.00000000
263      tec_t2 emque_pa_t2       1       0.00000000
264       wm_t2 emque_pa_t2       1       0.00000000
265     dccs_t2 emque_pa_t2       1       0.00000000
266   cbq_na_t2 emque_pa_t2       1       0.00000000
267  cbq_att_t2 emque_pa_t2       1       0.00000000
268  cbq_shy_t2 emque_pa_t2       1       0.00000000
269 emque_ec_t2 emque_pa_t2       1       0.10347454
270 emque_af_t2 emque_pa_t2       1       0.03352101
273       ht_t2  csus_pt_t2       1       0.00000000
274       ec_t2  csus_pt_t2       1       0.00000000
275       pa_t2  csus_pt_t2       1       0.00000000
276       sd_t2  csus_pt_t2       1       0.00000000
277        a_t2  csus_pt_t2       1       0.00000000
278      tom_t2  csus_pt_t2       1       0.00000000
279  flanker_t2  csus_pt_t2       1       0.00000000
280      tec_t2  csus_pt_t2       1       0.00000000
281       wm_t2  csus_pt_t2       1       0.00000000
282     dccs_t2  csus_pt_t2       1       0.00000000
283   cbq_na_t2  csus_pt_t2       1       0.00000000
284  cbq_att_t2  csus_pt_t2       1       0.00000000
285  cbq_shy_t2  csus_pt_t2       1       0.00000000
286 emque_ec_t2  csus_pt_t2       1       0.00000000
287 emque_af_t2  csus_pt_t2       1       0.00000000
288 emque_pa_t2  csus_pt_t2       1       0.05429799


 CENTRALITY INVARIANCE TEST 
 Nodes tested: ht_t2 ec_t2 pa_t2 sd_t2 a_t2 tom_t2 flanker_t2 tec_t2 wm_t2 dccs_t2 cbq_na_t2 cbq_att_t2 cbq_shy_t2 emque_ec_t2 emque_af_t2 emque_pa_t2 csus_pt_t2 
 Centralities tested: expectedInfluence
 Test statistics C: 
            expectedInfluence
ht_t2              0.03211008
ec_t2              0.02554698
pa_t2             -0.00547388
sd_t2              0.07856543
a_t2               0.06076482
tom_t2            -0.11644105
flanker_t2         0.00000000
tec_t2             0.00000000
wm_t2             -0.11644105
dccs_t2            0.00000000
cbq_na_t2          0.05347205
cbq_att_t2         0.00000000
cbq_shy_t2         0.05347205
emque_ec_t2        0.04989422
emque_af_t2       -0.02005931
emque_pa_t2        0.08269756
csus_pt_t2        -0.05429799

 p-values: 
            expectedInfluence
ht_t2                       1
ec_t2                       1
pa_t2                       1
sd_t2                       1
a_t2                        1
tom_t2                      1
flanker_t2                  1
tec_t2                      1
wm_t2                       1
dccs_t2                     1
cbq_na_t2                   1
cbq_att_t2                  1
cbq_shy_t2                  1
emque_ec_t2                 1
emque_af_t2                 1
emque_pa_t2                 1
csus_pt_t2                  1

if (file.exists(here("output", "models", "networks", "nct_6vs7_t2.rds"))) {
  
  nct_6vs7_t2 <- readRDS(here("output", "models", "networks", "nct_6vs7_t2.rds"))
  
  summary(nct_6vs7_t2)

  plot(nct_6vs7_t2, what = "strength" )

  plot(nct_6vs7_t2, what = "network")

  #plot(nct_4vs6, what = "centrality")

  #plot(nct_4vs6, what = "edge") 

} else { nct_6vs7_t2 <- NetworkComparisonTest::NCT(network_ebicglasso_t2_6,
                           network_ebicglasso_t2_7,
                           gamma = 0.5,
                           it = 5000,
                           abs = TRUE, 
                           edges = "yes",
                           test.edges = TRUE,
                           test.centrality = TRUE,
                           centrality = "expectedInfluence",
                           p.adjust.methods = "BH")

saveRDS(nct_6vs7_t2,
        file = here("output", "models", "networks", "nct_6vs7_t2.rds"))

summary(nct_6vs7_t2)

plot(nct_6vs7_t2, what = "strength" )

plot(nct_5vs6_t2, what = "network")

#plot(nct_6vs7_t2, what = "centrality")

#plot(nct_6vs7_t2, what = "edge")

}
 INDEPENDENT GROUPS GAUSSIAN NETWORK COMPARISON TEST 

 P-VALUE CORRECTION: BH 

 NETWORK INVARIANCE TEST 
 Test statistic M: 0.2034839 
 p-value 0.3055389 

 GLOBAL STRENGTH INVARIANCE TEST 
 Global strength per group:  1.558107 2.924347 
 Test statistic S:  1.36624 
 p-value 0.1483703

 EDGE INVARIANCE TEST 
           Var1        Var2   p-value Test statistic E
18        ht_t2       ec_t2 1.0000000       0.12440105
35        ht_t2       pa_t2 1.0000000       0.08236284
36        ec_t2       pa_t2 1.0000000       0.08679458
52        ht_t2       sd_t2 1.0000000       0.00000000
53        ec_t2       sd_t2 1.0000000       0.08299823
54        pa_t2       sd_t2 1.0000000       0.02623878
69        ht_t2        a_t2 1.0000000       0.00000000
70        ec_t2        a_t2 1.0000000       0.06076482
71        pa_t2        a_t2 1.0000000       0.00000000
72        sd_t2        a_t2 0.4759048       0.09836261
86        ht_t2      tom_t2 1.0000000       0.00000000
87        ec_t2      tom_t2 1.0000000       0.00000000
88        pa_t2      tom_t2 0.8469163       0.03904162
89        sd_t2      tom_t2 1.0000000       0.00000000
90         a_t2      tom_t2 1.0000000       0.00000000
103       ht_t2  flanker_t2 1.0000000       0.00000000
104       ec_t2  flanker_t2 1.0000000       0.00000000
105       pa_t2  flanker_t2 1.0000000       0.00000000
106       sd_t2  flanker_t2 1.0000000       0.00000000
107        a_t2  flanker_t2 1.0000000       0.00000000
108      tom_t2  flanker_t2 0.8770246       0.09148413
120       ht_t2      tec_t2 1.0000000       0.00000000
121       ec_t2      tec_t2 1.0000000       0.00000000
122       pa_t2      tec_t2 1.0000000       0.00000000
123       sd_t2      tec_t2 1.0000000       0.00000000
124        a_t2      tec_t2 1.0000000       0.00000000
125      tom_t2      tec_t2 1.0000000       0.00000000
126  flanker_t2      tec_t2 1.0000000       0.00000000
137       ht_t2       wm_t2 1.0000000       0.00000000
138       ec_t2       wm_t2 1.0000000       0.00000000
139       pa_t2       wm_t2 1.0000000       0.00000000
140       sd_t2       wm_t2 1.0000000       0.00000000
141        a_t2       wm_t2 1.0000000       0.00000000
142      tom_t2       wm_t2 1.0000000       0.03281102
143  flanker_t2       wm_t2 1.0000000       0.00000000
144      tec_t2       wm_t2 1.0000000       0.09449018
154       ht_t2     dccs_t2 1.0000000       0.00000000
155       ec_t2     dccs_t2 1.0000000       0.00000000
156       pa_t2     dccs_t2 1.0000000       0.00000000
157       sd_t2     dccs_t2 1.0000000       0.00000000
158        a_t2     dccs_t2 1.0000000       0.00000000
159      tom_t2     dccs_t2 1.0000000       0.00000000
160  flanker_t2     dccs_t2 1.0000000       0.00000000
161      tec_t2     dccs_t2 1.0000000       0.00000000
162       wm_t2     dccs_t2 1.0000000       0.02955106
171       ht_t2   cbq_na_t2 1.0000000       0.00000000
172       ec_t2   cbq_na_t2 1.0000000       0.00000000
173       pa_t2   cbq_na_t2 1.0000000       0.00000000
174       sd_t2   cbq_na_t2 1.0000000       0.00000000
175        a_t2   cbq_na_t2 1.0000000       0.00000000
176      tom_t2   cbq_na_t2 1.0000000       0.00000000
177  flanker_t2   cbq_na_t2 1.0000000       0.00000000
178      tec_t2   cbq_na_t2 1.0000000       0.00000000
179       wm_t2   cbq_na_t2 1.0000000       0.00000000
180     dccs_t2   cbq_na_t2 1.0000000       0.00000000
188       ht_t2  cbq_att_t2 1.0000000       0.00000000
189       ec_t2  cbq_att_t2 1.0000000       0.00000000
190       pa_t2  cbq_att_t2 1.0000000       0.00000000
191       sd_t2  cbq_att_t2 1.0000000       0.00000000
192        a_t2  cbq_att_t2 1.0000000       0.00000000
193      tom_t2  cbq_att_t2 1.0000000       0.00000000
194  flanker_t2  cbq_att_t2 1.0000000       0.00000000
195      tec_t2  cbq_att_t2 0.2447510       0.08536023
196       wm_t2  cbq_att_t2 1.0000000       0.00000000
197     dccs_t2  cbq_att_t2 1.0000000       0.00000000
198   cbq_na_t2  cbq_att_t2 1.0000000       0.00000000
205       ht_t2  cbq_shy_t2 0.6979937       0.01753731
206       ec_t2  cbq_shy_t2 1.0000000       0.00000000
207       pa_t2  cbq_shy_t2 1.0000000       0.00000000
208       sd_t2  cbq_shy_t2 1.0000000       0.00000000
209        a_t2  cbq_shy_t2 1.0000000       0.00000000
210      tom_t2  cbq_shy_t2 1.0000000       0.00000000
211  flanker_t2  cbq_shy_t2 1.0000000       0.00000000
212      tec_t2  cbq_shy_t2 1.0000000       0.00000000
213       wm_t2  cbq_shy_t2 1.0000000       0.00000000
214     dccs_t2  cbq_shy_t2 1.0000000       0.00000000
215   cbq_na_t2  cbq_shy_t2 1.0000000       0.13340390
216  cbq_att_t2  cbq_shy_t2 1.0000000       0.00000000
222       ht_t2 emque_ec_t2 1.0000000       0.00000000
223       ec_t2 emque_ec_t2 1.0000000       0.00000000
224       pa_t2 emque_ec_t2 1.0000000       0.00000000
225       sd_t2 emque_ec_t2 1.0000000       0.00000000
226        a_t2 emque_ec_t2 1.0000000       0.00000000
227      tom_t2 emque_ec_t2 1.0000000       0.00000000
228  flanker_t2 emque_ec_t2 1.0000000       0.00000000
229      tec_t2 emque_ec_t2 1.0000000       0.00000000
230       wm_t2 emque_ec_t2 1.0000000       0.00000000
231     dccs_t2 emque_ec_t2 1.0000000       0.00000000
232   cbq_na_t2 emque_ec_t2 1.0000000       0.00000000
233  cbq_att_t2 emque_ec_t2 1.0000000       0.00000000
234  cbq_shy_t2 emque_ec_t2 1.0000000       0.00000000
239       ht_t2 emque_af_t2 1.0000000       0.00000000
240       ec_t2 emque_af_t2 1.0000000       0.00000000
241       pa_t2 emque_af_t2 1.0000000       0.00000000
242       sd_t2 emque_af_t2 1.0000000       0.00000000
243        a_t2 emque_af_t2 1.0000000       0.00000000
244      tom_t2 emque_af_t2 1.0000000       0.00000000
245  flanker_t2 emque_af_t2 1.0000000       0.00000000
246      tec_t2 emque_af_t2 1.0000000       0.00000000
247       wm_t2 emque_af_t2 1.0000000       0.00000000
248     dccs_t2 emque_af_t2 1.0000000       0.00000000
249   cbq_na_t2 emque_af_t2 1.0000000       0.00000000
250  cbq_att_t2 emque_af_t2 1.0000000       0.00000000
251  cbq_shy_t2 emque_af_t2 1.0000000       0.00000000
252 emque_ec_t2 emque_af_t2 1.0000000       0.01256945
256       ht_t2 emque_pa_t2 1.0000000       0.00000000
257       ec_t2 emque_pa_t2 1.0000000       0.00000000
258       pa_t2 emque_pa_t2 1.0000000       0.00000000
259       sd_t2 emque_pa_t2 1.0000000       0.00000000
260        a_t2 emque_pa_t2 1.0000000       0.00000000
261      tom_t2 emque_pa_t2 1.0000000       0.00000000
262  flanker_t2 emque_pa_t2 1.0000000       0.00000000
263      tec_t2 emque_pa_t2 1.0000000       0.00000000
264       wm_t2 emque_pa_t2 1.0000000       0.00000000
265     dccs_t2 emque_pa_t2 1.0000000       0.00000000
266   cbq_na_t2 emque_pa_t2 1.0000000       0.00000000
267  cbq_att_t2 emque_pa_t2 1.0000000       0.00000000
268  cbq_shy_t2 emque_pa_t2 1.0000000       0.00000000
269 emque_ec_t2 emque_pa_t2 1.0000000       0.13828573
270 emque_af_t2 emque_pa_t2 0.5302939       0.20348392
273       ht_t2  csus_pt_t2 1.0000000       0.00000000
274       ec_t2  csus_pt_t2 1.0000000       0.00000000
275       pa_t2  csus_pt_t2 1.0000000       0.00000000
276       sd_t2  csus_pt_t2 1.0000000       0.00000000
277        a_t2  csus_pt_t2 1.0000000       0.00000000
278      tom_t2  csus_pt_t2 1.0000000       0.01528408
279  flanker_t2  csus_pt_t2 1.0000000       0.00000000
280      tec_t2  csus_pt_t2 1.0000000       0.05928222
281       wm_t2  csus_pt_t2 0.5874025       0.13926081
282     dccs_t2  csus_pt_t2 1.0000000       0.00000000
283   cbq_na_t2  csus_pt_t2 1.0000000       0.04261542
284  cbq_att_t2  csus_pt_t2 1.0000000       0.00000000
285  cbq_shy_t2  csus_pt_t2 0.5302939       0.12341783
286 emque_ec_t2  csus_pt_t2 1.0000000       0.00000000
287 emque_af_t2  csus_pt_t2 1.0000000       0.00000000
288 emque_pa_t2  csus_pt_t2 1.0000000       0.00628302


 CENTRALITY INVARIANCE TEST 
 Nodes tested: ht_t2 ec_t2 pa_t2 sd_t2 a_t2 tom_t2 flanker_t2 tec_t2 wm_t2 dccs_t2 cbq_na_t2 cbq_att_t2 cbq_shy_t2 emque_ec_t2 emque_af_t2 emque_pa_t2 csus_pt_t2 
 Centralities tested: expectedInfluence
 Test statistics C: 
            expectedInfluence
ht_t2            -0.059575527
ec_t2            -0.015373068
pa_t2             0.234437805
sd_t2             0.207599615
a_t2              0.037597783
tom_t2           -0.100537610
flanker_t2       -0.091484126
tec_t2           -0.239132637
wm_t2            -0.296113061
dccs_t2          -0.029551059
cbq_na_t2         0.176019324
cbq_att_t2       -0.085360235
cbq_shy_t2       -0.007551238
emque_ec_t2      -0.150855178
emque_af_t2      -0.216053367
emque_pa_t2      -0.348052659
csus_pt_t2       -0.300912538

 p-values: 
            expectedInfluence
ht_t2               0.7328934
ec_t2               0.9556089
pa_t2               0.3365327
sd_t2               0.4254816
a_t2                0.4626166
tom_t2              0.6087398
flanker_t2          0.4293341
tec_t2              0.3365327
wm_t2               0.4293341
dccs_t2             0.7039021
cbq_na_t2           0.4293341
cbq_att_t2          0.3365327
cbq_shy_t2          0.9556089
emque_ec_t2         0.5886489
emque_af_t2         0.4293341
emque_pa_t2         0.4254816
csus_pt_t2          0.3365327

if (file.exists(here("output", "models", "networks", "nct_5vs7_t2.rds"))) {
  
  nct_5vs7_t2 <- readRDS(here("output", "models", "networks", "nct_5vs7_t2.rds"))
  
  summary(nct_5vs7_t2)

  plot(nct_5vs7_t2, what = "strength" )

  plot(nct_5vs7_t2, what = "network")

  #plot(nct_4vs6, what = "centrality")

  #plot(nct_4vs6, what = "edge")
} else {
  nct_5vs7_t2 <- NetworkComparisonTest::NCT(network_ebicglasso_t2_5,
                           network_ebicglasso_t2_7,
                           gamma = 0.5,
                           it = 5000,
                           abs = TRUE, 
                           edges = "yes",
                           test.edges = TRUE,
                           test.centrality = TRUE,
                           centrality = "expectedInfluence",
                           p.adjust.methods = "none")

  saveRDS(nct_5vs7_t2,
        file = here("output", "models", "networks", "nct_5vs7_t2.rds"))

  summary(nct_5vs7_t2)

  plot(nct_5vs7_t2, what = "strength" )

  plot(nct_5vs7_t2, what = "network")

 # plot(nct_4vs6, what = "centrality")

  #plot(nct_4vs6, what = "edge")
}
 INDEPENDENT GROUPS GAUSSIAN NETWORK COMPARISON TEST 

 P-VALUE CORRECTION: none 

 NETWORK INVARIANCE TEST 
 Test statistic M: 0.186876 
 p-value 0.5962807 

 GLOBAL STRENGTH INVARIANCE TEST 
 Global strength per group:  1.234407 2.924347 
 Test statistic S:  1.68994 
 p-value 0.284943

 EDGE INVARIANCE TEST 
           Var1        Var2    p-value Test statistic E
18        ht_t2       ec_t2 0.30433913       0.10576004
35        ht_t2       pa_t2 0.29394121       0.09583191
36        ec_t2       pa_t2 0.91001800       0.01111096
52        ht_t2       sd_t2 1.00000000       0.00000000
53        ec_t2       sd_t2 0.31033793       0.10482300
54        pa_t2       sd_t2 0.34853029       0.08297944
69        ht_t2        a_t2 1.00000000       0.00000000
70        ec_t2        a_t2 1.00000000       0.00000000
71        pa_t2        a_t2 1.00000000       0.00000000
72        sd_t2        a_t2 0.14397121       0.09836261
86        ht_t2      tom_t2 1.00000000       0.00000000
87        ec_t2      tom_t2 1.00000000       0.00000000
88        pa_t2      tom_t2 0.04659068       0.03904162
89        sd_t2      tom_t2 1.00000000       0.00000000
90         a_t2      tom_t2 1.00000000       0.00000000
103       ht_t2  flanker_t2 1.00000000       0.00000000
104       ec_t2  flanker_t2 1.00000000       0.00000000
105       pa_t2  flanker_t2 1.00000000       0.00000000
106       sd_t2  flanker_t2 1.00000000       0.00000000
107        a_t2  flanker_t2 1.00000000       0.00000000
108      tom_t2  flanker_t2 0.29234153       0.09148413
120       ht_t2      tec_t2 1.00000000       0.00000000
121       ec_t2      tec_t2 1.00000000       0.00000000
122       pa_t2      tec_t2 1.00000000       0.00000000
123       sd_t2      tec_t2 1.00000000       0.00000000
124        a_t2      tec_t2 1.00000000       0.00000000
125      tom_t2      tec_t2 1.00000000       0.00000000
126  flanker_t2      tec_t2 1.00000000       0.00000000
137       ht_t2       wm_t2 1.00000000       0.00000000
138       ec_t2       wm_t2 1.00000000       0.00000000
139       pa_t2       wm_t2 1.00000000       0.00000000
140       sd_t2       wm_t2 1.00000000       0.00000000
141        a_t2       wm_t2 1.00000000       0.00000000
142      tom_t2       wm_t2 0.17536493       0.14925207
143  flanker_t2       wm_t2 1.00000000       0.00000000
144      tec_t2       wm_t2 0.38332334       0.09449018
154       ht_t2     dccs_t2 1.00000000       0.00000000
155       ec_t2     dccs_t2 1.00000000       0.00000000
156       pa_t2     dccs_t2 1.00000000       0.00000000
157       sd_t2     dccs_t2 1.00000000       0.00000000
158        a_t2     dccs_t2 1.00000000       0.00000000
159      tom_t2     dccs_t2 1.00000000       0.00000000
160  flanker_t2     dccs_t2 1.00000000       0.00000000
161      tec_t2     dccs_t2 1.00000000       0.00000000
162       wm_t2     dccs_t2 0.80063987       0.02955106
171       ht_t2   cbq_na_t2 1.00000000       0.00000000
172       ec_t2   cbq_na_t2 1.00000000       0.00000000
173       pa_t2   cbq_na_t2 1.00000000       0.00000000
174       sd_t2   cbq_na_t2 1.00000000       0.00000000
175        a_t2   cbq_na_t2 1.00000000       0.00000000
176      tom_t2   cbq_na_t2 1.00000000       0.00000000
177  flanker_t2   cbq_na_t2 1.00000000       0.00000000
178      tec_t2   cbq_na_t2 1.00000000       0.00000000
179       wm_t2   cbq_na_t2 1.00000000       0.00000000
180     dccs_t2   cbq_na_t2 1.00000000       0.00000000
188       ht_t2  cbq_att_t2 1.00000000       0.00000000
189       ec_t2  cbq_att_t2 1.00000000       0.00000000
190       pa_t2  cbq_att_t2 1.00000000       0.00000000
191       sd_t2  cbq_att_t2 1.00000000       0.00000000
192        a_t2  cbq_att_t2 1.00000000       0.00000000
193      tom_t2  cbq_att_t2 1.00000000       0.00000000
194  flanker_t2  cbq_att_t2 1.00000000       0.00000000
195      tec_t2  cbq_att_t2 0.00079984       0.08536023
196       wm_t2  cbq_att_t2 1.00000000       0.00000000
197     dccs_t2  cbq_att_t2 1.00000000       0.00000000
198   cbq_na_t2  cbq_att_t2 1.00000000       0.00000000
205       ht_t2  cbq_shy_t2 0.06218756       0.01753731
206       ec_t2  cbq_shy_t2 1.00000000       0.00000000
207       pa_t2  cbq_shy_t2 1.00000000       0.00000000
208       sd_t2  cbq_shy_t2 1.00000000       0.00000000
209        a_t2  cbq_shy_t2 1.00000000       0.00000000
210      tom_t2  cbq_shy_t2 1.00000000       0.00000000
211  flanker_t2  cbq_shy_t2 1.00000000       0.00000000
212      tec_t2  cbq_shy_t2 1.00000000       0.00000000
213       wm_t2  cbq_shy_t2 1.00000000       0.00000000
214     dccs_t2  cbq_shy_t2 1.00000000       0.00000000
215   cbq_na_t2  cbq_shy_t2 0.20475905       0.18687596
216  cbq_att_t2  cbq_shy_t2 1.00000000       0.00000000
222       ht_t2 emque_ec_t2 1.00000000       0.00000000
223       ec_t2 emque_ec_t2 1.00000000       0.00000000
224       pa_t2 emque_ec_t2 1.00000000       0.00000000
225       sd_t2 emque_ec_t2 1.00000000       0.00000000
226        a_t2 emque_ec_t2 1.00000000       0.00000000
227      tom_t2 emque_ec_t2 1.00000000       0.00000000
228  flanker_t2 emque_ec_t2 1.00000000       0.00000000
229      tec_t2 emque_ec_t2 1.00000000       0.00000000
230       wm_t2 emque_ec_t2 1.00000000       0.00000000
231     dccs_t2 emque_ec_t2 1.00000000       0.00000000
232   cbq_na_t2 emque_ec_t2 1.00000000       0.00000000
233  cbq_att_t2 emque_ec_t2 1.00000000       0.00000000
234  cbq_shy_t2 emque_ec_t2 1.00000000       0.00000000
239       ht_t2 emque_af_t2 1.00000000       0.00000000
240       ec_t2 emque_af_t2 1.00000000       0.00000000
241       pa_t2 emque_af_t2 1.00000000       0.00000000
242       sd_t2 emque_af_t2 1.00000000       0.00000000
243        a_t2 emque_af_t2 1.00000000       0.00000000
244      tom_t2 emque_af_t2 1.00000000       0.00000000
245  flanker_t2 emque_af_t2 1.00000000       0.00000000
246      tec_t2 emque_af_t2 1.00000000       0.00000000
247       wm_t2 emque_af_t2 1.00000000       0.00000000
248     dccs_t2 emque_af_t2 1.00000000       0.00000000
249   cbq_na_t2 emque_af_t2 1.00000000       0.00000000
250  cbq_att_t2 emque_af_t2 1.00000000       0.00000000
251  cbq_shy_t2 emque_af_t2 1.00000000       0.00000000
252 emque_ec_t2 emque_af_t2 0.60067986       0.06614977
256       ht_t2 emque_pa_t2 1.00000000       0.00000000
257       ec_t2 emque_pa_t2 1.00000000       0.00000000
258       pa_t2 emque_pa_t2 1.00000000       0.00000000
259       sd_t2 emque_pa_t2 1.00000000       0.00000000
260        a_t2 emque_pa_t2 1.00000000       0.00000000
261      tom_t2 emque_pa_t2 1.00000000       0.00000000
262  flanker_t2 emque_pa_t2 1.00000000       0.00000000
263      tec_t2 emque_pa_t2 1.00000000       0.00000000
264       wm_t2 emque_pa_t2 1.00000000       0.00000000
265     dccs_t2 emque_pa_t2 1.00000000       0.00000000
266   cbq_na_t2 emque_pa_t2 1.00000000       0.00000000
267  cbq_att_t2 emque_pa_t2 1.00000000       0.00000000
268  cbq_shy_t2 emque_pa_t2 1.00000000       0.00000000
269 emque_ec_t2 emque_pa_t2 0.76044791       0.03481119
270 emque_af_t2 emque_pa_t2 0.13517297       0.16996290
273       ht_t2  csus_pt_t2 1.00000000       0.00000000
274       ec_t2  csus_pt_t2 1.00000000       0.00000000
275       pa_t2  csus_pt_t2 1.00000000       0.00000000
276       sd_t2  csus_pt_t2 1.00000000       0.00000000
277        a_t2  csus_pt_t2 1.00000000       0.00000000
278      tom_t2  csus_pt_t2 0.92081584       0.01528408
279  flanker_t2  csus_pt_t2 1.00000000       0.00000000
280      tec_t2  csus_pt_t2 0.64247151       0.05928222
281       wm_t2  csus_pt_t2 0.21555689       0.13926081
282     dccs_t2  csus_pt_t2 1.00000000       0.00000000
283   cbq_na_t2  csus_pt_t2 0.14097181       0.04261542
284  cbq_att_t2  csus_pt_t2 1.00000000       0.00000000
285  cbq_shy_t2  csus_pt_t2 0.19176165       0.12341783
286 emque_ec_t2  csus_pt_t2 1.00000000       0.00000000
287 emque_af_t2  csus_pt_t2 1.00000000       0.00000000
288 emque_pa_t2  csus_pt_t2 0.51289742       0.06058101


 CENTRALITY INVARIANCE TEST 
 Nodes tested: ht_t2 ec_t2 pa_t2 sd_t2 a_t2 tom_t2 flanker_t2 tec_t2 wm_t2 dccs_t2 cbq_na_t2 cbq_att_t2 cbq_shy_t2 emque_ec_t2 emque_af_t2 emque_pa_t2 csus_pt_t2 
 Centralities tested: expectedInfluence
 Test statistics C: 
            expectedInfluence
ht_t2             -0.02746544
ec_t2              0.01017391
pa_t2              0.22896392
sd_t2              0.28616504
a_t2               0.09836261
tom_t2            -0.21697866
flanker_t2        -0.09148413
tec_t2            -0.23913264
wm_t2             -0.41255411
dccs_t2           -0.02955106
cbq_na_t2          0.22949138
cbq_att_t2        -0.08536023
cbq_shy_t2         0.04592082
emque_ec_t2       -0.10096096
emque_af_t2       -0.23611267
emque_pa_t2       -0.26535510
csus_pt_t2        -0.35521053

 p-values: 
            expectedInfluence
ht_t2              0.88982204
ec_t2              0.94101180
pa_t2              0.09958008
sd_t2              0.13977205
a_t2               0.27774445
tom_t2             0.49870026
flanker_t2         0.72885423
tec_t2             0.45690862
wm_t2              0.24195161
dccs_t2            0.85522895
cbq_na_t2          0.14037193
cbq_att_t2         0.12857429
cbq_shy_t2         0.71985603
emque_ec_t2        0.59548090
emque_af_t2        0.26014797
emque_pa_t2        0.36312737
csus_pt_t2         0.33953209

#9. Across-Time Network Comparison

# if (file.exists(here("output", "models", "networks", "nct_t1_vs_t2.rds"))) {
#   
#   nct_t1_vs_t2 <- readRDS(here("output", "models", "networks", "nct_t1_vs_t2.rds"))
#   
#   summary(nct_t1_vs_t2)
# 
#   plot(nct_t1_vs_t2, what = "strength" )
# 
#   plot(nct_t1_vs_t2, what = "network")
# 
#   #plot(nct_4vs6, what = "centrality")
# 
#   #plot(nct_4vs6, what = "edge")
# } else {nct_t1_vs_t2 <- NetworkComparisonTest::NCT(network_ebicglasso_t1,
#                            network_ebicglasso_t2,
#                            gamma = 0.5,
#                            it = 5000,
#                            abs = FALSE, 
#                            edges = "yes",
#                            test.edges = TRUE,
#                            test.centrality = TRUE,
#                            centrality = "expectedInfluence",
#                            p.adjust.methods = "BH",
#                            paired = TRUE)
# 
#   saveRDS(nct_t1_vs_t2,
#         file = here("output", "models", "networks", "nct_t1_vs_t2.rds"))
# 
#   summary(nct_t1_vs_t2)
# 
#   plot(nct_t1_vs_t2, what = "strength" )
# 
#   plot(nct_t1_vs_t2, what = "network")
#   }

#10. Exploratory Graph Analysis

if (file.exists(here("output", "models", "networks", "ega_boot_t1.rds"))) {
  
  ega_boot_t1 <- readRDS(here("output", "models", "networks", "ega_boot_t1.rds"))
  
  ega_empirical_t1 <- EGAnet::EGA(
  data = data_t1,
  cor = "cor_auto",
  plot.EGA = FALSE
  )
  
  print(summary(ega_boot_t1))

  print(EGAnet::dimensionStability(ega_boot_t1, IS.plot = FALSE))
   
  ega_compare_t1 <- EGAnet::compare.EGA.plots(
      ega_empirical_t1,
      ega_boot_t1,
      labels = c("Empirical", "Bootstrap"),
      plot.all = FALSE
      )
} else {

ega_empirical_t1 <- EGAnet::EGA(
  data = data_t1,
  cor = "cor_auto",
  plot.EGA = FALSE
)

ega_boot_t1 <- EGAnet::bootEGA(
  data = data_t1,
  cor = "cor_auto",
  iter = 5000,
  plot.EGA = FALSE
)

saveRDS(ega_boot_t1,
        here("output", "models", "networks", "ega_boot_t1.rds"))

  print(summary(ega_boot_t1))

  print(EGAnet::dimensionStability(ega_boot_t1, IS.plot = FALSE))
   
ega_compare_t1 <- EGAnet::compare.EGA.plots(
    ega_empirical_t1,
    ega_boot_t1,
    labels = c("Empirical", "Bootstrap"),
    plot.all = FALSE
    )
}
Registered S3 method overwritten by 'car':
  method           from
  na.action.merMod lme4
Model: GLASSO (EBIC)
Correlations: cor_auto
Algorithm:  Walktrap
Unidimensional Method:  Louvain

----

EGA Type: EGA 
Bootstrap Samples: 5000 (Parametric)
                                       
                 3      4      5      6
Frequency:  0.0578 0.8134 0.1246 0.0042

Median dimensions: 4 [3.14, 4.86] 95% CINULL
EGA Type: EGA 
Bootstrap Samples: 5000 (Parametric)

Proportion Replicated in Dimensions:

      ht       ec       pa       sd        a      tom  flanker      tec 
  1.0000   1.0000   1.0000   1.0000   0.9382   1.0000   0.9984   1.0000 
      wm     dccs   cbq_na  cbq_att  cbq_shy emque_ec emque_af emque_pa 
  1.0000   0.7650   0.8382   0.5520   0.8382   0.9886   0.9886   0.8592 
 csus_pt 
  0.6494 

----

Structural Consistency:

     1      2      3      4 
0.9404 0.5260 0.8382 0.8596 
if (file.exists(here("output", "models", "networks", "ega_boot_t2.rds"))) {
  
  ega_boot_t2 <- readRDS(here("output", "models", "networks", "ega_boot_t2.rds"))
  
  ega_empirical_t2 <- EGAnet::EGA(
  data = data_t2,
  cor = "cor_auto",
  plot.EGA = FALSE
  )
  
  print(summary(ega_boot_t2))

  print(EGAnet::dimensionStability(ega_boot_t2, IS.plot = FALSE))
   
  ega_compare_t2 <- EGAnet::compare.EGA.plots(
      ega_empirical_t2,
      ega_boot_t2,
      labels = c("Empirical", "Bootstrap"),
      plot.all = FALSE
      )
} else {

ega_empirical_t2 <- EGAnet::EGA(
  data = data_t2,
  cor = "cor_auto",
  plot.EGA = FALSE
)

ega_boot_t2 <- EGAnet::bootEGA(
  data = data_t2,
  cor = "cor_auto",
  iter = 5000,
  plot.EGA = FALSE
)

saveRDS(ega_boot_t2,
        here("output", "models", "networks", "ega_boot_t2.rds"))

  print(summary(ega_boot_t2, ... = ))
  
  EGAnet::summary()

  print(EGAnet::dimensionStability(ega_boot_t2, IS.plot = FALSE))
   
ega_compare_t2 <- EGAnet::compare.EGA.plots(
    ega_empirical_t2,
    ega_boot_t2,
    labels = c("Empirical", "Bootstrap"),
    plot.all = FALSE
    )
}
Model: GLASSO (EBIC)
Correlations: cor_auto
Algorithm:  Walktrap
Unidimensional Method:  Louvain

----

EGA Type: EGA 
Bootstrap Samples: 5000 (Parametric)
                               
                 3     4      5
Frequency:  0.1856 0.776 0.0384

Median dimensions: 4 [3.12, 4.88] 95% CINULL
EGA Type: EGA 
Bootstrap Samples: 5000 (Parametric)

Proportion Replicated in Dimensions:

      ht       ec       pa       sd        a      tom  flanker      tec 
  1.0000   1.0000   1.0000   1.0000   1.0000   0.9986   0.9876   0.9980 
      wm     dccs   cbq_na  cbq_att  cbq_shy emque_ec emque_af emque_pa 
  0.9986   0.9912   0.9642   0.6764   0.9642   0.8276   0.8276   0.7250 
 csus_pt 
  0.6480 

----

Structural Consistency:

     1      2      3      4 
1.0000 0.9858 0.6142 0.7272 
compare.EGA.plots(ega_boot_t1,
                  ega_boot_t2,
                  labels = c("T1", "T2"))

$all


$individual
$individual[[1]]


$individual[[2]]

time <- as.numeric(data_long_npn$time)

time_invariance <- EGAnet::invariance(
  data = data_long_npn[,7:23],
  groups = time
)
Testing configural invariance...

Configural invariance was found with 15 variables
Testing metric invariance...
The default 'loading.method' has changed to "revised" in {EGAnet} version >= 2.0.7.

 For the previous default (version <= 2.0.6), use `loading.method = "original"`
The default 'loading.method' has changed to "revised" in {EGAnet} version >= 2.0.7.

 For the previous default (version <= 2.0.6), use `loading.method = "original"`
plot(time_invariance$configural.results$item_stability)
Ignoring unknown labels:
• fill : "Communities"
• linetype : "Communities"
• shape : "Communities"

plot(time_invariance)

summary(time_invariance)
Summary of Invariance Results 

Number of groups: 2 
Number of pairwise comparisons: 1 


Comparison: 1 vs 2 
Number of noninvariant items (p < 0.05): 1 (6.7%)
Number of noninvariant items (p_BH < 0.05): 1 (6.7%)

Use `print()` for more detailed results.
print(time_invariance)
Invariance Results 

Comparison: 1 vs 2 
         Membership Difference     p  p_BH sig Direction
ht                1     -0.028 0.576 0.720              
ec                1     -0.128 0.186 0.399              
pa                1     -0.188 0.060 0.300   .          
sd                1     -0.136 0.100 0.300   .          
a                 1     -0.097 0.094 0.300   .          
tom               2      0.024 0.738 0.852              
flanker           2     -0.088 0.294 0.551              
tec               2     -0.016 0.834 0.894              
wm                2     -0.051 0.536 0.720              
dccs              2     -0.224 0.002 0.030  **     1 < 2
cbq_na            3      0.021 0.416 0.624              
cbq_shy           3     -0.021 0.416 0.624              
emque_ec          4     -0.101 0.058 0.300   .          
emque_af          4      0.003 0.956 0.956              
emque_pa          4     -0.074 0.156 0.390              
----
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 'n.s.' 1