ERGM モデルを実行するためにデータをフォーマットしようとしています。しかし、ergm モデルに使用したい 2 つのデータセットを組み合わせるのに問題があります。まず、私の実際のデータ セットは、最初のタイプのノード (政治家) を行として、2 番目のタイプのノード (1 つのトピックに関する政治家の各投票) を列とする 2 部構成のネットワークです。しかし、政治家に属性を追加しようとすると、sna オブジェクトがグラフ オブジェクトではないというエラーが発生しました。問題が何であるかを調べるために、私はウェブサイトの例 (以下のリンク) を使用し、2 部ネットワークになるように少し変更しました。より大きな元のデータセットで発生したのと同じ問題に遭遇しました。
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
2 部構成の sna オブジェクトに属性を追加する方法を知っている人はいますか (sna オブジェクトを使用すると、ERGM を実行できるはずです)。Web サイト (上のリンク) の例に従えばコードは機能しますが、2 部ネットワークでは機能しません。