Sample an Erdos-Renyi graph

erdos_renyi(n, p = NULL, avg_deg = NULL, directed = FALSE, ...)

erdos_renyi_params(n, p = NULL, avg_deg = NULL, directed = FALSE,
  ...)

Arguments

n

Number of nodes in graph.

p

Probability of an edge between any two nodes. You must specify either p or avg_deg. If you do not specify p, uses avg_deg / n.

avg_deg

Desired average out degree. When specified, rescales sampling probabilities to achieve the desired average out degree. Defaults to NULL, such that there is no rescaling.

directed

Defaults to FALSE for Erdos-Renyi graphs. The default in the more general fastRG() is TRUE.

...

Arguments passed on to fastRG

X

An n by k_1 matrix.

S

A k_1 by k_2 matrix.

Y

A d by k_2 matrix. Defaults to X.

avg_deg

When specified, rescales parameter such that the expected degree is avg_deg in the Poisson multi-graph. When poisson_edges = FALSE, the resulting graph will have lower a average degree than avg_deg due to lack of multi-edges. When the graph is sparse, the expected number of edges for the Poisson multi-graph and Bernoulli graph are nearly the same. Defaults to NULL, such that no scaling occurs.

simple

When TRUE, indicates that you want to work with undirected graphs where self-loops and multi-edges are prohibited. Accomplishes this by setting directed = FALSE, allow_self_loops = FALSE, and poisson_edges = FALSE, and then ignoring arguments directed, allow_self_loops and poisson_edges. Defaults to FALSE.

poisson_edges

Logical indicating whether or not multi-edges are allowed. Defaults to TRUE, which keeps multi-edges and produces a multi-graph. When FALSE, only single edges are allowed, resulting in a graph. See details for some additional comments. Effected by simple argument.

directed

Logical indicating whether or not the graph should be directed. Default is directed = TRUE. When directed = FALSE, symmetrizes S internally. When X = Y (which is the default when no Y is specified), this results in a symmetric adjacency matrix as output. When avg_deg is specified and the desired graph is directed, the average degree scaling is on the out-degree of each node (or the row sums if you prefer to think in terms of the adjacency matrix). Effected by the simple argument.

allow_self_loops

Logical indicating whether edges are allowed from a node back to itself. Defaults to TRUE. When FALSE, sampling proceeds normally, and then self-loops are removed after sampling is completed. Effected by the simple argument.

return_edge_list

Logical indicating whether to return an edgelist rather than an adjacency matrix. Defaults to FALSE.

Value

Never returns Poisson edges.

See also

fastRG()

Other bernoulli graphs: chung_lu, planted_partition

Examples

set.seed(27) # get the random dot product parameters erdos_renyi_params(n = 10, p = 0.1)
#> $X #> [,1] #> [1,] 1 #> [2,] 1 #> [3,] 1 #> [4,] 1 #> [5,] 1 #> [6,] 1 #> [7,] 1 #> [8,] 1 #> [9,] 1 #> [10,] 1 #> #> $S #> [,1] #> [1,] 0.1053605 #> #> $Y #> [,1] #> [1,] 1 #> [2,] 1 #> [3,] 1 #> [4,] 1 #> [5,] 1 #> [6,] 1 #> [7,] 1 #> [8,] 1 #> [9,] 1 #> [10,] 1 #>
# sample a small graph A <- erdos_renyi(n = 10, p = 0.1) A
#> 10 x 10 sparse Matrix of class "nsCMatrix" #> #> [1,] . | . . . . . . . . #> [2,] | | | . . . . | . | #> [3,] . | . . . . | . . . #> [4,] . . . . . . . . . | #> [5,] . . . . . . . . | . #> [6,] . . . . . . . . | . #> [7,] . . | . . . . . . | #> [8,] . | . . . . . . . . #> [9,] . . . . | | . . . . #> [10,] . | . | . . | . . .
# out degree of each node rowSums(A)
#> [1] 1 5 2 1 1 1 2 1 2 3
# in degree of each node colSums(A)
#> [1] 1 5 2 1 1 1 2 1 2 3
# sample a much larger graph B <- erdos_renyi(n = 10^6, avg_deg = 5)