To specify a stochastic blockmodel, you must specify
the number of nodes (via n), the mixing matrix (via k or B),
and the relative block probabilites (optional, via pi).
We provide defaults for most of these options to enable
rapid exploration, or you can invest the effort
for more control over the model parameters. We strongly recommend
setting the expected_degree or expected_density argument
to avoid large memory allocations associated with
sampling large, dense graphs.
Usage
sbm(
n,
k = NULL,
B = NULL,
...,
pi = rep(1/k, k),
sort_nodes = TRUE,
poisson_edges = TRUE,
allow_self_loops = TRUE
)Arguments
- n
The number of nodes in the network. Must be a positive integer. This argument is required.
- k
(mixing matrix) The number of blocks in the blockmodel. Use when you don't want to specify the mixing-matrix by hand. When
kis specified, the elements ofBare drawn randomly from aUniform(0, 1)distribution. This is subject to change, and may not be reproducible.kdefaults toNULL. You must specify eitherkorB, but not both.- B
(mixing matrix) A
kbykmatrix of block connection probabilities. The probability that a node in blockiconnects to a node in communityjisPoisson(B[i, j]). Must be a square matrix.matrixandMatrixobjects are both acceptable. IfBis not symmetric, it will be symmetrized via the updateB := B + t(B). Defaults toNULL. You must specify eitherkorB, but not both.- ...
Arguments passed on to
undirected_factor_modelexpected_degreeIf specified, the desired expected degree of the graph. Specifying
expected_degreesimply rescalesSto achieve this. Defaults toNULL. Do not specify bothexpected_degreeandexpected_densityat the same time.expected_densityIf specified, the desired expected density of the graph. Specifying
expected_densitysimply rescalesSto achieve this. Defaults toNULL. Do not specify bothexpected_degreeandexpected_densityat the same time.
- pi
(relative block probabilities) Relative block probabilities. Must be positive, but do not need to sum to one, as they will be normalized internally. Must match the dimensions of
Bork. Defaults torep(1 / k, k), or a balanced blocks.- sort_nodes
Logical indicating whether or not to sort the nodes so that they are grouped by block and by
theta. Useful for plotting. Defaults toTRUE. WhenTRUE, nodes are first sorted by block membership, and then by degree-correction parameters within each block. Additionally,piis sorted in increasing order, and the columns of theBmatrix are permuted to match the new order ofpi.- poisson_edges
Logical indicating whether or not multiple edges are allowed to form between a pair of nodes. Defaults to
TRUE. WhenFALSE, sampling proceeds as usual, and duplicate edges are removed afterwards. Further, whenFALSE, we assume thatSspecifies a desired between-factor connection probability, and back-transform thisSto the appropriate Poisson intensity parameter to approximate Bernoulli factor connection probabilities. See Section 2.3 of Rohe et al. (2017) for some additional details.- allow_self_loops
Logical indicating whether or not nodes should be allowed to form edges with themselves. Defaults to
TRUE. WhenFALSE, sampling proceeds allowing self-loops, and these are then removed after the fact.
Value
An undirected_sbm S3 object, which is a subclass of the
dcsbm() object.
Details
A stochastic block is equivalent to a degree-corrected stochastic blockmodel where the degree heterogeneity parameters have all been set equal to 1.
See also
Other stochastic block models:
dcsbm(),
directed_dcsbm(),
mmsbm(),
overlapping_sbm(),
planted_partition()
Other undirected graphs:
chung_lu(),
dcsbm(),
erdos_renyi(),
mmsbm(),
overlapping_sbm(),
planted_partition()
Examples
set.seed(27)
lazy_sbm <- sbm(n = 100, k = 5, expected_density = 0.01)
lazy_sbm
#> $fun
#> function (n, pref.matrix, block.sizes, directed = FALSE, loops = FALSE)
#> {
#> n <- as.numeric(n)
#> pref.matrix[] <- as.numeric(pref.matrix)
#> block.sizes <- as.numeric(block.sizes)
#> directed <- as.logical(directed)
#> loops <- as.logical(loops)
#> on.exit(.Call(R_igraph_finalizer))
#> res <- .Call(R_igraph_sbm_game, n, pref.matrix, block.sizes,
#> directed, loops)
#> if (igraph_opt("add.params")) {
#> res$name <- "Stochastic block model"
#> res$loops <- loops
#> }
#> res
#> }
#> <bytecode: 0x562715e4d388>
#> <environment: namespace:igraph>
#>
#> $args
#> <list_of<quosure>>
#>
#> $n
#> <quosure>
#> expr: ^100
#> env: empty
#>
#> $k
#> <quosure>
#> expr: ^5
#> env: empty
#>
#> $expected_density
#> <quosure>
#> expr: ^0.01
#> env: empty
#>
#>
#> $lazy
#> [1] FALSE
#>
#> attr(,"class")
#> [1] "igraph_constructor_spec"
# by default we get a multigraph (i.e. multiple edges are
# allowed between the same two nodes). using bernoulli edges
# will with an adjacency matrix with only zeroes and ones
bernoulli_sbm <- sbm(
n = 500,
k = 30,
poisson_edges = FALSE,
expected_degree = 8
)
bernoulli_sbm
#> $fun
#> function (n, pref.matrix, block.sizes, directed = FALSE, loops = FALSE)
#> {
#> n <- as.numeric(n)
#> pref.matrix[] <- as.numeric(pref.matrix)
#> block.sizes <- as.numeric(block.sizes)
#> directed <- as.logical(directed)
#> loops <- as.logical(loops)
#> on.exit(.Call(R_igraph_finalizer))
#> res <- .Call(R_igraph_sbm_game, n, pref.matrix, block.sizes,
#> directed, loops)
#> if (igraph_opt("add.params")) {
#> res$name <- "Stochastic block model"
#> res$loops <- loops
#> }
#> res
#> }
#> <bytecode: 0x562715e4d388>
#> <environment: namespace:igraph>
#>
#> $args
#> <list_of<quosure>>
#>
#> $n
#> <quosure>
#> expr: ^500
#> env: empty
#>
#> $k
#> <quosure>
#> expr: ^30
#> env: empty
#>
#> $poisson_edges
#> <quosure>
#> expr: ^FALSE
#> env: empty
#>
#> $expected_degree
#> <quosure>
#> expr: ^8
#> env: empty
#>
#>
#> $lazy
#> [1] FALSE
#>
#> attr(,"class")
#> [1] "igraph_constructor_spec"
edgelist <- sample_edgelist(bernoulli_sbm)
#> Error in UseMethod("sample_edgelist"): no applicable method for 'sample_edgelist' applied to an object of class "igraph_constructor_spec"
edgelist
#> Error: object 'edgelist' not found
A <- sample_sparse(bernoulli_sbm)
#> Error in UseMethod("sample_sparse"): no applicable method for 'sample_sparse' applied to an object of class "igraph_constructor_spec"
# only zeroes and ones!
sign(A)
#> Error: object 'A' not found