Random Bernoulli graph

rbernoulli(n, p = 0.5)

Arguments

n

Integer vector. Size of the graph. If length(n) > 1, then it will a list of random graphs.

p

Probability of a tie. This may be either a scalar, or a vector of the same length of n.

Value

If n is a single number, a square matrix of size n with zeros in the diagonal. Otherwise it returns a list of length(n) square matrices of sizes equal to those specified in n.

Examples

# A graph of size 4 rbernoulli(4)
#> [,1] [,2] [,3] [,4] #> [1,] 0 1 1 0 #> [2,] 0 0 1 1 #> [3,] 0 0 0 0 #> [4,] 0 1 1 0
# 3 graphs of various sizes rbernoulli(c(3, 4, 2))
#> [[1]] #> [,1] [,2] [,3] #> [1,] 0 0 0 #> [2,] 1 0 0 #> [3,] 0 1 0 #> #> [[2]] #> [,1] [,2] [,3] [,4] #> [1,] 0 1 0 0 #> [2,] 1 0 1 1 #> [3,] 0 1 0 0 #> [4,] 1 1 1 0 #> #> [[3]] #> [,1] [,2] #> [1,] 0 1 #> [2,] 1 0 #>
# 3 graphs of various sizes and different probabilities rbernoulli(c(3, 4, 6), c(.1, .2, .3))
#> [[1]] #> [,1] [,2] [,3] #> [1,] 0 0 0 #> [2,] 0 0 0 #> [3,] 0 0 0 #> #> [[2]] #> [,1] [,2] [,3] [,4] #> [1,] 0 0 0 0 #> [2,] 0 0 0 0 #> [3,] 1 0 0 0 #> [4,] 1 0 0 0 #> #> [[3]] #> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 0 1 0 0 0 1 #> [2,] 0 0 1 0 1 0 #> [3,] 0 0 0 0 1 1 #> [4,] 0 0 0 0 0 0 #> [5,] 1 0 0 0 0 0 #> [6,] 0 0 0 1 0 0 #>