Network metrics can be extracted using the function
extract_metric(bison_model, metric_name)
. The
metric_name
variable is made up of two parts: the network
feature and the network metric. For example, node_eigen
will calculate the eigenvector centrality of each node.
The following feature/metric pairs are currently supported in bisonR:
-
edge
- Edge-level properties-
weight
- Edge weight
-
-
node
- Node-level properties-
degree[t]
- Node degree (where t is the binary threshold for an edge) -
strength
- Node strength -
eigen
- Node eigenvector centrality -
betweenness
- Node betweenness -
closeness
- Node closeness -
clustering
- Node-level clustering coefficient
-
-
global
- Network-level properties-
density
- Weighted density -
cv
- Coefficient of variation of edge weights - also known as social differentiation -
std
- Standard deviation of edge weights -
diameter
- Diameter of the network -
clustering
- Clustering coefficient of the network - also known as transitivity
-
Examples
See below for examples of how to generate the network metrics listed above.
library(bisonR)
#> Loading required package: cmdstanr
#> This is cmdstanr version 0.6.0
#> - CmdStanR documentation and vignettes: mc-stan.org/cmdstanr
#> - CmdStan path: /home/runner/.cmdstan/cmdstan-2.32.2
#> - CmdStan version: 2.32.2
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
sim_data <- simulate_bison_model("binary", aggregated = TRUE)
df <- sim_data$df_sim
fit_edge <- bison_model(
(event | duration) ~ dyad(node_1_id, node_2_id),
data=df,
model_type="binary_conjugate",
priors=get_default_priors("binary_conjugate")
)
Edge
Edge weight
metrics <- extract_metric(fit_edge, "edge_weight", num_draws=10)
metrics[1:6, 1:5] # Preview first few samples and edges
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 4.8924773 1.0503140 1.2457936 2.464372 -1.0479794
#> [2,] 1.1143035 -0.6563552 0.2478771 1.565955 -0.6492542
#> [3,] 0.0953615 -0.8057166 -0.3968606 1.096896 -0.5441741
#> [4,] -0.9502620 -0.6585563 1.4192628 1.634613 -0.2781229
#> [5,] 2.5679828 -1.2388476 1.8376019 2.480110 1.2136049
#> [6,] 2.6648312 0.7381758 0.3152173 1.771346 -1.5424841
Node
Node degree
metrics <- extract_metric(fit_edge, "node_degree[0.2]")
metrics[1:6, 1:5] # Preview first few samples and nodes
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 9 8 7 8 8
#> [2,] 7 6 8 8 8
#> [3,] 7 6 6 9 8
#> [4,] 8 8 9 7 8
#> [5,] 9 6 7 7 8
#> [6,] 8 8 8 8 8
Node strength
metrics <- extract_metric(fit_edge, "node_strength", num_draws=10)
metrics[1:6, 1:5] # Preview first few samples and nodes
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 5.516674 6.231790 5.355593 5.157550 6.377006
#> [2,] 5.755396 6.062811 6.203890 4.939782 6.409306
#> [3,] 4.751005 6.082692 5.879320 5.551878 6.168587
#> [4,] 5.309583 3.945497 5.317942 5.079231 6.102656
#> [5,] 4.719506 3.593997 5.326996 3.337632 5.931005
#> [6,] 5.158812 5.314577 6.115566 4.691520 6.776485
Node eigenvector centrality
metrics <- extract_metric(fit_edge, "node_eigen")
metrics[1:6, 1:5] # Preview first few samples and nodes
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.7709416 0.8268392 0.8122154 0.8146290 1.0000000
#> [2,] 1.0000000 0.8450173 0.9452652 0.8664869 0.9929606
#> [3,] 0.9033606 0.7804688 0.8777111 0.6390672 1.0000000
#> [4,] 0.9204510 0.9583086 0.9824470 0.7392713 0.9834478
#> [5,] 0.8584216 0.7686363 0.8598711 0.6663035 0.9123913
#> [6,] 0.8603789 0.7682984 0.9825780 0.7582785 0.9745687
Node betweenness
metrics <- extract_metric(fit_edge, "node_betweenness")
metrics[1:6, 1:5] # Preview first few samples and nodes
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0 1 2 0 2
#> [2,] 0 1 1 0 1
#> [3,] 0 1 1 0 1
#> [4,] 0 0 0 0 0
#> [5,] 1 0 0 0 1
#> [6,] 1 0 1 0 0
Node closeness
metrics <- extract_metric(fit_edge, "node_closeness")
metrics[1:6, 1:5] # Preview first few samples and nodes
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.06057989 0.06556532 0.06349745 0.05776559 0.06966032
#> [2,] 0.06737337 0.06177000 0.06199146 0.05381018 0.07392337
#> [3,] 0.07224941 0.05901084 0.06793748 0.06066299 0.06042412
#> [4,] 0.06677771 0.06506665 0.06335622 0.05853553 0.07217058
#> [5,] 0.06420072 0.05715678 0.07677487 0.06045135 0.07450995
#> [6,] 0.07047507 0.06417592 0.07765820 0.05896865 0.07384517
Node-level clustering coefficient
metrics <- extract_metric(fit_edge, "node_clustering[0.2]")
metrics[1:6, 1:5] # Preview first few samples and nodes
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.9166667 0.9166667 0.9642857 0.9642857 0.9166667
#> [2,] 0.8888889 0.9285714 0.8928571 0.9285714 0.8888889
#> [3,] 0.8928571 0.9047619 0.9047619 0.8928571 0.8928571
#> [4,] 0.8055556 0.9047619 0.9047619 0.8928571 0.8928571
#> [5,] 0.8333333 0.8928571 0.8571429 0.9333333 0.8333333
#> [6,] 0.8214286 0.7777778 0.8214286 0.9047619 0.8214286
Global
Global coefficient of variation
metrics <- extract_metric(fit_edge, "global_cv")
metrics[1:6] # Preview first few samples
#> [1] 0.4899656 0.5206888 0.5420257 0.5169794 0.5034261 0.5263789
Global density
metrics <- extract_metric(fit_edge, "global_density")
metrics[1:6] # Preview first few samples
#> [1] 0.5558488 0.5944493 0.6147986 0.5825876 0.5807582 0.6145821
Global standard deviation of edge weights
metrics <- extract_metric(fit_edge, "global_std")
metrics[1:6] # Preview first few samples
#> [1] 0.2630823 0.3033708 0.3131161 0.2988569 0.2792150 0.2795077
Global diameter
metrics <- extract_metric(fit_edge, "global_diameter")
metrics[1:6] # Preview first few samples
#> [1] 0.6271193 0.7100829 0.8723304 0.6996885 0.6996885 0.8092036
Global clustering coefficient
metrics <- extract_metric(fit_edge, "global_clustering[0.2]")
metrics[1:6] # Preview first few samples
#> [1] 0.9030100 0.8873239 0.8488372 0.7797357 0.8947368 0.8267717