如何获得邻接数组以mrqap
在包中执行测试sna
?我有一个加权多重网络(两个无向和一个有向),在带有属性的边缘列表中,如下所示:
source target terr type weight
1010 1007 1 3 1
1011 1303 1 2 1
1014 1048 1 4 2
1014 1138 1 4 3
我需要几个具有相同数量节点的数组格式的矩阵,如下所示(但采用 adyacency 矩阵格式):
type 2
source target weight
1010 1007 0
1011 1303 1
1014 1048 0
1014 1138 0
type 3
source target weight
1010 1007 1
1011 1303 0
1014 1048 0
1014 1138 0
type 4
source target weight
1010 1007 0
1011 1303 0
1014 1048 2
1014 1138 3
我尝试过的一个脚本:
el=read.csv("S_EDGES.csv", header = TRUE, sep = ",") # edgelist
Nodos=read.csv("S_NODES.csv", header = TRUE, sep = ",")
el$type[el$type==2] <- 1 # un solo vínculo de infraestructura
library(igraph)
G=graph.data.frame(el, Nodos, directed=F)
subv = (Nodos$id (Nodos$terr_name=="ART") # this fail and then also "neighverts" and "g3"
SG = decompose.graph(G,mode="weak") # because different territories are in fact different networks
neighverts = unique(unlist(sapply(SG,FUN=function(s){if(any(V(s)$name %in% subv)) V(s)$name else NULL})))
g3 = induced.subgraph(graph=G,vids=neighverts)
# or:
AM=get.adjacency(G, type=c("both"), attr=NULL, names=TRUE, sparse=FALSE) # doesn't distinguish the types of links in different matrices