Learn R Programming

networksis (version 1.4)

simulate.sisnetwork: Draw a Bipartite Network Using Sequential Importance Sampling

Description

simulate is used to draw from exponential family random network models in their natural parameterizations. See ergm for more information on these models. The method simulate.sisnetwork draws it from graphs with the same marginals as the passed network through sequential importance sampling. That is, the degrees of the nodes are fixed and specified.

Usage

## S3 method for class 'sisnetwork':
simulate(object, nsim=1, \dots,
                       save.networks=TRUE,
                       control=ergm::control.simulate(),
                       verbose=FALSE)

Arguments

object
a sisnetwork object. This should be a list with components row and col to specify the row and column degrees. These are the degrees of the type 1 and type 2 nodes,
nsim
Number of networks to be randomly drawn from the set of all networks.
control
A list of control parameters for algorithm tuning. Constructed using control.simulate.
save.networks
If this is TRUE, the sampled networks are returned. Otherwise only the last network is returned.
verbose
If this is TRUE, we will print out more information as we run the program, including (currently) some goodness of fit statistics.
...
further arguments passed to or used by methods.

Value

  • simulate returns an object of class network.series that is a list consisting of the following elements:
  • log.probThe vector of the logarithm of the probability of being sampled.
  • log.graphspace.sizeThe logarithm of the mean estimate of the number of graphs in the graph space.
  • log.graphspace.SEThe logarithm of the standard error of the mean estimate of the number of graphs in the graph space.
  • log.graphspace.size.lneThe logarithm of the lognormal-based estimate of the number of graphs in the graph space.
  • log.graphspace.SE.lneThe logarithm of the standard error of the lognormal-based estimate of the number of graphs in the graph space.
  • In the case of a single network sampled, only the network is returned (as a network object), and the additional information is returned as attributes of the network.

Details

A sample of networks is randomly drawn from the space of networks with the same degrees for each node. More information can be found by looking at the documentation of ergm.

See Also

ergm, network

Examples

Run this code
bipartite.graph<-scan()
1 1 0 0
0 0 1 1
1 1 1 0

bipartite.graph<-matrix(bipartite.graph, nrow=3, byrow=TRUE)
example.net<-network(bipartite.graph)

## Specify which set each node belongs to ##
example.net %v% "set" <- c(rep(1,3),rep(2,4))

## Simulate 1000 graphs with the same ##
## marginals as 'example.net'         ##
sim<-simulate(example.net, nsim=1000)

## Estimated graph space size and SE ##
exp(sim %n% "log.graphspace.size")
exp(sim %n% "log.graphspace.SE")

## Darwin's finches example ##
data(finch)
sim<-simulate(finch, nsim=1000)

## Calculate importance weights from the graph probabilities ##
importance.weights<-1/exp(sim %n% "log.prob")
hist(importance.weights,breaks=75, xlab="Inverse Graph Probability",main="")

prob.vec<-rep(0,500)
s.bar.squared.vec<-rep(0,500)
for(i in 1:500)
{
   sim<-simulate(finch, nsim=1)
   
   ## Extract new bipartite graph ##
   new.graph<-as.matrix.network(sim)

   ## Calculate custom graph statistic ##
   s.bar.squared<-(sum((new.graph%*%t(new.graph))^2)-
   sum(diag((new.graph%*%t(new.graph))^2)))/(13*12)
   s.bar.squared.vec[i]<-s.bar.squared

   ## Graph probability ##
   prob.vec[i]<-exp(sim %n% "log.prob")
}

Run the code above in your browser using DataLab