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×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

igraph_sbm_game().

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 3a34d30 U--- 1000 16993 -- Stochastic block model
#> + attr: name (g/c), loops (g/l)
#> + edges from 3a34d30:
#>  [1]  4-- 5  4-- 9  9--10  5--11  7--13  9--16  4--17  7--17 10--17 12--17
#> [11] 10--18 11--19 16--19 16--20 18--20 19--20  4--21  6--21  1--22 20--22
#> [21]  5--23 14--23 21--23  3--24  3--25 13--25 15--25 23--25  8--26 15--26
#> [31] 18--26  6--27 24--27  2--28  5--28 22--28 16--29 22--29 28--29  8--30
#> [41] 22--30  5--31  9--31 20--31 22--31 21--32 31--32 11--33 14--33 19--33
#> [51] 20--33  4--34  7--34 17--34 25--34 20--35 29--35  2--36 14--36 20--36
#> [61] 27--36  9--37 14--37  1--38 11--38 17--38 19--38 21--38 23--38  6--39
#> [71]  9--39 12--40 22--40 23--40 37--40 13--41 18--41 21--41 23--41 35--41
#> + ... omitted several edges