Replies: 1 comment
-
sorry, i find that ergm is not work for directed bipartite network. Is there a variant of the ergm model suitable for directed bipartite networks? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Below is the command I used to fit a bipartite network using ergm, along with the error that occurred. Can anyone tell me why this error might have occurred, and how it could be corrected? I would greatly appreciate your responses!
edge_file <- "path/edgedata.csv"
node_file <- "path/nodedata.csv"
edge_data <- read.csv(edge_file)
node_data <- read.csv(node_file)
Create a bipartite network based on node and edge data.
num_source <- sum(node_data$nodetype == 1)
num_target <- sum(node_data$nodetype == 0)
total_nodes <- nrow(node_data)
initialize bipartite network
bipartite_network <- network.initialize(total_nodes, bipartite = num_source, directed = TRUE)
Before adding an edge, ensure that the node ID is within the range of network nodes
source_indices <- match(edge_data$source, node_data$ID)
target_indices <- match(edge_data$target, node_data$ID)
add edges
add.edges(bipartite_network, tail = source_indices, head = target_indices)
set attribute
set.vertex.attribute(bipartite_network, "A", node_data$A)
set.vertex.attribute(bipartite_network, "B", node_data$B)
set.vertex.attribute(bipartite_network, "C", node_data$C)
set.edge.attribute
set.edge.attribute(bipartite_network, "D", edge_data$D)
set.edge.attribute(bipartite_network, "E", edge_data$E)
set.edge.attribute(bipartite_network, "F", as.numeric(as.factor(edge_data$F)))
set.edge.attribute(bipartite_network, "G", as.numeric(as.factor(edge_data$G)))
set.edge.attribute(bipartite_network, "H", as.numeric(as.factor(edge_data$H)))
ERGM
bipartite_model <- ergm(bipartite_network ~ edges,
#+ b2star(2) + gwdsp(0.5, fixed = TRUE)+
# nodematch("A", diff = T) + b2cov("B")+
# edgecov("E") + edgecov("D") +
# edgecov("G") + edgecov("H") + edgecov("F"),
control= control.ergm(MCMLE.maxit = 3))
Error in
ergm_Init_abort()
:! In constraint ‘.attributes’ in package ‘ergm’: Term may not be used with directed bipartite networks.
Run
rlang::last_trace()
to see where the error occurred.Beta Was this translation helpful? Give feedback.
All reactions