Simulates nodes and edges from a network where edge edges are derived from the Stochastic Block Model. A dataframe describing the different blocks present and the number of nodes within them, a dataframe that provides the propensity of edge between two edges, and a distribution function who's main parameter the propensity value defines are needed.

sim_sbm_network(
  block_info,
  edge_propensities,
  edge_dist = stats::rpois,
  allow_self_edges = FALSE,
  keep_edge_counts = TRUE,
  setup_model = FALSE,
  random_seed = NULL
)

Arguments

block_info

A dataframe/tibble with two columns: block: the id of the block, and n_nodes: the number of nodes to simulate from that block.

edge_propensities

A dataframe with 3 columns: block_1: the id of the from block, block_2: the id of the to block, and propensity: the parameter for edge_dist that controls if and or how many edges should occur between the pair of blocks on average.

edge_dist

A distribution function that has two inputs: the first is number of samples to draw and the second the propensity value from edge_propensities. For instance, the default value is rpois which takes two arguments: n and lambda. In this scenario the propensity of edges between two nodes is provided to lambda and thus is the average number of edges for each pair of nodes between two given blocks.

allow_self_edges

Should nodes be allowed to have edges to themselves?

keep_edge_counts

Should the edge counts stay on returned edges? If edges distribution is a binary yes or no then you will likely want to set this to TRUE.

setup_model

Should an SBM model object be added? Set to FALSE if network is just being visualized or described.

random_seed

Integer seed to be passed to model's internal random sampling engine. Note that if the model is restored from a saved state this seed will be initialized again to the start value which will harm reproducability.

Value

An S3 object of class sbm_network. For details see new_sbm_network section "Class structure."

See also

Examples

block_info <- dplyr::tribble( ~block, ~n_nodes, "a", 10, "b", 12, "c", 15 ) edge_propensities <- dplyr::tribble( ~block_1, ~block_2, ~propensity, "a", "a", 0.7, "a", "b", 0.2, "a", "c", 0.1, "b", "b", 0.9, "b", "c", 0.4, "c", "c", 0.4, ) sim_sbm_network(block_info, edge_propensities, edge_dist = purrr::rbernoulli)
#> SBM Network with 37 nodes of a single type and 234 edges. #> #> Nodes: # A tibble: 6 x 3 #> id block type #> <chr> <chr> <chr> #> 1 a_1 a node #> 2 a_2 a node #> 3 a_3 a node #> 4 a_4 a node #> 5 a_5 a node #> 6 a_6 a node #> ... #> #> Edges: # A tibble: 6 x 3 #> from to edges #> <chr> <chr> <dbl> #> 1 a_1 a_4 1 #> 2 a_1 a_5 1 #> 3 a_1 a_6 1 #> 4 a_1 a_7 1 #> 5 a_1 b_3 1 #> 6 a_1 b_6 1 #> ... #>