0

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 [...]

Fulla
  • 17
  • 6

1 Answers1

1

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)

enter image description here

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • Hey lukeA, Thanks for your help. It seems to be a useful procedure to solve my problem. However, there is still another problem. Once I run the code with the command "simple.no.multiedges", the R software collapses on my notebook and I have to restart the program. – Fulla Aug 19 '15 at 00:16
  • @Fulla I cannot reproduce this. – lukeA Aug 19 '15 at 00:52
  • purpose is to create a graph with a core-periphery structure. For this is a 'Concentracion parameter' Lambda that include information about the degree quantities of the few hubs ( d_b ) in the network. These hubs have an expected value of E ( d_b ) = lambda * E ( d_s ) . E ( d_s ) is the expected value of the number of nodes with a low number of connections (-> low degree). These are randomly drawn from a Poisson distribution. – Fulla Aug 19 '15 at 13:58
  • Thanks, interesting snippet. `sample_degseq(D, D, method = "simple")` creates a graph successfully here. Maybe you wanna add the code to your question, so others, who may find it useful, will find it more easily. – lukeA Aug 19 '15 at 14:36
  • Sorry, i mean `sample_degseq(D, D, method = "simple.no.multiple"); ` instead – Fulla Aug 19 '15 at 16:58