0

我正在尝试格式化数据以运行 ERGM 模型。但是,我在组合我想用于 ergm 模型的两个数据集时遇到了问题。首先,我的实际数据集是一个二分网络,第一类节点(政治家)作为行,第二类节点(政治家对一个主题的每个投票)作为列。但是,在尝试向政客添加属性时,我遇到了我的 sna 对象不是图形对象的错误。为了找出问题所在,我使用了网站上的一个示例(链接如下)并稍作更改,使其也是一个二分网络。我遇到了与较大的原始数据集相同的问题。

http://www.mjdenny.com/Preparing_Network_Data_In_R.html

这里是可重现的例子

rm(list = ls())
# install.packages("statnet", dependencies = TRUE) 
library(statnet)

num_nodes <- 10 # in my real data set, these would be the politicians
num_events <- 30 # in my real data set, these would be the votes

my_sociomatrix <- matrix(round(runif(num_nodes*num_events)), # edge values
                         nrow = num_events, #nrow must be same as ncol
                         ncol = num_nodes)
diag(my_sociomatrix) <- 0
class(my_sociomatrix)
net <- as.network(x = my_sociomatrix, # the network object
                  directed = TRUE, # specify whether the network is directed
                  bipartite = TRUE,
                  loops = FALSE, # do we allow self ties (should not allow them)
                  matrix.type = "adjacency" # the type of input
)

添加名称似乎有效:

network.vertex.names(net) <- LETTERS[1:10]
network.vertex.names(net) <- c("Susan","Rachel","Angela","Carly","Stephanie","Tom","Mike","Tony","Matt","Steven")
gender <- c(rep("Female",num_nodes/2),rep("Male",num_nodes/2))
print(gender)

这是不起作用的部分:

set.vertex.attribute(net, # the name of the network object
                     "Gender", # the name we want to reference the variable by in that object
                     gender # the value we are giving that variable
) 

这是需要解决的错误:

Error in i_set_vertex_attr(graph = graph, name = name, index = index,  : 
  Not a graph object

有谁知道如何向双向 sna 对象添加属性(sna 对象应该允许我运行 ERGM)?如果我按照网站上的示例(上面的链接),代码确实有效,但不适用于二分网络。

4

0 回答 0