我是网络分析和ERGM模型的新手,我有一个列表,其中有100个Erdos Renyi模型作为内容,是用下面的代码创建的。
set.seed(666)
gs <- list()
for (x in seq_len(100L)) {
gs[[x]] <- erdos.renyi.game(374, 0.0084, type = "gnp", directed = F)
E(gs[[x]])$weight <- sample(1:5, ecount(gs[[x]]), T)
}现在我想计算两个节点之间的平均路径长度,以及这100个模型之间的平均聚类。对于平均路径长度,我使用了以下代码:
random_mean_paths <- sapply(gs, igraph::mean_distance, 1:100)
mean(random_mean_paths)但是,如果我对igraph::transitivity进行同样的尝试,即
random_mean_clus <- sapply(gs, igraph::transitivity, 1:100)我知道错误了
Error in match.arg(arg = arg, choices = choices, several.ok = several.ok) :
'arg' must be of length 1当试图通过设置type = "global"来解决此错误时,即
random_mean_clus <- sapply(gs, igraph::transitivity(type = "global", 1:100)我得到了错误argument "graph" is missing with no default
我不能在gs函数中指定transitivity(),因为它不是in对象,而且我无法将正确的参数传递给这个函数。
提前谢谢。
发布于 2022-03-30 15:33:13
任一种
random_mean_clus <- sapply(gs, igraph::transitivity, type = "global", 1:100)
random_mean_clus <- sapply(gs, \(s) igraph::transitivity(s, type = "global", 1:100))就能解决问题。
第一个参数包括参数列表中的命名参数,第二个参数使用R4.1中引入的新方法定义匿名函数\(s)。
https://stackoverflow.com/questions/71680037
复制相似问题