Simulates a simple block structured network with a desired number of constant sized blocks. The probability of edges between given blocks will be drawn from a passed function that must return a numeric value that will be used as the propensity parameter for drawing edge counts from a node pair. The default values will draw propensity values for bernouli edges with an average of a 50% chance of edge.

sim_basic_block_network(
  n_blocks = 2,
  n_nodes_per_block = 5,
  propensity_drawer = function(n) {     sample(seq(stats::rbeta(1, 1, 5),
    stats::rbeta(1, 5, 1), length.out = n)) },
  edge_dist = purrr::rbernoulli,
  allow_self_edges = FALSE,
  keep_edge_counts = FALSE,
  return_edge_propensities = FALSE,
  setup_model = FALSE,
  random_seed = NULL
)

Arguments

n_blocks

How many blocks to simulate

n_nodes_per_block

How many nodes in each block

propensity_drawer

Function that takes a single size argumenet and returns a vector of edge propensities of specified size. Default draws propensity from n evenly spaced values in the 0-1 range.

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.

return_edge_propensities

If set to TRUE the returned list will also include the simulated edge propensities dataframe. This can be used for recreating draws using sim_sbm_network.

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."

Details

If return_edge_propensities == TRUE: an $edge_propensities slot is added to the returned sbm_network object containing a dataframe that shows the randomly drawn edge propensities between blocks.

See also

Examples

sim_basic_block_network(n_blocks = 4, n_nodes_per_block = 40)
#> SBM Network with 160 nodes of a single type and 6827 edges. #> #> Nodes: # A tibble: 6 x 3 #> id block type #> <chr> <chr> <chr> #> 1 g1_1 g1 node #> 2 g1_2 g1 node #> 3 g1_3 g1 node #> 4 g1_4 g1 node #> 5 g1_5 g1 node #> 6 g1_6 g1 node #> ... #> #> Edges: # A tibble: 6 x 2 #> from to #> <chr> <chr> #> 1 g1_1 g1_2 #> 2 g1_1 g1_5 #> 3 g1_1 g1_13 #> 4 g1_1 g1_16 #> 5 g1_1 g1_17 #> 6 g1_1 g1_21 #> ... #>
sim_basic_block_network(n_blocks = 8, n_nodes_per_block = 20)
#> SBM Network with 160 nodes of a single type and 3824 edges. #> #> Nodes: # A tibble: 6 x 3 #> id block type #> <chr> <chr> <chr> #> 1 g1_1 g1 node #> 2 g1_2 g1 node #> 3 g1_3 g1 node #> 4 g1_4 g1 node #> 5 g1_5 g1 node #> 6 g1_6 g1 node #> ... #> #> Edges: # A tibble: 6 x 2 #> from to #> <chr> <chr> #> 1 g1_1 g1_3 #> 2 g1_1 g1_10 #> 3 g1_1 g1_11 #> 4 g1_1 g1_13 #> 5 g1_1 g1_14 #> 6 g1_1 g1_17 #> ... #>
# Can save the generating edge propensities as well net <- sim_basic_block_network(n_blocks = 4, n_nodes_per_block = 20, return_edge_propensities = TRUE) net$edge_propensities
#> # A tibble: 10 x 3 #> block_1 block_2 propensity #> <chr> <chr> <dbl> #> 1 g1 g1 0.0575 #> 2 g1 g2 0.658 #> 3 g1 g3 0.458 #> 4 g1 g4 0.191 #> 5 g2 g2 0.258 #> 6 g2 g3 0.391 #> 7 g2 g4 0.591 #> 8 g3 g3 0.524 #> 9 g3 g4 0.124 #> 10 g4 g4 0.324
right_skewed_beta <- function(n) rbeta(n, 1, 5) # Distribution that draws propensities can be customized net <- sim_basic_block_network(n_blocks = 4, n_nodes_per_block = 20, return_edge_propensities = TRUE, propensity_drawer = right_skewed_beta) net$edge_propensities
#> # A tibble: 10 x 3 #> block_1 block_2 propensity #> <chr> <chr> <dbl> #> 1 g1 g1 0.142 #> 2 g1 g2 0.261 #> 3 g1 g3 0.160 #> 4 g1 g4 0.0287 #> 5 g2 g2 0.345 #> 6 g2 g3 0.277 #> 7 g2 g4 0.310 #> 8 g3 g3 0.367 #> 9 g3 g4 0.113 #> 10 g4 g4 0.304