Examining Differences among Psychological Networks with Network Tree

R Psychometric

In this post, I will be visualizing differences between psychological networks with network tree to identify how the structure of the network changes across different population subgroups.

(7 min read)

Tarid Wongvorachan (University of Alberta)https://www.ualberta.ca
2023-12-08

Setting up and introducing the dataset

Show code
#read a csv file
df <- read.csv("riasec.csv", header = TRUE)

library(networktree)
library(bootnet)
library(tidyverse)

df_subsetted <- df[, c(1:48, 78, 81, 84)]

# save(df_subsetted, cor_RIASEC,
#      tree1, tree2, tree3, 
#      compare_tree, subtract_tree, 
#      net_engnat1, net_engnat2,
#      file = "riasec_tree.RData")
Show code
head(df_subsetted)
  R1 R2 R3 R4 R5 R6 R7 R8 I1 I2 I3 I4 I5 I6 I7 I8 A1 A2 A3 A4 A5 A6
1  3  4  3  1  1  4  1  3  5  5  4  3  4  5  4  3  5  4  1  2  4  5
2  1  1  2  4  1  2  2  1  5  5  5  4  4  4  4  4  2  1  4  2  1  3
3  2  1  1  1  1  1  1  1  4  1  1  1  1  1  1  1  1  1  1  2  1  1
4  3  1  1  2  2  2  2  2  4  1  2  4  3  2  3  2  5  2  4  5  1  4
5  4  1  1  2  1  1  1  2  5  5  5  3  5  5  5  3  3  5  5  5  5  5
6  3  5  1  3  1  5  3  4  4  5  4  4  4  3  3  5  5  5  4  5  5  5
  A7 A8 S1 S2 S3 S4 S5 S6 S7 S8 E1 E2 E3 E4 E5 E6 E7 E8 C1 C2 C3 C4
1  2  4  3  5  5  4  5  5  5  5  2  1  4  1  2  2  1  3  1  3  1  1
2  4  2  2  3  4  3  4  2  3  1  1  1  1  1  1  1  1  3  1  1  2  1
3  3  1  3  1  5  3  5  5  4  4  1  3  3  5  1  4  4  3  1  3  2  2
4  4  2  4  2  3  3  2  1  3  2  5  4  3  2  3  3  2  3  3  2  3  3
5  1  5  5  4  4  4  5  5  5  5  2  3  2  3  2  4  2  2  4  2  2  4
6  3  5  3  5  5  4  5  4  4  4  3  1  1  1  2  1  1  3  3  2  1  1
  C5 C6 C7 C8 education engnat religion
1  1  3  1  1         2      1        7
2  1  2  1  1         2      1        7
3  1  2  4  1         2      1        7
4  2  2  2  2         1      2        0
5  5  5  2  2         3      2        4
6  3  3  1  3         3      2        2
Show code
var_name <- colnames(df_subsetted)

cor_RIASEC <- cor(df_subsetted[,var_name])

riasec_dim <- list(R = 1:8,
                I = 9:16,
                A = 17:24,
                S = 25:32,
                E = 33:40,
                C = 41:48)

q1 <- qgraph::qgraph(cor_RIASEC, layout = "spring", labels = var_name, groups = riasec_dim,
                     color=c("#d73027", "#fc8d59", "#fee090", "#eddfea", "#91bfdb", "#7FFFD4"))
Network structure of the RIASEC dataset
Show code
qgraph::centralityPlot(q1, include ="all")
Centrality indices of the overall RIASEC network structure

Introducing Networktree

Network tree between educational level

Show code
tree2 <- networktree(R1 + R2 + R3 + R4 + R5 + R6 + R7 + R8 + I1 + I2 + I3 + I4 + I5 + 
    I6 + I7 + I8 + A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8 + S1 + 
    S2 + S3 + S4 + S5 + S6 + S7 + S8 + E1 + E2 + E3 + E4 + E5 + 
    E6 + E7 + E8 + C1 + C2 + C3 + C4 + C5 + C6 + C7 + C8 ~ education,
                         data = df_subsetted)

plot(tree2, labels = var_name, layout = "spring", groups = riasec_dim,
                     color=c("#d73027", "#fc8d59", "#fee090", "#eddfea", "#91bfdb", "#7FFFD4"))
