Learn R Programming

networksis (version 1.4)

simulate_sis: Compute statistics from Bipartite Networks via Sequential Importance Sampling

Description

The function simulate_sis draws bipartite graphs from the space of graphs with the same marginals as the passed network using sequential importance sampling. That is, the degrees of the nodes are fixed and specified. The formula specifies a set of network statistics that are evaluated on the sampled networks. See ergm-terms for more information on the available statistics.

Usage

simulate_sis(formula, nsim=1, ...,
             control=ergm::control.simulate.formula(),
             verbose=FALSE)

Arguments

formula
formula; an Rformula object, of the form y ~ , where y is a bipartite network object or a matrix that c
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.formula.
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

  • Returns a single bipartite network object. In addition the object has network attributes (using %n%):
  • samplestatisticsThe $n\times p$ matrix of the graph statistics produced by the sampled graphs, where n is the number of simulated graphs and p is the number of different graph statistics under consideration.
  • 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.

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
data(finch)

## Simulate graphs and record the networks statistics ##
## specified by 'coincidences(x)'                     ##
sim<-simulate_sis(finch~coincidences(0:17), nsim=10000)

observed.stats<-summary(finch~coincidences(0:17))
sampled.stats<-sim %n% "samplestatistics"

## Calculate 95\% confidence intervals for the network statistics ##
library(Hmisc)
p<-exp(sim %n% "log.prob")
p<-p/sum(p)
maxs<-apply(sampled.stats,2,wtd.quantile,
weights=p,probs=0.975,normwt=TRUE)
mins<-apply(sampled.stats,2,wtd.quantile,
weights=p,probs=0.025,normwt=TRUE)
means<-apply(sampled.stats,2,wtd.mean,weights=p)

## Plot the means and CIs for the null distributions of the ##
## statistics.  Also plot the observed statistics           ##
plot(0:17, means, type="b", ylim=c(0,24.5), lwd=3, lty=3,
xlab="Number of Islands", ylab="Pairs of Finches")
for(i in 1:18)
{
   points(rep(i-1,2), c(maxs[i],mins[i]), type="l", lwd=2)
}
points(0:17, observed.stats, type="b", pch=4, lwd=3)

## Calculate the p-value for 'coincidences(0)' ##
r0<-(p%*%sweep(sampled.stats,2,observed.stats,"<"))[1,]
r1<-(p%*%sweep(sampled.stats,2,observed.stats,">"))[1,]
round(apply(cbind(r0,r1),1,min),digits=8)[1]

Run the code above in your browser using DataLab