I'm trying to add an edge attribute to a network
object with statnet
in R
using the function add.edge.attribute()
.
Here is the network
object:
> g
Network attributes:
vertices = 866
directed = TRUE
hyper = FALSE
loops = FALSE
multiple = TRUE
bipartite = FALSE
total edges= 5310
missing edges= 0
non-missing edges= 5310
Vertex attribute names:
vertex.names
Edge attribute names not shown
I then used add.edge.attribute()
, with the below connections
, which has the same length as the number of edges in the network:
> table(connections)
favorite mention retweet
2564 2041 705
> sum(table(connections))
[1] 5310
> g <- set.edge.attribute(g, "connection_type", connections)
However, when I inspect the network
object, nothing appears to have changed:
> g
Network attributes:
vertices = 866
directed = TRUE
hyper = FALSE
loops = FALSE
multiple = TRUE
bipartite = FALSE
total edges= 5310
missing edges= 0
non-missing edges= 5310
Vertex attribute names:
membership vertex.names
Edge attribute names not shown
Yet, when I check with get.edge.attribute()
, it seems to have worked:
> tmp <- get.edge.attribute(g, "connection_type")
> str(tmp)
chr [1:5310] "mention" "mention" "mention" "mention" "mention" "mention" "mention" "mention" ...
And, when I try to use the edge attribute as part of an ergm
model - I tried using edgecov()
, the error below was returned:
m1 <- ergm(g ~ edges + mutual + edgecov("connection_type"))
Error: There is no network attribute named connection_type
What gives? Why are the edge attribute names not shown? And why does it not seem to be working as part of the ergm model?