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