Processing math: 100%
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

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