Skip to contents

Simulate a tidy network edge list

Usage

simulate_edge_list(
  nodes,
  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,
  edge_classes = NULL,
  class_probabilities = NULL,
  seed = NULL,
  batch = NULL
)

Arguments

nodes

Number of nodes or unique node labels. A single number produces the integer labels 1:nodes, as in simulate_network().

edges

Optional exact number of edges.

probability

Edge probability when edges is NULL.

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.

edge_classes

Optional number or labels of edge classes.

class_probabilities

Optional edge-class probabilities.

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 simulab_sim base data.frame with one row per edge and columns from, to, and weight (plus edge_class when edge_classes is supplied). as.data.frame(x, what = ) also returns nodes (node, type), adjacency (a long row/column/weight table over all ordered node pairs), and a one-row settings table.

Examples

result <- simulate_edge_list(nodes = 40, probability = 0.08, seed = 1)
head(result)
#> <simulab_sim:edge_list> 6 rows x 3 columns
#>   from to weight
#> 1    8  1      1
#> 2   19  1      1
#> 3   22  1      1
#> 4    2  3      1
#> 5   27  3      1
#> 6   32  3      1
#> 
#> Truth (settings):
#>       model directed loops weight nodes edges
#> 1 bernoulli     TRUE FALSE binary    40   138
#> 
#> Other tables: nodes, adjacency. Read one with as.data.frame(x, what = "nodes").
components(result)
#>       table rows columns
#> 1      data  138       3
#> 2     nodes   40       2
#> 3 adjacency 1600       3
#> 4  settings    1       6