我希望从数据帧创建网络对象。
数据框架是联盟投资组合,对联系进行了估价,并且状态A和状态B都有顶点属性
数据看起来像这样
data <- data.frame(CC1 = c(2,2,2,2,2,2,20,20,20,20,20,40,40,40,40,41,41,41,42,42,70),
CC2 = c(20,40,41,42,70,90,40,41,42,70,90,41,42,70,90,42,70,90,70,90,90),
weight=rnorm(n=21, mean=0.337, sd=0.75),
type1=c("x","x","x","x","x","x","x","x","x","x","x","y","y","y","y","z","z","z","a","a","b"),
type2=c("x","y","z","a","b","c","y","z","a","b","c","z","a","b","c","a","b","c","b","c","c"))
CC1是州A CC2是州B,权重是其联盟的级别。类型1和类型2分别是CC1和CC2的属性。
我已经成功创建了邻接矩阵,但是尝试创建网络对象会给我错误“参数不是矩阵”
nodes=unique(c(data[,1],data[,2]))
g=graph.data.frame(data, directed=F, vertices=nodes)
a=as_adjacency_matrix(g,attr = "weight",sparse = T)
n=network(a, directed=FALSE, loops=FALSE)
最终,我正在尝试创建一个网络对象,以便可以运行ergm模型并包括类型的nodematch。