R/sim_basic_block_network.R
sim_basic_block_network.Rd
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 )
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 |
edge_dist | A distribution function that has two inputs: the first is
number of samples to draw and the second the |
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 |
return_edge_propensities | If set to |
setup_model | Should an SBM model object be added? Set to |
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. |
An S3 object of class sbm_network
. For details see
new_sbm_network
section "Class structure."
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.
sim_sbm_network
sim_random_network
Other simulations:
sim_random_network()
,
sim_sbm_network()
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.324right_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