The tidygraph
package is really fantastic for computing network statistics. However, I have a network with a temporal dimension, and I'd like to calculate network statistics (e.g. centrality) over each of those networks. (E.g. calculate centrality separate for each date.)
I imagine there's a way to do this via purrr and map, but I'm struggling with the exact syntax. Any help here is appreciated. Repex example below.
library(tidygraph)
library('purrr')
library(dplyr)
library(tidyr)
# example network data with temporal dimension
edges <- tibble(
from = c(1, 2, 2, 3, 4, 1, 2, 3, 4, 4, 4, 2),
to = c(2, 3, 4, 2, 1, 2, 3, 4, 3, 2, 1, 3),
date = c(rep(1,4), rep(2,4), rep(3,4))
)
nodes <- tibble(id = 1:4)
# calculate centrality over all time periods of network
graph <-
tbl_graph(
nodes = nodes,
edges = edges,
directed = FALSE
)
graph_out <-
graph %>%
mutate(cent_alpha = centrality_alpha()))
# calculate centrality for each time period of the network?
edges_list <-
split(edges, edges$date)
# this doesn't work for me
graph_list <-
lmap(edges_list,
~ tbl_graph(nodes = nodes, edges = .x, directed = FALSE))
## Yikes... no idea
graph_out <-