--- title: "Resilience Factor Changes between Early and Later Adolescence" author: "J. Fritz, J. Stochl, E. I. Fried, I. M. Goodyer, C. D. van Borkulo, P. O. Wilkinson, A.-L. van Harmelen" date: "2019/April/10" --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ## Table of content ```{r} ##00: Opening data, loading packages, splitting data frame based on childhood adversity (CA; i.e. CA vs noCA) ##01: RF mean change analyses: Group comparisons (CA vs noCA) ##02: RF mean change analyses: Temporal comparisons (14 vs 17) ##03: RF mean change analyses: Do the change patterns of the RFs (between age 14 and 17) differ between the CA and the noCA group? ##04: RF data frames and correlation matrices for CA and noCA adolescents, for age 14 and 17, taking into account the general distress (GD) variable ##05: RF network models for CA and noCA adolescents, for age 14 and 17, taking into account GD ##06: Preparing the RF data frames for the network comparsion tests (taking into account GD) ##07: Contrasting RF network models that are corrected for GD between CA and noCA adolescents, and between age 14 and 17 ##08: Shortest pathways between the RFs and the GD variable ##09: Supplement IV: Repeating the mean change analyses for RF and GD scores derived from fully invarianct factor analyses ##10: Supplement VII: RF data frames and correlation matrices for CA and noCA adolescents, for age 14 and 17, without GD ##11: Supplement VII: RF network models for CA and noCA adolescents, for age 14 and 17, without GD ##12: Supplement VII: Preparing the RF data frames for the network comparsion tests (without GD) ##13: Supplement VII: Contrasting RF network models without GD between CA and noCA adolescents, and between age 14 and 17 ##14: Supplement VII: Contrasting RF network models with GD between CA and noCA adolescents, and between age 14 and 17 ##15: Supplement VIII: RF network models for CA and noCA adolescents, for age 14 and 17, with, without, and corrected for GD, with faded interrelations ##16: Supplement IX: Correlations and regularized partial correlations between the RFs and GD, for age 14 and 17 ##17: Supplement X: Accuracy and Stability of the CA and noCA networks, for age 14 and 17, with and without GD ##18: Supplement XI: RF centrality indices for networks corrected for GD, for age 14 and 17 ##19: Supplement XII: Repeating the network anlayses without the brooding variable ##20: Supplement XIII: Repeating the network anlayses with configural instead of fully invariant factor scores ``` ##00: Opening data, loading packages, splitting data frame based on childhood adversity (CA; i.e. CA vs noCA) ```{r} #opening data Net_data <- read.csv("location-data-file\\name-data-file.csv") #loading packages library("pastecs") library("coin") library("ggplot2") library("dplyr") library("sjPlot") library("qgraph") library("NetworkComparisonTest") library("bootnet") #splitting data frame CA_Network_Data <- subset(Net_data, Net_data$CA_dic==1) noCA_Network_Data <- subset(Net_data, Net_data$CA_dic==0) ``` ##01: RF mean change analyses: Group comparisons (CA vs noCA) ```{r} #a: friendship support age 14 wilcox.test(Net_data$FriendSupport_14_si ~ Net_data$CA_dic) #a: friendship support age 17 wilcox.test(Net_data$FriendSupport_17_si ~ Net_data$CA_dic) #b: family support age 14 wilcox.test(Net_data$FamilySupport_14_si ~ Net_data$CA_dic) #b: family support age 17 wilcox.test(Net_data$FamilySupport_17_si ~ Net_data$CA_dic) #c: family cohesion age 14 wilcox.test(Net_data$FamilyCohesion_14_si ~ Net_data$CA_dic) #c: family cohesion age 17 wilcox.test(Net_data$FamilyCohesion_17_si ~ Net_data$CA_dic) #d: negative self-esteem age 14 wilcox.test(Net_data$NegSes_14_si ~ Net_data$CA_dic) #d: negative self-esteem age 17 wilcox.test(Net_data$NegSes_17_si ~ Net_data$CA_dic) #e: positive self-esteem age 14 wilcox.test(Net_data$PosSes_14_si ~ Net_data$CA_dic) #e: positive self-esteem age 17 wilcox.test(Net_data$PosSes_17_si ~ Net_data$CA_dic) #f: brooding age 14 wilcox.test(Net_data$BrdNew_14_si ~ Net_data$CA_dic) #f: brooding age 17 wilcox.test(Net_data$BrdNew_17_si ~ Net_data$CA_dic) #g: reflection age 14 wilcox.test(Net_data$Reflection_14_si ~ Net_data$CA_dic) #g: reflection age 17 wilcox.test(Net_data$Reflection_17_si ~ Net_data$CA_dic) #h: distress tolerance age 14 wilcox.test(Net_data$DisTol_14_si ~ Net_data$CA_dic) #h: distress tolerance age 17 wilcox.test(Net_data$DisTol_17_si ~ Net_data$CA_dic) #i: general distress age 14 wilcox.test(Net_data$GeneralDistress_14_si ~ Net_data$CA_dic) #i: general distress age 17 wilcox.test(Net_data$GeneralDistress_17_si ~ Net_data$CA_dic) #j: aggression age 14 chi_agg <- table(Net_data$Aggression_14_bin, Net_data$CA_dic); chi_agg chisq.test(chi_agg) #j: aggression age 17 chi_agg <- table(Net_data$Aggression_17_bin, Net_data$CA_dic); chi_agg chisq.test(chi_agg) #k: expressive suppression age 14 chi_exs <- table(Net_data$ExpressiveSuppression14_bin, Net_data$CA_dic); chi_exs chisq.test(chi_exs) #k: expressive suppression age 17 chi_exs <- table(Net_data$ExpressiveSuppression17_bin, Net_data$CA_dic); chi_exs chisq.test(chi_exs) #j: FDR corrected p-vals #save the p-values in as a dataframe with the columns "CAvsnoCA_14" and "CAvsnoCA_17" #p_CAvsnoCA_14 padj_fdr_CAvsnoCA_14 <- p.adjust(p_vals$CAvsnoCA_14, method = "fdr"); padj_fdr_CAvsnoCA_14 #p_CAvsnoCA_17 padj_fdr_CAvsnoCA_17 <- p.adjust(p_vals$CAvsnoCA_17, method = "fdr"); padj_fdr_CAvsnoCA_17 ``` ##02: RF mean change analyses: Temporal comparisons (14 vs 17) ```{r} #a: frindshp 14 vs 17 CA wilcox.test(CA_Network_Data$FriendSupport_14_si, CA_Network_Data$FriendSupport_17_si, paired = TRUE) #a: frindshp 14 vs 17 noCA wilcox.test(noCA_Network_Data$FriendSupport_14_si, noCA_Network_Data$FriendSupport_17_si, paired = TRUE) #b: family 14 vs 17 CA wilcox.test(CA_Network_Data$FamilySupport_14_si, CA_Network_Data$FamilySupport_17_si, paired = TRUE) #b: family 14 vs 17 noCA wilcox.test(noCA_Network_Data$FamilySupport_14_si, noCA_Network_Data$FamilySupport_17_si, paired = TRUE) #c: family cohesion 14 vs 17 CA wilcox.test(CA_Network_Data$FamilyCohesion_14_si, CA_Network_Data$FamilyCohesion_17_si, paired = TRUE) #c: family cohesion 14 vs 17 noCA wilcox.test(noCA_Network_Data$FamilyCohesion_14_si, noCA_Network_Data$FamilyCohesion_17_si, paired = TRUE) #d: negative self-esteem 14 vs 17 CA wilcox.test(CA_Network_Data$NegSes_14_si, CA_Network_Data$NegSes_17_si, paired = TRUE) #d: negative self-esteem 14 vs 17 noCA wilcox.test(noCA_Network_Data$NegSes_14_si, noCA_Network_Data$NegSes_17_si, paired = TRUE) #e: positive self-esteem 14 vs 17 CA wilcox.test(CA_Network_Data$PosSes_14_si, CA_Network_Data$PosSes_17_si, paired = TRUE) #e: positive self-esteem 14 vs 17 noCA wilcox.test(noCA_Network_Data$PosSes_14_si, noCA_Network_Data$PosSes_17_si, paired = TRUE) #f: brooding 14 vs 17 CA wilcox.test(CA_Network_Data$BrdNew_14_si, CA_Network_Data$BrdNew_17_si, paired = TRUE) #f: brooding 14 vs 17 noCA wilcox.test(noCA_Network_Data$BrdNew_14_si, noCA_Network_Data$BrdNew_17_si, paired = TRUE) #g: reflection 14 vs 17 CA wilcox.test(CA_Network_Data$Reflection_14_si, CA_Network_Data$Reflection_17_si, paired = TRUE) #g: reflection 14 vs 17 noCA wilcox.test(noCA_Network_Data$Reflection_14_si, noCA_Network_Data$Reflection_17_si, paired = TRUE) #h: distress tolerance 14 vs 17 CA wilcox.test(CA_Network_Data$DisTol_14_si, CA_Network_Data$DisTol_17_si, paired = TRUE) #h: distress tolerance 14 vs 17 noCA wilcox.test(noCA_Network_Data$DisTol_14_si, noCA_Network_Data$DisTol_17_si, paired = TRUE) #i: general distress 14 vs 17 CA wilcox.test(CA_Network_Data$GeneralDistress_14_si, CA_Network_Data$GeneralDistress_17_si, paired = TRUE) #i: general distress 14 vs 17 noCA wilcox.test(noCA_Network_Data$GeneralDistress_14_si, noCA_Network_Data$GeneralDistress_17_si, paired = TRUE) #j: aggression 14 vs 17 CA wilcox.test(CA_Network_Data$Aggression_14_bin, CA_Network_Data$Aggression_17_bin, paired=TRUE) #j: aggression 14 vs 17 noCA wilcox.test(noCA_Network_Data$Aggression_14_bin, noCA_Network_Data$Aggression_17_bin, paired=TRUE) #k: expressive suppression age 14 vs 17 CA wilcox.test(CA_Network_Data$ExpressiveSuppression14_bin, CA_Network_Data$ExpressiveSuppression17_bin, paired=TRUE) #k: expressive suppression age 14 vs 17 noCA wilcox.test(noCA_Network_Data$ExpressiveSuppression14_bin, noCA_Network_Data$ExpressiveSuppression17_bin, paired=TRUE) #l: FDR corrected p-vals #save the p-values in as a dataframe with the columns "X14vs17_CA" and "X14vs17_noCA" #p_14vs17_CA padj_fdr_14vs17_CA <- p.adjust(p_vals$X14vs17_CA, method = "fdr"); padj_fdr_14vs17_CA #p_14vs17_noCA padj_fdr_14vs17_noCA <- p.adjust(p_vals$X14vs17_noCA, method = "fdr"); padj_fdr_14vs17_noCA ``` ##03: RF mean change analyses: Do the change patterns of the RFs (between age 14 and 17) differ between the CA and the noCA group? ```{r} ##example for the continuous RF friendship support #a: rename the variables for occasion 1 and occasion 2 Friend.wide <- data.frame(Net_data$FriendSupport_14_si, Net_data$FriendSupport_17_si, Net_data$id, Net_data$CA_dic) library("dplyr") Friend.wide <- rename(Friend.wide, FriendSupport_occ1 = Net_data.FriendSupport_14_si) Friend.wide <- rename(Friend.wide, FriendSupport_occ2 = Net_data.FriendSupport_17_si) Friend.wide <- rename(Friend.wide, id = Net_data.id) Friend.wide <- rename(Friend.wide, CA_dic = Net_data.CA_dic) detach("package:dplyr", unload=TRUE) #b: reformat the data frame as long, remove missing data, and code the CA variable as factor library("reshape") Friend.long <- reshape(Friend.wide, varying=c("FriendSupport_occ1","FriendSupport_occ2"), idvar="id",timevar = "occasion",direction="long",sep="_") detach("package:reshape", unload=TRUE) model <- data.frame(Friend.long$FriendSupport, Friend.long$CA_dic, Friend.long$occasion) mod <- na.omit(model) mod$Friend.long.CA_dic <- as.factor(mod$Friend.long.CA_dic) #c: run the moderation analysis maineffects <- lm(Friend.long.FriendSupport ~ Friend.long.CA_dic + Friend.long.occasion, data=mod); summary(maineffects) moderation <- lm(Friend.long.FriendSupport ~ Friend.long.CA_dic*Friend.long.occasion, data=mod); summary(moderation) #d: plot the moderation analysis plot_model(moderation, type = "pred", terms = c("Friend.long.occasion", "Friend.long.CA_dic")) ##example for the dichotomous RF aggression potential #a: rename the variables for occasion 1 and occasion 2 AGG.wide <- data.frame(Net_data$Aggression_14_bin, Net_data$Aggression_17_bin, Net_data$id, Net_data$CA_dic) library("dplyr") AGG.wide <- rename(AGG.wide, AGG_occ1 = Net_data.Aggression_14_bin) AGG.wide <- rename(AGG.wide, AGG_occ2 = Net_data.Aggression_17_bin) AGG.wide <- rename(AGG.wide, id = Net_data.id) AGG.wide <- rename(AGG.wide, CA_dic = Net_data.CA_dic) detach("package:dplyr", unload=TRUE) #b: reformat the data frame as long, remove missing data, and code the CA variable and the resilience factor as factor library("reshape") AGG.long <- reshape(AGG.wide, varying=c("AGG_occ1","AGG_occ2"), idvar="id",timevar = "occasion",direction="long",sep="_") detach("package:reshape", unload=TRUE) model <- data.frame(AGG.long$AGG, AGG.long$CA_dic, AGG.long$occasion) mod <- na.omit(model) mod$AGG.long.CA_dic <- as.factor(mod$AGG.long.CA_dic) mod$AGG.long.AGG <- as.factor(mod$AGG.long.AGG) #c: run the moderation analysis maineffects <- glm(AGG.long.AGG ~ AGG.long.CA_dic + AGG.long.occasion, data=mod, family=binomial(link = "logit")); summary(maineffects) moderation <- glm(AGG.long.AGG ~ AGG.long.CA_dic*AGG.long.occasion, data=mod, family=binomial(link = "logit")); summary(moderation) #EST = 0.2380 exp(0.2380) #d: plot the moderation analysis plot_model(moderation, type = "pred", terms = c("AGG.long.occasion", "AGG.long.CA_dic")) ``` ##04: RF data frames and correlation matrices for CA and noCA adolescents, for age 14 and 17, taking into account the general distress (GD) variable ```{r} #a: Making the CA network data frame and correlation matrix for age 14 with GD CA_a14_GD_data <- data.frame(CA_Network_Data$FriendSupport_14_fi_tr, CA_Network_Data$FamilySupport_14_fi_tr, CA_Network_Data$FamilyCohesion_14_fi_tr, CA_Network_Data$PosSes_14_fi_tr, CA_Network_Data$NegSes_14_fi_tr, CA_Network_Data$BrdNew_14_fi_tr, CA_Network_Data$Reflection_14_fi_tr, CA_Network_Data$DisTol_14_fi_tr, CA_Network_Data$Aggression_14_bin, CA_Network_Data$ExpressiveSuppression14_bin, CA_Network_Data$GeneralDistress_14_fi_tr) CA_a14_cor_GD <- cor_auto(CA_a14_GD_data); max(CA_a14_cor_GD[upper.tri(CA_a14_cor_GD,diag=FALSE)]) # 0.7225167 #b: Making the noCA network data frame and correlation matrix for age 14 with GD noCA_a14_GD_data <- data.frame(noCA_Network_Data$FriendSupport_14_fi_tr, noCA_Network_Data$FamilySupport_14_fi_tr, noCA_Network_Data$FamilyCohesion_14_fi_tr, noCA_Network_Data$PosSes_14_fi_tr, noCA_Network_Data$NegSes_14_fi_tr, noCA_Network_Data$BrdNew_14_fi_tr, noCA_Network_Data$Reflection_14_fi_tr, noCA_Network_Data$DisTol_14_fi_tr, noCA_Network_Data$Aggression_14_bin, noCA_Network_Data$ExpressiveSuppression14_bin, noCA_Network_Data$GeneralDistress_14_fi_tr) noCA_a14_cor_GD <- cor_auto(noCA_a14_GD_data); max(noCA_a14_cor_GD[upper.tri(noCA_a14_cor_GD,diag=FALSE)]) # 0.7022132 #c: Making the CA network data frame and correlation matrix for age 17 with GD CA_a17_GD_data <- data.frame(CA_Network_Data$FriendSupport_17_fi_tr, CA_Network_Data$FamilySupport_17_fi_tr, CA_Network_Data$FamilyCohesion_17_fi_tr, CA_Network_Data$PosSes_17_fi_tr, CA_Network_Data$NegSes_17_fi_tr, CA_Network_Data$BrdNew_17_fi_tr, CA_Network_Data$Reflection_17_fi_tr, CA_Network_Data$DisTol_17_fi_tr, CA_Network_Data$Aggression_17_bin, CA_Network_Data$ExpressiveSuppression17_bin, CA_Network_Data$GeneralDistress_17_fi_tr) CA_a17_cor_GD <- cor_auto(CA_a17_GD_data); max(CA_a17_cor_GD[upper.tri(CA_a17_cor_GD,diag=FALSE)]) # 0.7459274 #d: Making the noCA network data frame and correlation matrix for age 17 with GD noCA_a17_GD_data <- data.frame(noCA_Network_Data$FriendSupport_17_fi_tr, noCA_Network_Data$FamilySupport_17_fi_tr, noCA_Network_Data$FamilyCohesion_17_fi_tr, noCA_Network_Data$PosSes_17_fi_tr, noCA_Network_Data$NegSes_17_fi_tr, noCA_Network_Data$BrdNew_17_fi_tr, noCA_Network_Data$Reflection_17_fi_tr, noCA_Network_Data$DisTol_17_fi_tr, noCA_Network_Data$Aggression_17_bin, noCA_Network_Data$ExpressiveSuppression17_bin, noCA_Network_Data$GeneralDistress_17_fi_tr) noCA_a17_cor_GD <- cor_auto(noCA_a17_GD_data); max(noCA_a17_cor_GD[upper.tri(noCA_a17_cor_GD,diag=FALSE)]) # 0.7272325 ``` ##05: RF network models for CA and noCA adolescents, for age 14 and 17, taking into account GD ```{r} #RF networks with GD #set.seed(99) #Layout11_GD <- averageLayout(CA_a14_GD, noCA_a14_GD, CA_a17_GD, noCA_a17_GD); dput(Layout11_GD) Layout11_GD <- structure(c(-0.223572293194913, 0.474820143338557, 0.646309113850157, -0.822892477179424, -1, -0.277794001071531, 0.115273643149332, 0.440224168079278, -0.826566950350062, 1, -0.479865678652014, 0.890465769390171, 1, 0.638138199657798, 0.796120987391392, 0.250402787867299, -0.766101677441511, -1, -0.264521327088009, -0.417361750985539, -0.0759513435886436, 0.016282613266049), .Dim = c(11L, 2L)) #b1: CA_a14_cor + GD CA_a14_GD <- qgraph(CA_a14_cor_GD, layout = Layout11_GD, graph = "glasso", details = TRUE, nodeNames = colnames(CA_a14_cor_GD), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(CA_a14_GD_data)) #b2: noCA_a14_cor + GD noCA_a14_GD <- qgraph(noCA_a14_cor_GD, layout = Layout11_GD, graph = "glasso", details = TRUE, nodeNames = colnames(noCA_a14_cor_GD), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(noCA_a14_GD_data)) #b3: CA_a17_cor + GD CA_a17_GD <- qgraph(CA_a17_cor_GD, layout = Layout11_GD, graph = "glasso", details = TRUE, nodeNames = colnames(CA_a17_cor_GD), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(CA_a17_GD_data)) #b4: noCA_a17_cor + GD noCA_a17_GD <- qgraph(noCA_a17_cor_GD, layout = Layout11_GD, graph = "glasso", details = TRUE, nodeNames = colnames(noCA_a17_cor_GD), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(noCA_a17_GD_data)) ``` ##06: Preparing the RF data frames for the network comparsion tests (taking into account GD) ```{r} ##rename variables so that they are equal for the two groups, and at the two ime points library("dplyr") #a: CA_a14_GD CA_14_NCT_GD <- CA_a14_GD_data CA_14_NCT_GD <- rename(CA_14_NCT_GD, friendsupport = CA_Network_Data.FriendSupport_14_fi_tr) CA_14_NCT_GD <- rename(CA_14_NCT_GD, familysupport = CA_Network_Data.FamilySupport_14_fi_tr) CA_14_NCT_GD <- rename(CA_14_NCT_GD, familycohesion = CA_Network_Data.FamilyCohesion_14_fi_tr) CA_14_NCT_GD <- rename(CA_14_NCT_GD, positiveselfesteem = CA_Network_Data.PosSes_14_fi_tr) CA_14_NCT_GD <- rename(CA_14_NCT_GD, negativeselfesteem = CA_Network_Data.NegSes_14_fi_tr) CA_14_NCT_GD <- rename(CA_14_NCT_GD, brooding = CA_Network_Data.BrdNew_14_fi_tr) CA_14_NCT_GD <- rename(CA_14_NCT_GD, reflection = CA_Network_Data.Reflection_14_fi_tr) CA_14_NCT_GD <- rename(CA_14_NCT_GD, distresstolerance = CA_Network_Data.DisTol_14_fi_tr) CA_14_NCT_GD <- rename(CA_14_NCT_GD, aggression = CA_Network_Data.Aggression_14_bin) CA_14_NCT_GD <- rename(CA_14_NCT_GD, expressivesuppression = CA_Network_Data.ExpressiveSuppression14_bin) CA_14_NCT_GD <- rename(CA_14_NCT_GD, generaldistress = CA_Network_Data.GeneralDistress_14_fi_tr) #b: noCA_a14_GD noCA_14_NCT_GD <- noCA_a14_GD_data noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , friendsupport = noCA_Network_Data.FriendSupport_14_fi_tr) noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , familysupport = noCA_Network_Data.FamilySupport_14_fi_tr) noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , familycohesion = noCA_Network_Data.FamilyCohesion_14_fi_tr) noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , positiveselfesteem = noCA_Network_Data.PosSes_14_fi_tr) noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , negativeselfesteem = noCA_Network_Data.NegSes_14_fi_tr) noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , brooding = noCA_Network_Data.BrdNew_14_fi_tr) noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , reflection = noCA_Network_Data.Reflection_14_fi_tr) noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , distresstolerance = noCA_Network_Data.DisTol_14_fi_tr) noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , aggression = noCA_Network_Data.Aggression_14_bin) noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , expressivesuppression = noCA_Network_Data.ExpressiveSuppression14_bin) noCA_14_NCT_GD <- rename(noCA_14_NCT_GD , generaldistress = noCA_Network_Data.GeneralDistress_14_fi_tr) #c: CA_a17_GD CA_17_NCT_GD <- CA_a17_GD_data CA_17_NCT_GD <- rename(CA_17_NCT_GD , friendsupport = CA_Network_Data.FriendSupport_17_fi_tr) CA_17_NCT_GD <- rename(CA_17_NCT_GD , familysupport = CA_Network_Data.FamilySupport_17_fi_tr) CA_17_NCT_GD <- rename(CA_17_NCT_GD , familycohesion = CA_Network_Data.FamilyCohesion_17_fi_tr) CA_17_NCT_GD <- rename(CA_17_NCT_GD , positiveselfesteem = CA_Network_Data.PosSes_17_fi_tr) CA_17_NCT_GD <- rename(CA_17_NCT_GD , negativeselfesteem = CA_Network_Data.NegSes_17_fi_tr) CA_17_NCT_GD <- rename(CA_17_NCT_GD, brooding = CA_Network_Data.BrdNew_17_fi_tr) CA_17_NCT_GD <- rename(CA_17_NCT_GD , reflection = CA_Network_Data.Reflection_17_fi_tr) CA_17_NCT_GD <- rename(CA_17_NCT_GD , distresstolerance = CA_Network_Data.DisTol_17_fi_tr) CA_17_NCT_GD <- rename(CA_17_NCT_GD , aggression = CA_Network_Data.Aggression_17_bin) CA_17_NCT_GD <- rename(CA_17_NCT_GD , expressivesuppression = CA_Network_Data.ExpressiveSuppression17_bin) CA_17_NCT_GD <- rename(CA_17_NCT_GD, generaldistress = CA_Network_Data.GeneralDistress_17_fi_tr) #d: noCA_a17_GD noCA_17_NCT_GD <- noCA_a17_GD_data noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , friendsupport = noCA_Network_Data.FriendSupport_17_fi_tr) noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , familysupport = noCA_Network_Data.FamilySupport_17_fi_tr) noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , familycohesion = noCA_Network_Data.FamilyCohesion_17_fi_tr) noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , positiveselfesteem = noCA_Network_Data.PosSes_17_fi_tr) noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , negativeselfesteem = noCA_Network_Data.NegSes_17_fi_tr) noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , brooding = noCA_Network_Data.BrdNew_17_fi_tr) noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , reflection = noCA_Network_Data.Reflection_17_fi_tr) noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , distresstolerance = noCA_Network_Data.DisTol_17_fi_tr) noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , aggression = noCA_Network_Data.Aggression_17_bin) noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , expressivesuppression = noCA_Network_Data.ExpressiveSuppression17_bin) noCA_17_NCT_GD <- rename(noCA_17_NCT_GD , generaldistress = noCA_Network_Data.GeneralDistress_17_fi_tr) ``` ##07: Contrasting RF network models that are corrected for GD between CA and noCA adolescents, and between age 14 and 17 ```{r} ## Network comparison test for expected influence are adapted from van Borkulo et al. (2017; Comparing network structures on three aspects: A permutation test. Manuscript submitted for publication) and can be requested from the first author jf585@cam.ac.uk. set.seed(10) #a: CA vs noCA corrected for GD, age 14 CA_a14_vs_noCA_a14_correctedGD_EI <- NCT_cor_auto_corrected_EI(CA_14_NCT_GD, noCA_14_NCT_GD, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7),c(2,8), c(2,9),c(2,10),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(4,5),c(4,6),c(4,7),c(4,8),c(4,9),c(4,10), c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(6,7),c(6,8),c(6,9),c(6,10),c(7,8),c(7,9),c(7,10),c(8,9),c(8,10),c(9,10)), progressbar=TRUE); summary(CA_a14_vs_noCA_a14_correctedGD_EI) #b: CA vs noCA corrected for GD, age 17 CA_a17_vs_noCA_a17_correctedGD_EI <- NCT_cor_auto_corrected_EI(CA_17_NCT_GD, noCA_17_NCT_GD, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7),c(2,8), c(2,9),c(2,10),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(4,5),c(4,6),c(4,7),c(4,8),c(4,9),c(4,10), c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(6,7),c(6,8),c(6,9),c(6,10),c(7,8),c(7,9),c(7,10),c(8,9),c(8,10),c(9,10)), progressbar=TRUE); summary(CA_a17_vs_noCA_a17_correctedGD_EI) #c: age 14 vs 17 corrected for GD, for CA networks CA_a14_vs_CA_a17_correctedGD_EI <- NCT_cor_auto_corrected_paired_EI(CA_14_NCT_GD, CA_17_NCT_GD, it=5000, binary.data = FALSE, paired = TRUE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7),c(2,8), c(2,9),c(2,10),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(4,5),c(4,6),c(4,7),c(4,8),c(4,9),c(4,10), c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(6,7),c(6,8),c(6,9),c(6,10),c(7,8),c(7,9),c(7,10),c(8,9),c(8,10),c(9,10)), progressbar=TRUE); summary(CA_a14_vs_CA_a17_correctedGD_EI) #d: age 14 vs 17 corrected for GD, for noCA networks noCA_a14_vs_noCA_a17_correctedGD_EI <- NCT_cor_auto_corrected_paired_EI(noCA_14_NCT_GD, noCA_17_NCT_GD, it=5000, binary.data = FALSE, paired = TRUE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7),c(2,8), c(2,9),c(2,10),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(4,5),c(4,6),c(4,7),c(4,8),c(4,9),c(4,10), c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(6,7),c(6,8),c(6,9),c(6,10),c(7,8),c(7,9),c(7,10),c(8,9),c(8,10),c(9,10)), progressbar=TRUE); summary(noCA_a14_vs_noCA_a17_correctedGD_EI) ``` ##08: Shortest pathways between the RFs and the GD variable ```{r} ##Making the data frames and networks #a1: CA_a14 with GD CA_14_NCT_GD_cor <- cor_auto(CA_14_NCT_GD) CA_a14_GD <- qgraph(CA_14_NCT_GD_cor, layout = Layout11_GD, graph = "glasso", details = TRUE, nodeNames = colnames(CA_14_NCT_GD_cor), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(CA_14_NCT_GD)) pathways(CA_a14_GD, from = c(1,2,3,4,5,6,7,8,9,10), to = c(11)) flow(CA_a14_GD, from = c(11), horizontal = TRUE, equalize = FALSE, minCurve = 2, maxCurve = 4,unfadeFirst = TRUE, fade = TRUE) #b1: noCA_a14 with GD noCA_14_NCT_GD_cor <- cor_auto(noCA_14_NCT_GD) noCA_a14_GD <- qgraph(noCA_14_NCT_GD_cor, layout = Layout11_GD, graph = "glasso", details = TRUE, nodeNames = colnames(noCA_14_NCT_GD_cor), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(noCA_14_NCT_GD)) pathways(noCA_a14_GD, from = c(1,2,3,4,5,6,7,8,9,10), to = c(11)) flow(noCA_a14_GD, from = c(11), horizontal = TRUE, equalize = FALSE, minCurve = 2, maxCurve = 4,unfadeFirst = TRUE, fade = TRUE) #c1: CA_a17 with GD CA_17_NCT_GD_cor <- cor_auto(CA_17_NCT_GD) CA_a17_GD <- qgraph(CA_17_NCT_GD_cor, layout = Layout11_GD, graph = "glasso", details = TRUE, nodeNames = colnames(CA_17_NCT_GD_cor), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(CA_17_NCT_GD)) pathways(CA_a17_GD, from = c(1,2,3,4,5,6,7,8,9,10), to = c(11)) flow(CA_a17_GD, from = c(11), horizontal = TRUE, equalize = FALSE, minCurve = 2, maxCurve = 4,unfadeFirst = TRUE, fade = TRUE) #d1: noCA_a17 with GD noCA_17_NCT_GD_cor <- cor_auto(noCA_17_NCT_GD) noCA_a17_GD <- qgraph(noCA_17_NCT_GD_cor, layout = Layout11_GD, graph = "glasso", details = TRUE, nodeNames = colnames(noCA_17_NCT_GD_cor), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(noCA_17_NCT_GD)) pathways(noCA_a17_GD, from = c(1,2,3,4,5,6,7,8,9,10), to = c(11)) flow(noCA_a17_GD, from = c(11), horizontal = TRUE, equalize = FALSE, minCurve = 2, maxCurve = 4,unfadeFirst = TRUE, fade = TRUE) ##group comparisons: SPL set.seed(16) NCT_EI_compare_GD_14_SPL <- NCT_cor_auto_EI_for_GD_SPL(CA_14_NCT_GD, noCA_14_NCT_GD, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = FALSE, progressbar=TRUE); summary(NCT_EI_compare_GD_14_SPL) NCT_EI_compare_GD_17_SPL <- NCT_cor_auto_EI_for_GD_SPL(CA_17_NCT_GD, noCA_17_NCT_GD, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = FALSE, progressbar=TRUE); summary(NCT_EI_compare_GD_17_SPL) ##temporal comparisons: SPL set.seed(16) NCT_EI_compare_GD_CA_SPL <- NCT_cor_auto_paired_EI_for_GD_SPL(CA_14_NCT_GD, CA_17_NCT_GD, it=5000, binary.data = FALSE, paired = TRUE, weighted=TRUE, test.edges = FALSE, progressbar=TRUE); summary(NCT_EI_compare_GD_CA_SPL) NCT_EI_compare_GD_noCA_SPL <- NCT_cor_auto_paired_EI_for_GD_SPL(noCA_14_NCT_GD, noCA_17_NCT_GD, it=5000, binary.data = FALSE, paired = TRUE, weighted=TRUE, test.edges = FALSE, progressbar=TRUE); summary(NCT_EI_compare_GD_noCA_SPL) ##group comparisons: direct effects set.seed(16) NCT_EI_compare_GD_14 <- NCT_cor_auto_EI_for_GD(CA_14_NCT_GD, noCA_14_NCT_GD, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = FALSE, progressbar=TRUE); summary(NCT_EI_compare_GD_14) NCT_EI_compare_GD_17 <- NCT_cor_auto_EI_for_GD(CA_17_NCT_GD, noCA_17_NCT_GD, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = FALSE, progressbar=TRUE); summary(NCT_EI_compare_GD_17) ##temporal comparisons: direct effects set.seed(16) NCT_EI_compare_GD_CA <- NCT_cor_auto_paired_EI_for_GD(CA_14_NCT_GD, CA_17_NCT_GD, it=5000, binary.data = FALSE, paired = TRUE, weighted=TRUE, test.edges = FALSE, progressbar=TRUE); summary(NCT_EI_compare_GD_CA) NCT_EI_compare_GD_noCA <- NCT_cor_auto_paired_EI_for_GD(noCA_14_NCT_GD, noCA_17_NCT_GD, it=5000, binary.data = FALSE, paired = TRUE, weighted=TRUE, test.edges = FALSE, progressbar=TRUE); summary(NCT_EI_compare_GD_noCA) ``` ##09: Supplement IV: Repeating the mean change analyses for RF and GD scores derived from fully invarianct factor analyses ```{r} ##Please repeat the analyses reported in section ##01 (RF mean change analyses: Group comparisons (CA vs noCA)) and section ##02 (RF mean change analyses: Temporal comparisons (14 vs 17)), this time with the following variables: #FriendSupport_14_fi & FriendSupport_17_fi #FamilySupport_14_fi & FamilySupport_17_fi #FamilyCohesion_14_fi & FamilyCohesion_17_fi #NegSes_14_fi & NegSes_17_fi #PosSes_14_fi & PosSes_17_fi #BrdNew_14_fi & BrdNew_17_fi #Reflection_14_fi & Reflection_17_fi #DisTol_14_fi & DisTol_17_fi #GeneralDistress_14_fi & GeneralDistress_17_fi ``` ##10: Supplement VII: RF data frames and correlation matrices for CA and noCA adolescents, for age 14 and 17, without GD ```{r} ##without GD #a: Making the CA network data frame and correlation matrix for age 14 without GD CA_a14_data <- data.frame(CA_Network_Data$FriendSupport_14_fi_tr, CA_Network_Data$FamilySupport_14_fi_tr, CA_Network_Data$FamilyCohesion_14_fi_tr, CA_Network_Data$PosSes_14_fi_tr, CA_Network_Data$NegSes_14_fi_tr, CA_Network_Data$BrdNew_14_fi_tr, CA_Network_Data$Reflection_14_fi_tr, CA_Network_Data$DisTol_14_fi_tr, CA_Network_Data$Aggression_14_bin, CA_Network_Data$ExpressiveSuppression14_bin) CA_a14_cor <- cor_auto(CA_a14_data); max(CA_a14_cor[upper.tri(CA_a14_cor,diag=FALSE)]) # 0.7225167 #b: Making the noCA network data frame and correlation matrix for age 14 without GD noCA_a14_data <- data.frame(noCA_Network_Data$FriendSupport_14_fi_tr, noCA_Network_Data$FamilySupport_14_fi_tr, noCA_Network_Data$FamilyCohesion_14_fi_tr, noCA_Network_Data$PosSes_14_fi_tr, noCA_Network_Data$NegSes_14_fi_tr, noCA_Network_Data$BrdNew_14_fi_tr, noCA_Network_Data$Reflection_14_fi_tr, noCA_Network_Data$DisTol_14_fi_tr, noCA_Network_Data$Aggression_14_bin, noCA_Network_Data$ExpressiveSuppression14_bin) noCA_a14_cor <- cor_auto(noCA_a14_data); max(noCA_a14_cor[upper.tri(noCA_a14_cor,diag=FALSE)]) # 0.7022132 #c: Making the CA network data frame and correlation matrix for age 17 without GD CA_a17_data <- data.frame(CA_Network_Data$FriendSupport_17_fi_tr, CA_Network_Data$FamilySupport_17_fi_tr, CA_Network_Data$FamilyCohesion_17_fi_tr, CA_Network_Data$PosSes_17_fi_tr, CA_Network_Data$NegSes_17_fi_tr, CA_Network_Data$BrdNew_17_fi_tr, CA_Network_Data$Reflection_17_fi_tr, CA_Network_Data$DisTol_17_fi_tr, CA_Network_Data$Aggression_17_bin, CA_Network_Data$ExpressiveSuppression17_bin) CA_a17_cor <- cor_auto(CA_a17_data); max(CA_a17_cor[upper.tri(CA_a17_cor,diag=FALSE)]) # 0.7459274 #d: Making the noCA network data frame and correlation matrix for age 17 without GD noCA_a17_data <- data.frame(noCA_Network_Data$FriendSupport_17_fi_tr, noCA_Network_Data$FamilySupport_17_fi_tr, noCA_Network_Data$FamilyCohesion_17_fi_tr, noCA_Network_Data$PosSes_17_fi_tr, noCA_Network_Data$NegSes_17_fi_tr, noCA_Network_Data$BrdNew_17_fi_tr, noCA_Network_Data$Reflection_17_fi_tr, noCA_Network_Data$DisTol_17_fi_tr, noCA_Network_Data$Aggression_17_bin, noCA_Network_Data$ExpressiveSuppression17_bin) noCA_a17_cor <- cor_auto(noCA_a17_data); max(noCA_a17_cor[upper.tri(noCA_a17_cor,diag=FALSE)]) # 0.7272325 ``` ##11: Supplement VII: RF network models for CA and noCA adolescents, for age 14 and 17, without GD ```{r} #networks without GD Layout10 <- structure(c(-0.223572293194913, 0.474820143338557, 0.646309113850157, -0.822892477179424, -1, -0.277794001071531, 0.115273643149332, 0.440224168079278, -0.826566950350062, 1, 0.890465769390171, 1, 0.638138199657798, 0.796120987391392, 0.250402787867299, -0.766101677441511, -1, -0.264521327088009, -0.417361750985539, -0.0759513435886436), .Dim = c(10L, 2L)) #a1: CA_a14_cor CA_a14 <- qgraph(CA_a14_cor, layout = Layout10, graph = "glasso", details = TRUE, nodeNames = colnames(CA_a14_cor), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(CA_a14_data)) #a2: noCA_a14_cor noCA_a14 <- qgraph(noCA_a14_cor, layout = Layout10, graph = "glasso", details = TRUE, nodeNames = colnames(noCA_a14_cor), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(noCA_a14_data)) #a3: CA_a17_cor CA_a17 <- qgraph(CA_a17_cor, layout = Layout10, graph = "glasso", details = TRUE, nodeNames = colnames(CA_a17_cor), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(CA_a17_data)) #a4: noCA_a17_cor noCA_a17 <- qgraph(noCA_a17_cor, layout = Layout10, graph = "glasso", details = TRUE, nodeNames = colnames(noCA_a17_cor), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(noCA_a17_data)) ``` ##12: Supplement VII: Preparing the RF data frames for the network comparsion tests (without GD) ```{r} ##rename variables so that they are equal for the two groups, and at the two ime points #a: CA_a14 CA_14_NCT <- CA_a14_data CA_14_NCT <- rename(CA_14_NCT , friendsupport = CA_Network_Data.FriendSupport_14_fi_tr) CA_14_NCT <- rename(CA_14_NCT , familysupport = CA_Network_Data.FamilySupport_14_fi_tr) CA_14_NCT <- rename(CA_14_NCT , familycohesion = CA_Network_Data.FamilyCohesion_14_fi_tr) CA_14_NCT <- rename(CA_14_NCT , positiveselfesteem = CA_Network_Data.PosSes_14_fi_tr) CA_14_NCT <- rename(CA_14_NCT , negativeselfesteem = CA_Network_Data.NegSes_14_fi_tr) CA_14_NCT <- rename(CA_14_NCT , brooding = CA_Network_Data.BrdNew_14_fi_tr) CA_14_NCT <- rename(CA_14_NCT , reflection = CA_Network_Data.Reflection_14_fi_tr) CA_14_NCT <- rename(CA_14_NCT , distresstolerance = CA_Network_Data.DisTol_14_fi_tr) CA_14_NCT <- rename(CA_14_NCT , aggression = CA_Network_Data.Aggression_14_bin) CA_14_NCT <- rename(CA_14_NCT , expressivesuppression = CA_Network_Data.ExpressiveSuppression14_bin) #b: noCA_a14 noCA_14_NCT <- noCA_a14_data noCA_14_NCT <- rename(noCA_14_NCT , friendsupport = noCA_Network_Data.FriendSupport_14_fi_tr) noCA_14_NCT <- rename(noCA_14_NCT , familysupport = noCA_Network_Data.FamilySupport_14_fi_tr) noCA_14_NCT <- rename(noCA_14_NCT , familycohesion = noCA_Network_Data.FamilyCohesion_14_fi_tr) noCA_14_NCT <- rename(noCA_14_NCT , positiveselfesteem = noCA_Network_Data.PosSes_14_fi_tr) noCA_14_NCT <- rename(noCA_14_NCT , negativeselfesteem = noCA_Network_Data.NegSes_14_fi_tr) noCA_14_NCT <- rename(noCA_14_NCT , brooding = noCA_Network_Data.BrdNew_14_fi_tr) noCA_14_NCT <- rename(noCA_14_NCT , reflection = noCA_Network_Data.Reflection_14_fi_tr) noCA_14_NCT <- rename(noCA_14_NCT , distresstolerance = noCA_Network_Data.DisTol_14_fi_tr) noCA_14_NCT <- rename(noCA_14_NCT , aggression = noCA_Network_Data.Aggression_14_bin) noCA_14_NCT <- rename(noCA_14_NCT , expressivesuppression = noCA_Network_Data.ExpressiveSuppression14_bin) #c: CA_a17 CA_17_NCT <- CA_a17_data CA_17_NCT <- rename(CA_17_NCT , friendsupport = CA_Network_Data.FriendSupport_17_fi_tr) CA_17_NCT <- rename(CA_17_NCT , familysupport = CA_Network_Data.FamilySupport_17_fi_tr) CA_17_NCT <- rename(CA_17_NCT , familycohesion = CA_Network_Data.FamilyCohesion_17_fi_tr) CA_17_NCT <- rename(CA_17_NCT , positiveselfesteem = CA_Network_Data.PosSes_17_fi_tr) CA_17_NCT <- rename(CA_17_NCT , negativeselfesteem = CA_Network_Data.NegSes_17_fi_tr) CA_17_NCT <- rename(CA_17_NCT , brooding = CA_Network_Data.BrdNew_17_fi_tr) CA_17_NCT <- rename(CA_17_NCT , reflection = CA_Network_Data.Reflection_17_fi_tr) CA_17_NCT <- rename(CA_17_NCT , distresstolerance = CA_Network_Data.DisTol_17_fi_tr) CA_17_NCT <- rename(CA_17_NCT , aggression = CA_Network_Data.Aggression_17_bin) CA_17_NCT <- rename(CA_17_NCT , expressivesuppression = CA_Network_Data.ExpressiveSuppression17_bin) #d: noCA_a17 noCA_17_NCT <- noCA_a17_data noCA_17_NCT <- rename(noCA_17_NCT , friendsupport = noCA_Network_Data.FriendSupport_17_fi_tr) noCA_17_NCT <- rename(noCA_17_NCT , familysupport = noCA_Network_Data.FamilySupport_17_fi_tr) noCA_17_NCT <- rename(noCA_17_NCT , familycohesion = noCA_Network_Data.FamilyCohesion_17_fi_tr) noCA_17_NCT <- rename(noCA_17_NCT , positiveselfesteem = noCA_Network_Data.PosSes_17_fi_tr) noCA_17_NCT <- rename(noCA_17_NCT , negativeselfesteem = noCA_Network_Data.NegSes_17_fi_tr) noCA_17_NCT <- rename(noCA_17_NCT , brooding = noCA_Network_Data.BrdNew_17_fi_tr) noCA_17_NCT <- rename(noCA_17_NCT , reflection = noCA_Network_Data.Reflection_17_fi_tr) noCA_17_NCT <- rename(noCA_17_NCT , distresstolerance = noCA_Network_Data.DisTol_17_fi_tr) noCA_17_NCT <- rename(noCA_17_NCT , aggression = noCA_Network_Data.Aggression_17_bin) noCA_17_NCT <- rename(noCA_17_NCT , expressivesuppression = noCA_Network_Data.ExpressiveSuppression17_bin) ``` ##13: Supplement VII: Contrasting RF network models without GD between CA and noCA adolescents, and between age 14 and 17 ```{r} ## Network comparison test for expected influence is adapted from van Borkulo et al. (2017; Comparing network structures on three aspects: A permutation test. Manuscript submitted for publication) and can be requested from the first author jf585@cam.ac.uk. set.seed(12) #a: CA vs noCA without GD, age 14 CA_a14_vs_noCA_a14_EI <- NCT_cor_auto_EI(CA_14_NCT, noCA_14_NCT, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7),c(2,8), c(2,9),c(2,10),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(4,5),c(4,6),c(4,7),c(4,8),c(4,9),c(4,10), c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(6,7),c(6,8),c(6,9),c(6,10),c(7,8),c(7,9),c(7,10),c(8,9),c(8,10),c(9,10)), progressbar=TRUE); summary(CA_a14_vs_noCA_a14_EI) #b: CA vs noCA without GD, age 17 CA_a17_vs_noCA_a17_EI <- NCT_cor_auto_EI(CA_17_NCT, noCA_17_NCT, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7),c(2,8), c(2,9),c(2,10),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(4,5),c(4,6),c(4,7),c(4,8),c(4,9),c(4,10), c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(6,7),c(6,8),c(6,9),c(6,10),c(7,8),c(7,9),c(7,10),c(8,9),c(8,10),c(9,10)), progressbar=TRUE); summary(CA_a17_vs_noCA_a17_EI) #c: age 14 vs 17 without GD, for CA networks CA_a14_vs_CA_a17_EI <- NCT_cor_auto_EI(CA_14_NCT, CA_17_NCT, it=5000, binary.data = FALSE, paired = TRUE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7),c(2,8), c(2,9),c(2,10),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(4,5),c(4,6),c(4,7),c(4,8),c(4,9),c(4,10), c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(6,7),c(6,8),c(6,9),c(6,10),c(7,8),c(7,9),c(7,10),c(8,9),c(8,10),c(9,10)), progressbar=TRUE); summary(CA_a14_vs_CA_a17_EI) #d: age 14 vs 17 without GD, for noCA networks noCA_a14_vs_noCA_a17_EI <- NCT_cor_auto_EI(noCA_14_NCT, noCA_17_NCT, it=5000, binary.data = FALSE, paired = TRUE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7),c(2,8), c(2,9),c(2,10),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(4,5),c(4,6),c(4,7),c(4,8),c(4,9),c(4,10), c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(6,7),c(6,8),c(6,9),c(6,10),c(7,8),c(7,9),c(7,10),c(8,9),c(8,10),c(9,10)), progressbar=TRUE); summary(noCA_a14_vs_noCA_a17_EI) ``` ##14: Supplement VII: Contrasting RF network models with GD between CA and noCA adolescents, and between age 14 and 17 ```{r} ## Network comparison test for expected influence is adapted from van Borkulo et al. (2017; Comparing network structures on three aspects: A permutation test. Manuscript submitted for publication) and can be requested from the first author jf585@cam.ac.uk. set.seed(4) #a: CA vs noCA with GD, age 14 CA_a14_vs_noCA_a14_GD_EI <- NCT_cor_auto_EI(CA_14_NCT_GD, noCA_14_NCT_GD, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(1,11),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7), c(2,8),c(2,9),c(2,10),c(2,11),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(3,11),c(4,5),c(4,6),c(4,7), c(4,8),c(4,9),c(4,10),c(4,11),c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(5,11),c(6,7),c(6,8),c(6,9),c(6,10),c(6,11), c(7,8),c(7,9),c(7,10),c(7,11),c(8,9),c(8,10),c(8,11),c(9,10),c(9,11),c(10,11)), progressbar=TRUE); summary(CA_a14_vs_noCA_a14_GD_EI) #b: CA vs noCA with GD, age 17 CA_a17_vs_noCA_a17_GD_EI <- NCT_cor_auto_EI(CA_17_NCT_GD, noCA_17_NCT_GD, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(1,11),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7), c(2,8),c(2,9),c(2,10),c(2,11),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(3,11),c(4,5),c(4,6),c(4,7), c(4,8),c(4,9),c(4,10),c(4,11),c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(5,11),c(6,7),c(6,8),c(6,9),c(6,10),c(6,11), c(7,8),c(7,9),c(7,10),c(7,11),c(8,9),c(8,10),c(8,11),c(9,10),c(9,11),c(10,11)), progressbar=TRUE); summary(CA_a17_vs_noCA_a17_GD_EI) #c: age 14 vs 17 with GD, for CA networks CA_a14_vs_CA_a17_GD_EI <- NCT_cor_auto_EI(CA_14_NCT_GD, CA_17_NCT_GD, it=5000, binary.data = FALSE, paired = TRUE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(1,11),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7), c(2,8),c(2,9),c(2,10),c(2,11),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(3,11),c(4,5),c(4,6),c(4,7), c(4,8),c(4,9),c(4,10),c(4,11),c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(5,11),c(6,7),c(6,8),c(6,9),c(6,10),c(6,11), c(7,8),c(7,9),c(7,10),c(7,11),c(8,9),c(8,10),c(8,11),c(9,10),c(9,11),c(10,11)), progressbar=TRUE); summary(CA_a14_vs_CA_a17_GD_EI) #d: age 14 vs 17 with GD, for noCA networks noCA_a14_vs_noCA_a17_GD_EI <- NCT_cor_auto_EI(noCA_14_NCT_GD, noCA_17_NCT_GD, it=5000, binary.data = FALSE, paired = TRUE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(1,10),c(1,11),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7), c(2,8),c(2,9),c(2,10),c(2,11),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(3,10),c(3,11),c(4,5),c(4,6),c(4,7), c(4,8),c(4,9),c(4,10),c(4,11),c(5,6),c(5,7),c(5,8),c(5,9),c(5,10),c(5,11),c(6,7),c(6,8),c(6,9),c(6,10),c(6,11), c(7,8),c(7,9),c(7,10),c(7,11),c(8,9),c(8,10),c(8,11),c(9,10),c(9,11),c(10,11)), progressbar=TRUE); summary(noCA_a14_vs_noCA_a17_GD_EI) ``` ##15: Supplement VIII: RF network models for CA and noCA adolescents, for age 14 and 17, with, without, and corrected for GD, with faded interrelations ```{r} ##For the analyses in Supplement V, please repeat the analyses in section ##05 (RF network models for CA and noCA adolescents, for age 14 and 17, taking into account GD) and section ##11 (Supplement IV: RF network models for CA and noCA adolescents, for age 14 and 17, without GD)), this time with the command "fade = TRUE" instead of "fade = FALSE". ``` ##16: Supplement IX: Correlations and regularized partial correlations between the RFs and GD, for age 14 and 17 ```{r} ##age 14: for CA #a: correlation CA_a14_GD_zo <- qgraph(CA_a14_cor_GD, layout = Layout11_GD, graph = "cor", details = TRUE, nodeNames = colnames(CA_a14_cor_GD), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(CA_a14_GD_data)) x <- getWmat(CA_a14_GD_zo); x[,11] #b: regularized partial correlation y <- getWmat(CA_a14_GD); y[,11] ##age 14: for noCA #a: correlation noCA_a14_GD_zo <- qgraph(noCA_a14_cor_GD, layout = Layout11_GD, graph = "cor", details = TRUE, nodeNames = colnames(noCA_a14_cor_GD), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(noCA_a14_GD_data)) z <- getWmat(noCA_a14_GD_zo); z[,11] #b: regularized partial correlation xx <- getWmat(noCA_a14_GD); xx[,11] ##age 17: for CA #a: correlation CA_a17_GD_zo <- qgraph(CA_a17_cor_GD, layout = Layout11_GD, graph = "cor", details = TRUE, nodeNames = colnames(CA_a17_cor_GD), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(CA_a17_GD_data)) x <- getWmat(CA_a17_GD_zo); x[,11] #b: regularized partial correlation y <- getWmat(CA_a17_GD); y[,11] ##age 17: for noCA #a: correlation noCA_a17_GD_zo <- qgraph(noCA_a17_cor_GD, layout = Layout11_GD, graph = "cor", details = TRUE, nodeNames = colnames(noCA_a17_cor_GD), maximum = 0.74, minimum = 0, cut = 0, legend = FALSE, theme = "colorblind", fade = FALSE, sampleSize = nrow(noCA_a17_GD_data)) z <- getWmat(noCA_a17_GD_zo); z[,11] #b: regularized partial correlation xx <- getWmat(noCA_a17_GD); xx[,11] ``` ##17: Supplement X: Accuracy and Stability of the CA and noCA networks, for age 14 and 17, with and without GD ```{r} ##age 14: without GD #a1: CA network CA_a14_accuracy <- bootnet(CA_a14_data, default = "EBICglasso", type = "nonparametric", nCores = 8, nBoots = 2000, statistics = c("edge", "expectedInfluence")) plot(CA_a14_accuracy, labels = TRUE, order = "id") CA_a14_stability <- bootnet(CA_a14_data, default = "EBICglasso", type = "case", nCores = 8, caseN = 25, nBoots = 2000, statistics = c("expectedInfluence")) plot(CA_a14_stability, statistics = c("expectedInfluence")) corStability(CA_a14_stability, statistics = c("expectedInfluence"), cor = 0.7) #a2: noCA network noCA_a14_accuracy <- bootnet(noCA_a14_data, default = "EBICglasso", type = "nonparametric", nCores = 8, nBoots = 2000, statistics = c("edge", "expectedInfluence")) plot(noCA_a14_accuracy, labels = TRUE, order = "id") noCA_a14_stability <- bootnet(noCA_a14_data, default = "EBICglasso", type = "case", nCores = 8, caseN = 25, nBoots = 2000, statistics = c("expectedInfluence")) plot(noCA_a14_stability, statistics = c("expectedInfluence")) corStability(noCA_a14_stability, statistics = c("expectedInfluence"), cor = 0.7) ##age 17: without GD #b1: CA network CA_a17_accuracy <- bootnet(CA_a17_data, default = "EBICglasso", type = "nonparametric", nCores = 8, nBoots = 2000, statistics = c("edge", "expectedInfluence")) plot(CA_a17_accuracy, labels = TRUE, order = "id") CA_a17_stability <- bootnet(CA_a17_data, default = "EBICglasso", type = "case", nCores = 8, caseN = 25, nBoots = 2000, statistics = c("expectedInfluence")) plot(CA_a17_stability, statistics = c("expectedInfluence")) corStability(CA_a17_stability, statistics = c("expectedInfluence"), cor = 0.7) #b2: noCA network noCA_a17_accuracy <- bootnet(noCA_a17_data, default = "EBICglasso", type = "nonparametric", nCores = 8, nBoots = 2000, statistics = c("edge", "expectedInfluence")) plot(noCA_a17_accuracy, labels = TRUE, order = "id") noCA_a17_stability <- bootnet(noCA_a17_data, default = "EBICglasso", type = "case", nCores = 8, caseN = 25, nBoots = 2000, statistics = c("expectedInfluence")) plot(noCA_a17_stability, statistics = c("expectedInfluence")) corStability(noCA_a17_stability, statistics = c("expectedInfluence"), cor = 0.7) ##age 14: with GD #c1: CA network CA_a14_GD_accuracy <- bootnet(CA_a14_GD_data, default = "EBICglasso", type = "nonparametric", nCores = 8, nBoots = 2000, statistics = c("edge", "expectedInfluence")) plot(CA_a14_GD_accuracy, labels = TRUE, order = "id") CA_a14_GD_stability <- bootnet(CA_a14_GD_data, default = "EBICglasso", type = "case", nCores = 8, caseN = 25, nBoots = 2000, statistics = c("expectedInfluence")) plot(CA_a14_GD_stability, statistics = c("expectedInfluence")) corStability(CA_a14_GD_stability, statistics = c("expectedInfluence"), cor = 0.7) #c2: noCA network noCA_a14_GD_accuracy <- bootnet(noCA_a14_GD_data, default = "EBICglasso", type = "nonparametric", nCores = 8, nBoots = 2000, statistics = c("edge", "expectedInfluence")) plot(noCA_a14_GD_accuracy, labels = TRUE, order = "id") noCA_a14_GD_stability <- bootnet(noCA_a14_GD_data, default = "EBICglasso", type = "case", nCores = 8, caseN = 25, nBoots = 2000, statistics = c("expectedInfluence")) plot(noCA_a14_GD_stability, statistics = c("expectedInfluence")) corStability(noCA_a14_GD_stability, statistics = c("expectedInfluence"), cor = 0.7) ##age 17: with GD #d1: CA network CA_a17_GD_accuracy <- bootnet(CA_a17_GD_data, default = "EBICglasso", type = "nonparametric", nCores = 8, nBoots = 2000, statistics = c("edge", "expectedInfluence")) plot(CA_a17_GD_accuracy, labels = TRUE, order = "id") CA_a17_GD_stability <- bootnet(CA_a17_GD_data, default = "EBICglasso", type = "case", nCores = 8, caseN = 25, nBoots = 2000, statistics = c("expectedInfluence")) plot(CA_a17_GD_stability, statistics = c("expectedInfluence")) corStability(CA_a17_GD_stability, statistics = c("expectedInfluence"), cor = 0.7) #d1: noCA network noCA_a17_GD_accuracy <- bootnet(noCA_a17_GD_data, default = "EBICglasso", type = "nonparametric", nCores = 8, nBoots = 2000, statistics = c("edge", "expectedInfluence")) plot(noCA_a17_GD_accuracy, labels = TRUE, order = "id") noCA_a17_GD_stability <- bootnet(noCA_a17_GD_data, default = "EBICglasso", type = "case", nCores = 8, caseN = 25, nBoots = 2000, statistics = c("expectedInfluence")) plot(noCA_a17_GD_stability, statistics = c("expectedInfluence")) corStability(noCA_a17_GD_stability, statistics = c("expectedInfluence"), cor = 0.7) ``` ##18: Supplement XI: RF centrality indices for networks corrected for GD, for age 14 and 17 ```{r} #a: CA, age 14 a1 <- getWmat(CA_a14_GD) CA_a14_corGD_EI <- colSums(a1[-c(11),-c(11)]); CA_a14_corGD_EI #b: noCA, age 14 a2 <- getWmat(noCA_a14_GD) noCA_a14_corGD_EI <- colSums(a2[-c(11),-c(11)]); noCA_a14_corGD_EI #c: CA, age 17 a3 <- getWmat(CA_a17_GD) CA_a17_corGD_EI <- colSums(a3[-c(11),-c(11)]); CA_a17_corGD_EI #d: noCA, age 17 a4 <- getWmat(noCA_a17_GD) noCA_a17_corGD_EI <- colSums(a4[-c(11),-c(11)]); noCA_a17_corGD_EI ``` ##19: Supplement XII: Repeating the network anlayses without the brooding variable ```{r} ##For the analyses in Supplement IX, please repeat the analyses in section ##04 until ##07 and ##10 until 14, this time excluding the brooding variables ("CA_Network_Data$BrdNew_14_fi_tr", "noCA_Network_Data$BrdNew_14_fi_tr", "CA_Network_Data$BrdNew_17_fi_tr", and "noCA_Network_Data$BrdNew_17_fi_tr") from the data frames/ correlation matrices in the sections ##04, ##06, ##10, and ##12. ##Please note, that you accordinlgy need to adapt the layout for the network figures in section ##05 and ##11: #a: RF networks without GD Layout9 <- structure(c(-0.223572293194913, 0.474820143338557, 0.646309113850157, -0.822892477179424, -1, 0.115273643149332, 0.440224168079278, -0.826566950350062, 1, 0.890465769390171, 1, 0.638138199657798, 0.796120987391392, 0.250402787867299, -1, -0.264521327088009, -0.417361750985539, -0.0759513435886436), .Dim = c(9L, 2L)) #b: RF networks with GD Layout10_GD <- structure(c(-0.223572293194913, 0.474820143338557, 0.646309113850157, -0.822892477179424, -1, 0.115273643149332, 0.440224168079278, -0.826566950350062, 1, -0.479865678652014, 0.890465769390171, 1, 0.638138199657798, 0.796120987391392, 0.250402787867299, -1, -0.264521327088009, -0.417361750985539, -0.0759513435886436, 0.016282613266049), .Dim = c(10L, 2L)) #Also note, that you need to remove the redundant edges from the network comparison test commands in section ##07, ##13 and ##14 (alongside an adapted network comparison script for the networks corrected for GD): #here is an example for the comparison for CA vs noCA at age 14 (as in section ##07): CA_a14_vs_noCA_a14_correctedGD_EI <- NCT_cor_auto_corrected_EI(CA_14_NCT_GD, noCA_14_NCT_GD, it=5000, binary.data = FALSE, paired = FALSE, weighted=TRUE, test.edges = TRUE, edges = list(c(1,2),c(1,3),c(1,4),c(1,5),c(1,6),c(1,7),c(1,8),c(1,9),c(2,3),c(2,4),c(2,5),c(2,6),c(2,7),c(2,8), c(2,9),c(3,4),c(3,5),c(3,6),c(3,7),c(3,8),c(3,9),c(4,5),c(4,6),c(4,7),c(4,8),c(4,9), c(5,6),c(5,7),c(5,8),c(5,9),c(6,7),c(6,8),c(6,9),c(7,8),c(7,9),c(8,9)), progressbar=TRUE); summary(CA_a14_vs_noCA_a14_correctedGD_EI) ``` ##20: Supplement XIII: Repeating the network anlayses with configural instead of fully invariant factor scores ```{r} ##For the analyses in Supplement XI, please repeat the analyses in section ##04 until ##07 and ##10 until 14, this time using the below variables for the data frames/ correlation matrices in the sections ##04, ##06, ##10, and ##12: #FriendSupport_14_ci & FriendSupport_17_ci #FamilySupport_14_ci & FamilySupport_17_ci #FamilyCohesion_14_ci & FamilyCohesion_17_ci #PosSes_14_ci & PosSes_17_ci #NegSes_14_ci & NegSes_17_ci #BrdNew_14_ci & BrdNew_17_ci #Reflection_14_ci & Reflection_17_ci #DisTol_14_ci & DisTol_17_ci #Aggression_14_bin & Aggression_17_bin #ExpressiveSuppression14_bin & ExpressiveSuppression17_bin #GeneralDistress_14_ci & GeneralDistress_17_ci ##Please note, here you can use the same layout for the network figures as in section ##05 and ##11, but you need to make sure that "GeneralDistress_14/7_ci" is the last variable in the data frames/ correlation matrices. ```