1

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?

Joshua Rosenberg
  • 4,014
  • 9
  • 34
  • 73
  • 1
    The `edgecov` option does not accept edge attributes. Note that the error term says "no *network attribute*. `edgecov` accepts matrices of dyadic covariates, other networks, and quantitative network attributes. You can set network attributes with `set.network.attribute`. However, `edgecov` only accepts quantitative terms from network attributes, so your case still won't work. What exactly are you trying to estimate? – paqmo Oct 29 '16 at 13:52
  • I am trying to estimate the effect of different categories of edges ("mentions", "retweets", "favorites"). – Joshua Rosenberg Oct 29 '16 at 14:19
  • Would these have to be estimated as different ties - as part of different networks? – Joshua Rosenberg Oct 29 '16 at 14:41
  • 1
    Yes, you could enter them in as different networks and use the `edgecov` term. – paqmo Oct 29 '16 at 14:45
  • But there is a bit of a problem, since the tie attributes can mechanically only predict the presence of a tie and not its absence. So I'm thinking ergm might not be the best approach in this case, but of course depends on the research question. – paqmo Oct 29 '16 at 14:56
  • Thanks - the research question at the moment has something to do with how ties are predicted by `node` "membership" (one of five categories of participants) and `edge` "category" (one of three interactions, i.e. "mentions", "retweets", and "favorites"). I'd also be interested in their interactions. Any tips for someone interested in getting started trying to model this? – Joshua Rosenberg Oct 29 '16 at 15:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/126964/discussion-between-paqmo-and-joshua-rosenberg). – paqmo Oct 29 '16 at 15:30

1 Answers1

-1

m1 <- ergm(g ~ edges + mutual + edgecov(g,"connection_type"))

  • Please don't simply post code. Add some context to your answer. Take a look at [How to answer](https://stackoverflow.com/help/how-to-answer) – Martin Gal May 25 '20 at 23:23