Reputation: 1
I have a rather complicated network. The network has 91 nodes and 3453 edges. There are twelve edge types. To build the network, I created 12 separate ego networks, using the edge attributes as individual nodes, then deleted the edge attribute nodes, and finally merged the 12 graphs together.
The nodes have 5 attributes: Who, Request date, Response date, Affiliation in request, and Category.
I would like to use ERGMs to predict the likelihood of forming a tie (any ties, and particular 'edge type' ties), based on node attributes. I have tried to use 'nodematch', but R is throwing the following error: "Error in ergm.getnetwork(formula) : Invalid network. Is the left-hand-side of the formula correct?"
I'm wondering whether this issue stems from the way I have built my rather complicated network.
Can anyone help? Suggestions most welcome.
Thank you so much in advance.
Code below:
DIDPel<-read.csv("DIDPEdgeListv2.csv", header=TRUE, stringsAsFactors = FALSE) #read edges
library(reshape2)
library(igraph)
library(statnet)
m.el<-melt(DIDPel, 'Req.ID') #create an edge list
m.el<-subset(m.el, value==1) #get rid of non-existant edges
types<-levels(m.el$variable)
m.vert<-data.frame(id=unique(c(t(m.el[,c(1,2)])))) # Create a list of node IDs
m.vert$type<-m.vert$id %in% m.el$variable #Highlight request retrictions vs request ids
m.net<-graph.data.frame(m.el, vertices=m.vert, directed=FALSE) #create a network
plot(m.net, vertex.color=V(m.net)$type) #take a looksee
egos<-make_ego_graph(m.net, 1, V(m.net)$type==TRUE) #Make an ego network for every request type
plot(egos[[1]]) #One ego network
egos.con<-lapply(egos, function(x) connect(x, 2))
plot(egos.con[[1]]) #one connected ego network
for(i in 1:length(types)){
egos.con[[i]]<-set.edge.attribute(egos.con[[i]], name=types[[i]], value=TRUE)} #identify type of edge
egos.con[[1]]
plot(egos.con[[1]], edge.label=E(egos.con[[1]])$a..Confidential.government.information)
egos.con<-lapply(egos.con, function(x) delete.vertices(x, V(x)$type==TRUE)) #delete the restriction node
plot(egos.con[[1]])
ego.base<- egos.con[[1]] #establish a base graph
for(i in 2:length(egos.con)){
ego.base <- ego.base + egos.con[[i]] #merge everything together
}
plot(ego.base)
ego.m.df<-get.data.frame(ego.base)
head(ego.m.df)
ego.m.df
ego.m.df<-melt(ego.m.df, id=c('from', 'to')) #melt it back down to one column
ego.m.df<-subset(ego.m.df, value==TRUE) #only keep actual edges
head(ego.m.df)
ego.m.df
nodes<-read.csv('DIDPNodeList.csv')
head(nodes)
final.net<-graph.data.frame(ego.m.df, vertices=nodes, directed=FALSE)
#Plot network
l<-layout.grid(final.net)
plot(final.net, edge.color=factor(E(final.net)$variable))
summary (final.net)
#ERG model
erg.net<- ergm(final.net ~ edges + nodematch("Category"), control=control.ergm(seed=1))
erg.net
summary(erg.net)
Upvotes: 0
Views: 614
Reputation: 1109
it appears that final.net
is a graph
object from the igraph
library, but ergm
requires its input to a be a network
object. You can probably construct the network
object using the network()
function and your ego.m.df
object, or perhaps use the intergraph
package to convert the graph
to a network
Upvotes: 1