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 9902 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_5 #> 3 g1_1 g1_7 #> 4 g1_1 g1_8 #> 5 g1_1 g1_9 #> 6 g1_1 g1_10 #> ... #>sim_basic_block_network(n_blocks = 8, n_nodes_per_block = 20)#> SBM Network with 160 nodes of a single type and 4092 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_4 #> 3 g1_1 g1_5 #> 4 g1_1 g1_6 #> 5 g1_1 g1_7 #> 6 g1_1 g1_9 #> ... #># 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.453 #> 2 g1 g2 0.915 #> 3 g1 g3 0.268 #> 4 g1 g4 0.176 #> 5 g2 g2 0.730 #> 6 g2 g3 0.823 #> 7 g2 g4 0.361 #> 8 g3 g3 0.0836 #> 9 g3 g4 0.638 #> 10 g4 g4 0.546right_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.163 #> 2 g1 g2 0.398 #> 3 g1 g3 0.148 #> 4 g1 g4 0.291 #> 5 g2 g2 0.147 #> 6 g2 g3 0.0169 #> 7 g2 g4 0.159 #> 8 g3 g3 0.0179 #> 9 g3 g4 0.0486 #> 10 g4 g4 0.446