Network tree X educational level

Network tree between native English status

Show code
tree3 <- networktree(R1 + R2 + R3 + R4 + R5 + R6 + R7 + R8 + I1 + I2 + I3 + I4 + I5 + 
    I6 + I7 + I8 + A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8 + S1 + 
    S2 + S3 + S4 + S5 + S6 + S7 + S8 + E1 + E2 + E3 + E4 + E5 + 
    E6 + E7 + E8 + C1 + C2 + C3 + C4 + C5 + C6 + C7 + C8 ~ engnat,
                         data = df_subsetted)

plot(tree3, labels = var_name, layout = "spring", groups = riasec_dim,
                     color=c("#d73027", "#fc8d59", "#fee090", "#eddfea", "#91bfdb", "#7FFFD4"))

print(tree3)
Network tree X native English status

Network tree between educational level and native English status

Show code
tree1 <- networktree(R1 + R2 + R3 + R4 + R5 + R6 + R7 + R8 + I1 + I2 + I3 + I4 + I5 + 
    I6 + I7 + I8 + A1 + A2 + A3 + A4 + A5 + A6 + A7 + A8 + S1 + 
    S2 + S3 + S4 + S5 + S6 + S7 + S8 + E1 + E2 + E3 + E4 + E5 + 
    E6 + E7 + E8 + C1 + C2 + C3 + C4 + C5 + C6 + C7 + C8 ~ education + engnat,
                         data = df_subsetted)

plot(tree1, labels = var_name, layout = "spring", groups = riasec_dim,
                     color=c("#d73027", "#fc8d59", "#fee090", "#eddfea", "#91bfdb", "#7FFFD4"))
Network tree X educational level and native English status

Understanding the difference between trees

Show code
compare_tree <- comparetree(tree_full, id1 = 2, id2 = 3, highlights = 4, plot = TRUE, plot.type = "compare",
                            groups = riasec_dim, color=c("#d73027", "#fc8d59", "#fee090", "#eddfea", "#91bfdb", "#7FFFD4"))
Show code
compare_tree$highlights
  node1 node2          id1        id2 (id1 - id2)
1    R2    R8  0.708318736 0.58935851   0.1189602
2    A1    A2  0.560195173 0.44242742   0.1177678
3    E2    E6  0.591883279 0.47636222   0.1155211
4    R1    S5 -0.005596371 0.09861601  -0.1042124
Compare tree3 additive
Show code
subtract_tree <- comparetree(tree1, highlights = 4, plot = TRUE, plot.type = "subtract", groups = riasec_dim, color=c("#d73027", "#fc8d59", "#fee090", "#eddfea", "#91bfdb", "#7FFFD4"))
Show code
subtract_tree$highlights
  node1 node2          id1        id2 (id1 - id2)
1    R2    R8  0.708318736 0.58935851   0.1189602
2    A1    A2  0.560195173 0.44242742   0.1177678
3    E2    E6  0.591883279 0.47636222   0.1155211
4    R1    S5 -0.005596371 0.09861601  -0.1042124
Compare tree3 substract

Compare centrality indices between two subgroups

Show code
engnat1 <- df_subsetted %>% filter(engnat == 1)
engnat2 <- df_subsetted %>% filter(engnat == 2)

net_engnat1 <- bootnet::estimateNetwork(engnat1[, 1:48], default = "ggmModSelect", verbose = FALSE)
net_engnat2 <- bootnet::estimateNetwork(engnat2[, 1:48], default = "ggmModSelect", verbose = FALSE)

qgraph::centralityPlot(net_engnat1, include ="all")
qgraph::centralityPlot(net_engnat2, include ="all")
Centrality engnat1
Centrality engnat2

Concluding remark

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".

Citation

For attribution, please cite this work as

Wongvorachan (2023, Dec. 8). Tarid Wongvorachan: Examining Differences among Psychological Networks with Network Tree. Retrieved from https://taridwong.github.io/posts/2023-12-08-networktree/

BibTeX citation

@misc{wongvorachan2023examining,
  author = {Wongvorachan, Tarid},
  title = {Tarid Wongvorachan: Examining Differences among Psychological Networks with Network Tree},
  url = {https://taridwong.github.io/posts/2023-12-08-networktree/},
  year = {2023}
}