Reputation: 108
I can make a configuration model with igraph like this:
set.seed(124)
k_i <- rpois(10, 3)
## [1] 1 2 3 2 2 2 3 3 6 2
g <- igraph::sample_degseq(k_i, method = "vl")
plot(g)
I can recover the correct degree histogram for this network with statnet tools:
library(statnet)
G <- intergraph::asNetwork(g)
summary(G ~ degree(min(k_i):max(k_i)))
But going the other way results in several warnings and errors:
m <- ergm(G ~ degree(min(k_i):max(k_i)))
## e.g.
## In mple.existence(pl) : The MPLE does not exist!
Is there a function or series of steps in one of the statnet
packages that produces a similar result to igraph's sample_degseq
?
Upvotes: 1
Views: 175
Reputation: 2948
Is the goal to sample networks? I assume Yes. If you have already produced a graph that realizes a given degree sequence you can construct an ERGM distribution in order to sample from it. The key is to use sample space constraints, e.g. (disregard the warnings):
m <- ergm(G ~ edges, constraints = ~ degrees)
nets <- simulate(m, nsim = 4)
sapply(nets, sna::degree) / 2
#> [,1] [,2] [,3] [,4]
#> [1,] 1 1 1 1
#> [2,] 2 2 2 2
#> [3,] 3 3 3 3
#> [4,] 2 2 2 2
#> [5,] 2 2 2 2
#> [6,] 2 2 2 2
#> [7,] 3 3 3 3
#> [8,] 3 3 3 3
#> [9,] 6 6 6 6
#> [10,] 2 2 2 2
m <- ergm(G ~ edges, constraints = ~ degreedist)
nets <- simulate(m, nsim = 4)
sapply(nets, sna::degree) / 2
#> [,1] [,2] [,3] [,4]
#> [1,] 1 3 2 3
#> [2,] 2 2 3 1
#> [3,] 2 2 2 3
#> [4,] 3 2 3 2
#> [5,] 3 1 2 2
#> [6,] 2 2 2 3
#> [7,] 3 2 2 2
#> [8,] 2 3 1 2
#> [9,] 6 6 6 6
#> [10,] 2 3 3 2
Upvotes: 1