0

How does one go about creating a "graph stack" in the network class for SNA commands that accept more than one graph? According to the documentation a graph stack should be of dimension m x N x N. I tried to create one as follows, but I get an error:

library(network)
a <- array(NA,dim=c(2,10,10))
a[1,,]<- matrix(sample(c(0,1),100,replace=T),10,10)
a[2,,]<- matrix(sample(c(0,1),100,replace=T),10,10)
t <- network(a,matrix.type="adjacency")

Creating a random graph with the rgraph function creates an array with a similar structure:

library(sna)
b <-rgraph(10,2,tprob=c(0.2,0.8))

But first creating the structure and then attempting to turn it into a network object doesn't work.

Related: is there a way to make a network object with networks of different sizes? The documentation also seems to suggest that a network object can be a list of other network objects.

tvg
  • 388
  • 2
  • 13

1 Answers1

3

What are you trying to accomplish with the 'graph stack'? The 'graph stack' formulation is used by sna but not by the network package. In the network package multiple networks can be represented as a list of networks, as multiple tie types in a single multiplex network object, or, if your multiple networks represent sequential observations of the network in time, a networkDynamic object using extensions from the networkDynamic package. The best representation depends on your use case.

If it is the case that you just want to run sna measures on a series of matrices, it appears you can construct a graph stack by just putting them in a list like

graphs<-list(rgraph(10,2,tprob=c(0.2,0.8)),rgraph(5,2,tprob=c(0.2,0.8)))

you can then call the sna measures by including the g argument to tell it to evaluate on multiple graphs on the list

> degree(graphs,g=1:2)
[[1]]
      [,1]
 [1,]    1
 [2,]    4
 [3,]    3
 [4,]    5
 [5,]    3
 [6,]    3
 [7,]    3
 [8,]    5
 [9,]    5
[10,]    6

[[2]]
     [,1]
[1,]    1
[2,]    2
[3,]    1
[4,]    2
[5,]    0
skyebend
  • 1,079
  • 6
  • 19
  • I was looking for a general explanation since I have seen references to "graph stacks" and sna functions that take multiple graphs without understanding how to implement this. The list solution works well for my application. In case this is of use to posterity, I was trying to use the cugtest (not cug.test) function to compare two graphs. The full solution requires the gliop function and is well explained on page 30 of Butts' JoSS paper on sna...took me a while to find it. – tvg Aug 26 '15 at 09:35