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