tvg
tvg

Reputation: 418

"graph stack" in network class

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.

Upvotes: 0

Views: 211

Answers (1)

skyebend
skyebend

Reputation: 1109

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

Upvotes: 3

Related Questions