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().

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.

Random graph models (games) erdos.renyi.game(), sample_(), sample_bipartite(), sample_chung_lu(), sample_correlated_gnp(), sample_correlated_gnp_pair(), sample_degseq(), sample_dot_product(), sample_fitness(), sample_fitness_pl(), sample_forestfire(), sample_gnm(), sample_gnp(), sample_grg(), sample_growing(), sample_hierarchical_sbm(), sample_islands(), sample_k_regular(), sample_last_cit(), sample_pa(), sample_pa_age(), sample_pref(), sample_smallworld(), sample_traits_callaway(), sample_tree()

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