0

My question is similar to the one posted here: Network adding edges error

I am creating a network from scratches: I have data about 228 vertices, over a period of 13 years. In the first year, I have just 1781 edges: they do not involve all of my vertices (barely 164), therefore the remaining nodes should result as isolated.

I created the network starting from my edgelist, using the code

fdi.graph.2003 <- graph_from_data_frame(fdi.edge.2003, directed = T, vertices = fdi.attr.2003)

where fdi.edge.2003 is a data.frame containing edge attributes (including some potential weight columns): it only involves 164 vertices out of the total vertices defined by fdi.attr.2003 is a data.frame containing a row for each vertex that is involved in the edgelist (164 in total).

all i get is a network with 164 vertices and no isolates. However, I know they do exist in my data! Any suggestion on how to do it? I think that I shoul initialize a network with all 228 vertices, adding their attributes and then adding the edges. However, nothing I am trying is working: rather, I am receiving the most disparate errors related to "Illegal vertex reference in addEdges_R".

Any suggestion is more than welcome, also in the case it would involve the alternative package igraph, for which I am finding the same problem

Filippo

Filippo Santi
  • 109
  • 1
  • 8
  • Maybe I am confused. You say `fdi.attr.2003 is a data.frame containing a row for each vertex that is involved in the edgelist` So it sounds like you have selected exactly those nodes that are _not_ isolates. They all have an edge. Am I misunderstanding you? – G5W Jan 26 '18 at 21:17
  • Dear G5W, No, you did not misunderstand. The point is that using statnet I have not been able to solve the issue, since I kept receiving the error I wrote in the question. I eventuallyI solved the issue using igraph and imposing an attributes list based on all the nodes in my sample, even if part of them does not appear in the edgelist. But, if you have any suggestion about how to do the same in statnet, it will be extremely appreciated! – Filippo Santi Jan 27 '18 at 14:43
  • Sorry, I use R but don't know statnet. I hope that someone else can help you. – G5W Jan 27 '18 at 15:35

1 Answers1

2

Use add.isolates from the sna package

net1 = as.network(cbind(1:3, 3:5)) #5 vertices, 3 edges
net2 = as.network(add.isolates(net1, 10), matrix.type = "edgelist") #15 v, 3 e

And then you'll probably want to create new vertex names, e.g.

net2%v%"vertex.names" = 1:15
jac
  • 620
  • 4
  • 11