randomGraph: Random Graph Generator

randomGraphR Documentation

Random Graph Generator

Description

A function for generating a random directed graph.

Usage

randomGraph(
  NV,
  NC,
  NP,
  timestep,
  maxDist,
  ...,
  mean = c("arithmetic", "geometric", "harmonic"),
  weighting = invDistWeighting,
  verbose = TRUE,
  saveDist = TRUE
)

Arguments

NV

An integer. The number of vertices to generate.

NC

A function with a ... argument returning the maximum number outgoing edges from each of the vertices; effectively determining the maximum number of children vertices for any given vertex.

NP

A function with a ... argument returning the maximum number of incoming edges to each of the vertices; effectively determining the maximum number of parent vertices for any given vertex.

timestep

A function with a ... argument returning the amount of time associated with the edges.

maxDist

A function with a ... argument returning the maximum distances, in terms of time, allowed between any two parents vertices.

...

Any arguments to be passed internally to the functions given as arguments NC, NP, timestep, maxDist, or weighting.

mean

One of character strings "arithmetic", "geometric", "harmonic", or any unambiguous abbreviation thereof, specifying the type of mean used for averaging the distances when a vertex has multiple ascendant edges.

weighting

A weighting function; it takes a set of distances as its first argument and returns a set of weights summing to 1 (default: invDistWeighting).

verbose

A Boolean. Whether or not to print messages associated with the graph simulation process (default: TRUE).

saveDist

A Boolean. Whether or not to save the graph distance matrix as an attribute to the returned graph-class object (default: TRUE).

Details

Details contents...

Value

A graph-class object.

Author(s)

Guillaume Guénard [aut, cre] (<https://orcid.org/0000-0003-0761-3072>), Pierre Legendre [ctb] (<https://orcid.org/0000-0002-3838-3305>) Maintainer: Guillaume Guénard <guillaume.guenard@umontreal.ca>

See Also

graph-class.

Examples

## Setting the RNG seed to obtain consistent examples:
set.seed(2182955)

## A linear evolutionary sequence with random edge lengths between 2 and 5:
randomGraph(
  NV = 100,
  NC = function(...) 1,
  NP = function(...) 1,
  timestep = function(ts_min, ts_max, ...) runif(1, ts_min, ts_max),
  maxDist = function(...) NULL,
  ts_min = 2,
  ts_max = 5
)

## As above, but allowing for dichotomic splitting.
randomGraph(
  NV = 100,
  NC = function(...) 2,
  NP = function(...) 1,
  timestep = function(ts_min, ts_max, ...) runif(1, ts_min, ts_max),
  maxDist = function(...) NULL,
  ts_min = 2,
  ts_max = 5
)

## A random evolutionary graph with random numbers of children and parents per
## node, random time steps, and a random maximum distance between the parents:
randomGraph(
  NV = 250,
  NC = function(lambda_child, ...) 1 + rpois(1, lambda_child),
  NP = function(lambda_parent, ...) 1 + rpois(1, lambda_parent),
  timestep = function(ts_min, ts_max, ...) runif(1, ts_min, ts_max),
  maxDist = function(max_anc, ...) runif(1, 0, max_anc),
  lambda_child = 2.5,
  lambda_parent = 4,
  ts_min = 2,
  ts_max = 5,
  max_anc = 4
)


guenardg/MPSEM documentation built on April 14, 2025, 3:53 p.m.