Create an organisation where each unit starts with a specified number of child units up until a maximum depth, but where units are then randomly removed according to probabilities set in either a single value for all units, a value per unit depth or a user defined function of depth.

create_realistic_org(n_children = 4, max_depth = 3, prob = 0.3,
  .f = NULL, delete_units = TRUE)

Arguments

n_children

number of child units per parent unit (integer)

max_depth

integer maximum depth of organisation (integer)

prob

probability that a unit is deleted to create an irregular organisation. If a vector is provided that is the same length as max_depth then a different probability can be assigned to different levels of the organisation (double or vector of doubles)

.f

function of depth that generates probability that a unit is removed (NOT IMPLEMENTED) (function of x)

delete_units

retains intermediate variables and doesn't delete units - useful to understand how the function is working (logical)

Value

tidygraph object

Examples

set.seed(1234) tg1a <- create_realistic_org(4,3, prob=0.3) tg1a
#> # A tbl_graph: 42 nodes and 41 edges #> # #> # A rooted tree #> # #> # Node Data: 42 x 2 (active) #> unit_id org_depth #> <chr> <int> #> 1 1 0 #> 2 2 1 #> 3 3 1 #> 4 4 1 #> 5 6 2 #> 6 7 2 #> # ... with 36 more rows #> # #> # Edge Data: 41 x 2 #> from to #> <int> <int> #> 1 1 2 #> 2 1 3 #> 3 1 4 #> # ... with 38 more rows
# NOT RUN { plot_org(tg1a, fill_var='org_depth') # }
set.seed(1234) tg1b <- create_realistic_org(4,3, prob=0.3, delete_units=FALSE) tg1b
#> # A tbl_graph: 85 nodes and 84 edges #> # #> # A rooted tree #> # #> # Node Data: 85 x 5 (active) #> unit_id org_depth prob_deletion branch_delete to_delete #> <chr> <int> <dbl> <int> <int> #> 1 1 0 0.3 0 0 #> 2 2 1 0.3 0 0 #> 3 3 1 0.3 0 0 #> 4 4 1 0.3 0 0 #> 5 5 1 0.3 1 1 #> 6 6 2 0.3 0 0 #> # ... with 79 more rows #> # #> # Edge Data: 84 x 2 #> from to #> <int> <int> #> 1 1 2 #> 2 1 3 #> 3 1 4 #> # ... with 81 more rows
# NOT RUN { plot_org(tg1b, fill_var='to_delete') # }
set.seed(1234) tg2a <- create_realistic_org(4,3, prob=c(0.2, 0.4, 0.6)) tg2a
#> # A tbl_graph: 26 nodes and 25 edges #> # #> # A rooted tree #> # #> # Node Data: 26 x 2 (active) #> unit_id org_depth #> <chr> <int> #> 1 1 0 #> 2 2 1 #> 3 3 1 #> 4 4 1 #> 5 5 1 #> 6 8 2 #> # ... with 20 more rows #> # #> # Edge Data: 25 x 2 #> from to #> <int> <int> #> 1 1 2 #> 2 1 3 #> 3 1 4 #> # ... with 22 more rows
# NOT RUN { plot_org(tg2a, fill_var='org_depth') # }
set.seed(1234) tg2b <- create_realistic_org(4,3, prob=c(0.2, 0.4, 0.6), delete_units=FALSE) tg2b
#> # A tbl_graph: 85 nodes and 84 edges #> # #> # A rooted tree #> # #> # Node Data: 85 x 5 (active) #> unit_id org_depth prob_deletion branch_delete to_delete #> <chr> <int> <dbl> <int> <int> #> 1 1 0 0 0 0 #> 2 2 1 0.2 0 0 #> 3 3 1 0.2 0 0 #> 4 4 1 0.2 0 0 #> 5 5 1 0.2 0 0 #> 6 6 2 0.4 1 1 #> # ... with 79 more rows #> # #> # Edge Data: 84 x 2 #> from to #> <int> <int> #> 1 1 2 #> 2 1 3 #> 3 1 4 #> # ... with 81 more rows
# NOT RUN { plot_org(tg2b, fill_var='to_delete') # }