Learn R Programming

networksis (version 2.1-3)

simulate.sisnetwork: Simulate a bipartite network using sequential importance sampling

Description

The method simulate.sisnetwork simulates graphs with the same marginals as the passed network or as the rows and columns specified in a sisnetwork object through sequential importance sampling. That is, the degrees of the nodes are fixed and specified.

Usage

"simulate"(object, nsim = 1, seed = NULL, save.networks = FALSE, ...)

Arguments

object
Either a network object or sisnetwork object. If 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, respectively.
nsim
Number of networks to be randomly drawn from the set of all networks.
seed
Seed for random number generator.
save.networks
If this is TRUE, the sampled networks are returned. Otherwise only the last network is returned.
...
Further arguments passed to or used by methods.

Value

simulate.sisnetwork returns an object of class network.series, that is a list consisting of the following elements:
networks
The vector of simulated networks.
log.prob
The vector of the logarithm of the probability of being sampled.
log.graphspace.size
The logarithm of the mean estimate of the number of graphs in the graph space.
log.graphspace.SE
The logarithm of the standard error of the mean estimate of the number of graphs in the graph space.
log.graphspace.size.lne
The logarithm of the lognormal-based estimate of the number of graphs in the graph space.
log.graphspace.SE.lne
The logarithm of the standard error of the lognormal-based estimate of the number of graphs in the graph space.

Details

A sample of networks is randomly drawn from the space of networks with the same degrees for each node.

See Also

network

Examples

Run this code
bipartite.graph <- matrix(c(1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0), nrow = 3, byrow = TRUE)
example.net <- network(bipartite.graph)

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

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

# Estimated graph space size and SE
exp(sim$log.graphspace.size)
exp(sim$log.graphspace.SE)

# Darwin's finches example
data(finch)

sim <- simulate.sisnetwork(finch, nsim = 100, save.networks = TRUE)

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

# Calculate Sanderson's \bar{S}^2
s.bar.squared.vec <- rep(0, 100)

for(i in 1 : 100)
{
   # Extract simulated bipartite graphs
   new.graph <- as.matrix.network(sim$networks[[i]])

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

Run the code above in your browser using DataLab