| simulate.sisnetwork {networksis} | R Documentation |
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.
## S3 method for class 'sisnetwork' simulate(object, nsim = 1, seed = NULL, save.networks = FALSE, ...)
object |
Either a |
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 |
... |
Further arguments passed to or used by methods. |
A sample of networks is randomly drawn from the space of networks with the same degrees for each node.
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. |
network
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)
}