install.packages("qgraph")
#see qgraph: Network Visualizations of Relationships in Psychometric Data for details
library(qgraph)
#load qgraph
For illustration purposes, code is illustrated using the pearson correlation matrix.
library(psych)
HDS.Sim.cor <- cor(SimData.HDS) #Pearson
HDS.Sim.tet <- tetrachoric(SimData.HDS) #Tetrachoric
groups <- c(rep("Narcissism", 14), rep("Psychoticism", 14), rep("Machievallianism", 14)) #color nodes by scale
##Correlation network##
netCor <- qgraph(HDS.Sim.cor, layout = "spring", labels = colnames(HDS.Sim.cor), groups = groups,
vsize=4, title = "A. Correlation Network", legend = F)
##Partial correlation network - Cut edge correlations < .10##
netPcor <- qgraph(HDS.Sim.cor, layout = "spring", labels = colnames(HDS.Sim.cor), groups = groups, graph = "concentration",
vsize = 4, title = "B. Partial Correlation Network", legend = F, cut = .10, esize = 10)
install.packages("parcor")
#Package for regularized estimation of partial correlation matrices
library(parcor)
Estimate the adaptive lasso network1.
set.seed(100)
adls <- adalasso.net(HDS.Sim) #compute partial correlation matrix via LASSO technique
network <- as.matrix(forceSymmetric(adls$pcor.adalasso)) #extract adaptive LASSO matrix
colnames(network) <- rownames(network) <- colnames(HDS.Sim)
Plot adaptive lasso network
netal <- qgraph(network, layout = "spring", labels = colnames(HDS.Sim), groups=groups, vsize=4, Title = "C. Adaptive LASSO Network", legend = F, cut = .10, esize = 10)
Create a uniform layout based upon the adapative lasso network (see Figure 2)
L <- netal$layout
qgraph(netCor, layout = L)
qgraph(netPcor, layout = L)
Creating partial correlation table (Table 2)
ew <- round(network,2)
ew[upper.tri(ew)] <- ""
ew <- as.data.frame(ew)
Descriptives and t-test for comparing difference in weights between positive v. negative edges
ew <- network[upper.tri(network)]
describe(ew)
sum(ew != 0)
sum (ew > 0)
sum (ew < 0)
t.test(abs (ew [ew > 0]), abs(ew [ew < 0]), var.equal = TRUE)
smallworldness(network)
#Calculate small-worldness index (Humphries & Gurney, 2008)
centrality <- centrality_auto(network)
#Calculate and store centrality indices (Betweenness, closeness, strength)
centralityPlot(network, theme_bw = FALSE)
#Visualize centrality indices
cluster <- clustcoef_auto(network)
#Calculate and store clustering coefficients
clusteringPlot(network, theme_bw = FALSE)
#Visualize multiple clustering coefficients
1 qgraph implements a similiar yet slightly distinct EBICglasso function.