# Convert to igraph object
g <- graph_from_adjacency_matrix(adj_matrix, mode = "directed", diag = FALSE)
# Degree centrality
degree_centrality <- degree(g, mode = "all")
# Betweenness centrality
betweenness_centrality <- betweenness(g)
# Closeness centrality
closeness_centrality <- closeness(g)
# Print summary
centrality_df <- data.frame(
Node = V(g)$name,
Degree = degree_centrality,
Betweenness = betweenness_centrality,
Closeness = closeness_centrality
)
print(centrality_df[order(-centrality_df$Degree), ])Calculate Network Measures
We can now calculate basic measures of the network structure.
These measures help us understand how nodes are connected and which nodes are most central within the network.
Copy and paste the following into your R script and run it:
The output shows the centrality values for each node in the network.
NoteCentrality measures
- Degree: number of connections a node has
- Betweenness: how often a node lies between other nodes
- Closeness: how close a node is to all others in the network
These measures will be used to help interpret the network in later steps.