Skip to contents

Simulate a bipartite network

Usage

simulate_bipartite_network(
  actors,
  events,
  edges = NULL,
  probability = 0.1,
  weight = c("binary", "uniform", "normal", "poisson"),
  weight_mean = 1,
  weight_sd = 1,
  weight_range = c(0.1, 1),
  seed = NULL,
  batch = NULL
)

Arguments

actors

Number or labels of primary-mode nodes.

events

Number or labels of secondary-mode nodes.

edges

Optional exact number of cross-mode edges.

probability

Cross-mode edge probability when edges is NULL.

weight

Edge-weight distribution: "binary" (the default), every weight 1; "uniform" on weight_range; "normal" with weight_mean and weight_sd; or "poisson" with mean weight_mean.

weight_mean, weight_sd, weight_range

Parameters of weight: the mean of normal and Poisson weights (default 1), the standard deviation of normal weights (default 1), and the lower and upper limits of uniform weights (default c(0.1, 1)). Unused by binary weights.

seed

Optional random seed. A single number makes the call reproducible and restores the session's random-number state afterwards; NULL (the default) draws from the session's stream and advances it.

batch

Optional single positive whole number. When given, the simulator runs batch times and returns a plain list of batch results, each exactly what the same call without batch returns. With a seed, every dataset gets its own seed drawn from seed, so the whole batch is reproducible; without one the datasets are consecutive draws from the session's random-number stream. The default NULL returns a single result.

Value

A tidy cross-mode edge-list simulab_sim base data.frame with one row per actor-event edge and columns from (always an actor), to (always an event), weight, from_mode, and to_mode. The two modes are disjoint, so no edge joins two actors or two events and self-loops cannot occur. as.data.frame(x, what = ) also returns nodes (node, mode), incidence (the wide actor-by-event incidence table: an actor column followed by one column per event), and a one-row settings table.

Examples

result <- simulate_bipartite_network(actors = 20, events = 6, probability = 0.3, seed = 1)
head(result)
#> <simulab_sim:bipartite_network> 6 rows x 5 columns
#>       from      to weight from_mode to_mode
#> 1  Actor 4 Event 1      1     actor   event
#> 2  Actor 6 Event 1      1     actor   event
#> 3  Actor 7 Event 1      1     actor   event
#> 4 Actor 15 Event 1      1     actor   event
#> 5 Actor 17 Event 1      1     actor   event
#> 6 Actor 18 Event 1      1     actor   event
#> 
#> Truth (settings):
#>   probability weight actors events
#> 1         0.3 binary     20      6
#> 
#> Other tables: nodes, incidence. Read one with as.data.frame(x, what = "nodes").
components(result)
#>       table rows columns
#> 1      data   37       5
#> 2     nodes   26       2
#> 3 incidence   20       7
#> 4  settings    1       4