I have the following problem in R: I have a vector that contains the degrees of 200 nodes in my graph. Strictly speaking should they present out-degrees. Is it possible to create from these existing degrees for the nodes i = 1, ...,200 a random graph and its adjacency matrix?
As an example some degrees of the vector are entered below:
118 134 120 124 102 100 126 123 112 3 3 4 6 4 4 2 3 2 3 8 5 3 2 4 5 7 3 4 5 8 3 4 2 9 0 1 4 4 4 6 5 2 2 4 4 7 6 5 5 5 3 3 4 5 5 5 1 3 6 4 8 7 9 6 3 2 3 6 4 7 2 8 7 6 9 3 1 3 [...]
I think you can use sample_degseq
from igraph
:
library(igraph)
outdegrees <- c(2, 1, 1, 2, 4)
g <- sample_degseq(outdegrees, method = "simple.no.multiple")
get.adjacency(g)
# 5 x 5 sparse Matrix of class "dgCMatrix"
#
# [1,] . . . 1 1
# [2,] . . . . 1
# [3,] . . . . 1
# [4,] 1 . . . 1
# [5,] 1 1 1 1 .
plot(g)