Generates a bernoulli random graph.
Integer. Number of vertices
Integer. Number of time periods
Double. Probability of a link between ego and alter.
Logical scalar. Whether the graph is undirected or not.
Logical. Whether the graph is weighted or not.
Logical. Whether it includes self-edges.
Logical. When TRUE the graph is presented as an edgelist instead of an adjacency matrix.
A graph represented by an adjacency matrix (if t=1
), or an array of
adjacency matrices (if t>1
).
For each pair of nodes \(\{i,j\}\), an edge is created with probability \(p\), this is, \(Pr\{Link i-j\} = Pr\{x<p\}\), where \(x\) is drawn from a \(Uniform(0,1)\).
When weighted=TRUE
, the strength of ties is given by
the random draw \(x\) used to compare against \(p\), hence, if \(x < p\)
then the strength will be set to \(x\).
In the case of dynamic graphs, the algorithm is repeated \(t\) times, so the networks are uncorrelated.
The resulting adjacency matrix is store as a dense matrix, not as a sparse matrix, hence the user should be careful when choosing the size of the network.
Barabasi, Albert-Laszlo. "Network science book" Retrieved November 1 (2015) https://barabasi.com/book/network-science.
Other simulation functions:
permute_graph()
,
rdiffnet()
,
rewire_graph()
,
rgraph_ba()
,
rgraph_ws()
,
ring_lattice()
# Setting the seed
set.seed(13)
# Generating an directed graph
rgraph_er(undirected=FALSE, p = 0.1)
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#> [[ suppressing 10 column names ‘1’, ‘2’, ‘3’ ... ]]
#>
#> 1 . . . . . 1 . . . .
#> 2 . . . . . . . . . .
#> 3 . . . . . . . . . .
#> 4 . . . . . . 1 . . .
#> 5 . . . . . . . 1 . .
#> 6 1 . . . . . . . . 1
#> 7 . . . . . . . . . .
#> 8 . . . . . . . . . .
#> 9 . . . 1 . . . . . .
#> 10 . 1 . . . 1 . . 1 .
# Comparing P(tie)
x <- rgraph_er(1000, p=.1)
sum(x)/length(x)
#> [1] 0.099633
# Several period random gram
rgraph_er(t=5)
#> $`1`
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#> [[ suppressing 10 column names ‘1’, ‘2’, ‘3’ ... ]]
#>
#> 1 . . . . . . . . . .
#> 2 . . . 1 . . . . . .
#> 3 . . . . . . . . . .
#> 4 . . . . . . . . . .
#> 5 . . . . . . . . . .
#> 6 . . . . . . . . . .
#> 7 . . . . . . . . . 1
#> 8 . . . . . . . . . .
#> 9 . . . . . . . . . .
#> 10 . . . . . . . . . .
#>
#> $`2`
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#> [[ suppressing 10 column names ‘1’, ‘2’, ‘3’ ... ]]
#>
#> 1 . . . . . . . . . .
#> 2 . . . . . . . . . .
#> 3 . . . . . . . . . .
#> 4 . . . . . . . . . .
#> 5 . . . . . . . . . .
#> 6 . . . . . . . . . .
#> 7 . . . . . . . . . .
#> 8 . . . . . . . . . .
#> 9 . . . . . . . . . .
#> 10 . . . . . . . . . .
#>
#> $`3`
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#> [[ suppressing 10 column names ‘1’, ‘2’, ‘3’ ... ]]
#>
#> 1 . . . . . . . . . .
#> 2 . . . . . . . . . .
#> 3 . . . . . . . . . .
#> 4 1 . . . . . . . . .
#> 5 . . . . . . . . . .
#> 6 . . . . . . . . . .
#> 7 . . . . . . . . . .
#> 8 . . . . . . . . . .
#> 9 . . . . . . . . . .
#> 10 . . . . . . . . . .
#>
#> $`4`
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#> [[ suppressing 10 column names ‘1’, ‘2’, ‘3’ ... ]]
#>
#> 1 . . . . . . . . . .
#> 2 . . . . . . . . . .
#> 3 . . . . . . . . . .
#> 4 . . . . . . . . . .
#> 5 . . . . . . . . . .
#> 6 . . . . . . . . . .
#> 7 . . . . . . . . . .
#> 8 . . . . . . . . . .
#> 9 . . . . . . . . . .
#> 10 . . . . . . . . . .
#>
#> $`5`
#> 10 x 10 sparse Matrix of class "dgCMatrix"
#> [[ suppressing 10 column names ‘1’, ‘2’, ‘3’ ... ]]
#>
#> 1 . . . . . . . . . .
#> 2 . . . . . . . . . .
#> 3 . . . . . . . . . .
#> 4 . . . . . . . . . 1
#> 5 . . . . . . . . . .
#> 6 . . . . . . . . . .
#> 7 . . . . . . . . . .
#> 8 . . . . . . . . . .
#> 9 . . . . . . . . . .
#> 10 . . . . . . . . . .
#>
#> attr(,"undirected")
#> [1] FALSE