igraph中多个有向图的分类性

时间:2019-04-23 23:52:58

标签: r igraph

我有来自定向网络的边缘列表的列表

e_list=list(structure(list(nominator1 = structure(c(3L, 4L, 1L, 2L), .Label = c("Angela", 
"Jeff", "Jim", "Pam"), class = "factor"), nominee1 = structure(c(1L, 
2L, 3L, 2L), .Label = c("Andy", "Angela", "Jeff"), class = "factor")), class = "data.frame", row.names = c(NA, 
-4L)), structure(list(nominator2 = structure(c(4L, 1L, 2L, 3L
), .Label = c("Eric", "Jamie", "Oscar", "Tim"), class = "factor"), 
    nominee2 = structure(c(1L, 3L, 2L, 3L), .Label = c("Eric", 
    "Oscar", "Tim"), class = "factor")), class = "data.frame", row.names = c(NA, 
-4L)))

以及两个网络中每个人的属性数据框

attribute_df=structure(list(names = structure(c(6L, 7L, 5L, 2L, 1L, 8L, 3L, 
4L), .Label = c("Andy", "Angela", "Eric", "Jamie", "Jeff", "Jim", 
"Pam", "Tim"), class = "factor"), gender = structure(c(3L, 2L, 
3L, 2L, 3L, 1L, 1L, 2L), .Label = c("", "F", "M"), class = "factor"), 
    happiness = c(8, 9, 4.5, 5.7, 5, 6, 7, 8)), class = "data.frame", row.names = c(NA, 
-8L))

然后将它们转换为igraph个对象

if(!require(igraph)) install.packages("igraph"); require(igraph)
graph_list<-lapply(name_of_edgelist_list, graph_from_data_frame)

我使用此循环添加了性别属性

for(i in 1:length(graph_list)){
  graph_list[[i]]=set_vertex_attr(graph_list[[i]],"gender", value=attribute_df$gender[match(V(graph_list[[i]])$name, attribute_df$names)])

}

和图形对象的幸福属性

for(i in 1:length(graph_list)){
  graph_list[[i]]=set_vertex_attr(graph_list[[i]],"happiness", value=attribute_df$happiness[match(V(graph_list[[i]])$name, attribute_df$names)])

}

当我尝试像这样测量幸福的分类性

lapply(graph_list, function(x) assortativity(x, V(x)$happiness))

我得到第一个图的值,然后第二个图的分类只是'NA'

关于如何在这些有向图中测量分类性的任何想法?

0 个答案:

没有答案