graph - 无法将属性添加到类 sna 的二分网络
问题描述
我正在尝试格式化数据以运行 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)?如果我按照网站上的示例(上面的链接),代码确实有效,但不适用于二分网络。
解决方案
推荐阅读
- flutter - 如何显示用户图像?
- javascript - NG8001:“app-home”不是已知元素
- javascript - 我正在尝试获取一个表格来使用函数更改行的文本
- image - 如何从相机一张一张地捕捉 3 张或多张图像。在本机反应
- git - Git - 删除源代码上不需要的提交消息
- angular - 如何询问用户是否允许在 Chrome 浏览器中播放声音
- android-architecture-navigation - NavDeepLinkBuilder 将先前的活动添加到后台堆栈
- python - x 次迭代后 Python 并行 for 循环中断
- spring-integration - 检测 RabbitMq 连接上的异常
- excel - 循环直到最后一行数据