I would like to generate an undirected network with 100 nodes, where half of the nodes have a degree of 10 and the other half has a degree of 3. Is such a network possible to construct without self loops?
Using the code specified below:
library(graph)
degrees=c(rep(3,50),rep(10,50))
names(degrees)=paste("node",seq_along(degrees)) #nodes must be names
x=randomNodeGraph(degrees)
I can obtain such a graph, but there are self-loops included.
Is there any way to get a graph without self loops?
It is easy to do with the graph package from Bioconductor (see here)
#install graph from Bioconductor
source("http://bioconductor.org/biocLite.R")
biocLite("graph")
#load graph and make the specified graph
library(graph)
degrees=c(rep(3,50),rep(10,50))
names(degrees)=paste("node",seq_along(degrees)) #nodes must be names
x=randomNodeGraph(degrees)
#verify graph
edges=edgeMatrix(x)
edgecount=table(as.vector(edges))
table(edgecount)
#edgecount
# 3 10
#50 50
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With