Create an undirected erdos renyi object
Arguments
- n
Number of nodes in graph.
- ...
Arguments passed on to
undirected_factor_model
expected_degree
If specified, the desired expected degree of the graph. Specifying
expected_degree
simply rescalesS
to achieve this. Defaults toNULL
. Do not specify bothexpected_degree
andexpected_density
at the same time.
- p
Probability of an edge between any two nodes. You must specify either
p
orexpected_degree
.- poisson_edges
Logical indicating whether or not multiple edges are allowed to form between a pair of nodes. Defaults to
TRUE
. WhenFALSE
, sampling proceeds as usual, and duplicate edges are removed afterwards. Further, whenFALSE
, we assume thatS
specifies a desired between-factor connection probability, and back-transform thisS
to the appropriate Poisson intensity parameter to approximate Bernoulli factor connection probabilities. See Section 2.3 of Rohe et al. (2017) for some additional details.- allow_self_loops
Logical indicating whether or not nodes should be allowed to form edges with themselves. Defaults to
TRUE
. WhenFALSE
, sampling proceeds allowing self-loops, and these are then removed after the fact.
See also
Other erdos renyi:
directed_erdos_renyi()
Other undirected graphs:
chung_lu()
,
dcsbm()
,
mmsbm()
,
overlapping_sbm()
,
planted_partition()
,
sbm()
Examples
set.seed(87)
er <- erdos_renyi(n = 10, p = 0.1)
er
#> Undirected Factor Model
#> -----------------------
#>
#> Nodes (n): 10
#> Rank (k): 1
#>
#> X: 10 x 1 [dgeMatrix]
#> S: 1 x 1 [ddiMatrix]
#>
#> Poisson edges: TRUE
#> Allow self loops: TRUE
#>
#> Expected edges: 10
#> Expected degree: 1
#> Expected density: 0.22222
er <- erdos_renyi(n = 10, expected_density = 0.1)
er
#> Undirected Factor Model
#> -----------------------
#>
#> Nodes (n): 10
#> Rank (k): 1
#>
#> X: 10 x 1 [dgeMatrix]
#> S: 1 x 1 [ddiMatrix]
#>
#> Poisson edges: TRUE
#> Allow self loops: TRUE
#>
#> Expected edges: 4
#> Expected degree: 0.4
#> Expected density: 0.1
big_er <- erdos_renyi(n = 10^6, expected_degree = 5)
big_er
#> Undirected Factor Model
#> -----------------------
#>
#> Nodes (n): 1000000
#> Rank (k): 1
#>
#> X: 1000000 x 1 [dgeMatrix]
#> S: 1 x 1 [ddiMatrix]
#>
#> Poisson edges: TRUE
#> Allow self loops: TRUE
#>
#> Expected edges: 5e+06
#> Expected degree: 5
#> Expected density: 1e-05
A <- sample_sparse(er)
A
#> 10 x 10 sparse Matrix of class "dsCMatrix"
#>
#> [1,] . . . . . . . . . .
#> [2,] . . . 1 . . . . . .
#> [3,] . . . . . . . . . .
#> [4,] . 1 . . . . . . . .
#> [5,] . . . . . . . . . .
#> [6,] . . . . . . . . . .
#> [7,] . . . . . . . . . .
#> [8,] . . . . . . . . . .
#> [9,] . . . . . . . . . .
#> [10,] . . . . . . . . . .