# Install and load qgraph and psych: install.packages(c("qgraph","psych"),dep=TRUE) library("qgraph") library("psych") # Load BFI data: data(bfi) bfi <- bfi[,1:25] # Groups and names object (not needed really, but make the plots easier to interpret): Names <- scan("http://sachaepskamp.com/files/BFIitems.txt", what = "character", sep = "\n") Groups <- rep(c('A','C','E','N','O'),each=5) # Compute correlations: cor_bfi <- cor_auto(bfi) # Plot correlation network: graph_cor <- qgraph(cor_bfi, layout = "spring", nodeNames = Names, groups = Groups, legend.cex =0.6) # Plot partial correlation network: graph_pcor <- qgraph(cor_bfi, graph = "concentration", layout = "spring", nodeNames = Names, groups = Groups, legend.cex =0.6) # Plot glasso network: graph_glas <- qgraph(cor_bfi, graph = "glasso", sampleSize = nrow(bfi), layout = "spring", nodeNames = Names, legend.cex =0.6, groups = Groups) # Centrality measures (glasso): centrality_auto(graph_glas) # centrality plot (glasso): centralityPlot(graph_glas, labels=Names) # centrality plot (all graphs): centralityPlot(list(cor = graph_cor, pcor = graph_pcor, glasso = graph_glas), labels=Names) # Clustering measures: clustcoef_auto(graph_glas) # Clustering plot: clusteringPlot(list(cor = graph_cor, pcor = graph_pcor, glasso = graph_glas), labels=Names) # Smallworldness: smallworldness(graph_glas)