测量 igraph 中网络列表的分类性?

Measure the assortativity of a list of networks in igraph?

我想测量网络列表的分类能力。这就是我生成列表的方式。

nodes <- data.frame("Nodes" = 1:22,
                    "Type" = c(rep(1, 18), rep(0, 4)) # for measuring assortativity

set.seed(1)
nwl <- list()
for (x in seq_len(1000L)) {
    Start = 22, 500, replace=TRUE)
    End   = 22, 500, replace=TRUE)
    df = data.frame(Start, End)
    nwl[[x]]= graph_from_data_frame(df, 
                                    vertices = nodes,
                                    directed=TRUE)
}

我想在我的列表的 sapply() 函数中应用类似 assortativity(network, V(network)$Type, directed =T) 的内容。

我试过sapply(nwl, V(nwl)$Type, directed =T)sapply(nwl, sapply(nwl, V)$Type, directed = T)sapply(nwl, sapply(nwl, V, $Type), directed = T)

如果没有更好的方法可以做到这一点 sapply 我也会感激不尽。

如果我没理解错的话,您想遍历网络列表 nwl 并应用 assortativity 函数。在 base R 中,这可以实现如下:

sapply(nwl, function(network) assortativity(network, V(network)$Type, directed =T))

在这里,我将一个匿名函数传递给围绕 assortativity 构建的 sapply。一种更直观的方法,更接近您的方法,这是使用 purrr 包中的 map

purrr::map_dbl(nwl, ~ assortativity(.x, V(.x)$Type, directed = T))

它允许您直接插入 .x 作为网络的占位符(在参数 nwl 中指定)。我不知道如何使用 base R.

无论如何结果应该是相同的。