Skip to contents

Sampling from the stochastic block model of networks

Usage

sample_sbm(n, pref.matrix, block.sizes, directed = FALSE, loops = FALSE)

sbm(...)

Arguments

n

Number of vertices in the graph.

pref.matrix

The matrix giving the Bernoulli rates. This is a \(K\times K\) matrix, where \(K\) is the number of groups. The probability of creating an edge between vertices from groups \(i\) and \(j\) is given by element \((i,j)\). For undirected graphs, this matrix must be symmetric.

block.sizes

Numeric vector giving the number of vertices in each group. The sum of the vector must match the number of vertices.

directed

Logical scalar, whether to generate a directed graph.

loops

Logical scalar, whether self-loops are allowed in the graph.

...

Passed to sample_sbm().

Value

An igraph graph.

Details

This function samples graphs from a stochastic block model by (doing the equivalent of) Bernoulli trials for each potential edge with the probabilities given by the Bernoulli rate matrix, pref.matrix. The order of the vertices in the generated graph corresponds to the block.sizes argument.

References

Faust, K., & Wasserman, S. (1992a). Blockmodels: Interpretation and evaluation. Social Networks, 14, 5--61.

Author

Gabor Csardi csardi.gabor@gmail.com

Examples


## Two groups with not only few connection between groups
pm <- cbind(c(.1, .001), c(.001, .05))
g <- sample_sbm(1000, pref.matrix = pm, block.sizes = c(300, 700))
g
#> IGRAPH 1014c8a U--- 1000 16933 -- Stochastic block model
#> + attr: name (g/c), loops (g/l)
#> + edges from 1014c8a:
#>  [1]  2-- 3  2-- 7  6-- 7  4-- 8  4-- 9  4--10  4--11  7--11 10--11  7--12
#> [11]  1--13  8--13  9--14 11--14  8--16 11--16  3--17  4--17 12--17  7--18
#> [21] 14--18 15--18 15--19 18--19  5--20  7--20  9--20 17--20  1--21  5--21
#> [31] 11--21 17--21  1--22  5--22  6--22  3--23  7--23 15--23 16--23  4--25
#> [41]  6--25  9--25 18--25 19--25 22--25 20--26 21--26 24--26 21--27 24--27
#> [51]  1--28 14--28 18--28 19--28 21--28 22--28 24--28  6--29 21--29  3--30
#> [61]  6--30  8--30 13--30 13--31 29--32  1--33  8--33 15--33 20--33 21--33
#> [71]  3--34  5--34 10--34 17--34 18--34  1--35 24--35 28--35  9--36 13--36
#> + ... omitted several edges