Skip to contents

Simulate a multiplex network

Usage

simulate_multiplex_network(
  nodes,
  layers,
  edges = NULL,
  probability = 0.1,
  directed = TRUE,
  loops = FALSE,
  weight = c("binary", "uniform", "normal", "poisson"),
  weight_mean = 1,
  weight_sd = 1,
  weight_range = c(0.1, 1),
  node_type = NULL,
  seed = NULL,
  batch = NULL
)

Arguments

nodes

Number of nodes or unique labels shared across layers.

layers

Number of layers or unique layer labels.

edges

Optional exact edge count, scalar or one value per layer.

probability

Edge probability, scalar or one value per layer.

directed

Single logical. TRUE (the default) draws ordered pairs, FALSE unordered pairs, each undirected edge stored once.

loops

Single logical. TRUE permits self-loops; defaults to FALSE.

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.

node_type

Optional node type for each node.

seed

Optional base seed. A single number, or NULL (the default). Layer k is drawn with seed + k - 1, so the call is reproducible and the session's random-number state is restored afterwards.

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 layered edge-list simulab_sim base data.frame with one row per edge and columns layer, from, to, and weight. Every layer is drawn independently over the same node set. as.data.frame(x, what = ) also returns nodes (node, type), layers (layer, probability), adjacency (a long layer/row/column/weight table over all ordered node pairs in every layer), and a one-row settings table.

Examples

result <- simulate_multiplex_network(nodes = 25, layers = 3, probability = 0.1, seed = 1)
head(result)
#> <simulab_sim:multiplex_network> 6 rows x 4 columns
#>     layer    from     to weight
#> 1 Layer 1  Node 5 Node 1      1
#> 2 Layer 1  Node 8 Node 1      1
#> 3 Layer 1 Node 19 Node 1      1
#> 4 Layer 1 Node 22 Node 1      1
#> 5 Layer 1 Node 14 Node 3      1
#> 6 Layer 1  Node 9 Node 4      1
#> 
#> Truth (settings):
#>   layers directed loops weight
#> 1      3     TRUE FALSE binary
#> 
#> Other tables: nodes, layers, adjacency. Read one with as.data.frame(x, what = "nodes").
components(result)
#>       table rows columns
#> 1      data  182       4
#> 2     nodes   25       2
#> 3    layers    3       2
#> 4 adjacency 1875       4
#> 5  settings    1       4