-8

I have tried using 'rewire' in igraph in R, but it works only for unweighted networks. Any help???

  • 1
    tried to edit to improve the question but my edit was rejected. seeing the comments below the OP says the key problem is the production of NAs when rewiring i.e. `using the example above NA in the wiehgts are produced with set.seed(1) g – user1320502 Aug 11 '16 at 12:29
  • 1
    @user1320502 The reason your edit was rejected is because you do not put words into the OP's mouth. The the question is not clear you should request the OP improve it. Your guess my not be correct so we should leave it to the OP. Really the only exception is taking a comment from the OP and adding it to the question. – NathanOliver Aug 11 '16 at 12:32
  • @user1320502 This edit is [being discussed on Meta](http://meta.stackoverflow.com/questions/332189/suggested-edit-deleting-the-question-in-its-entirety). – S.L. Barth Aug 11 '16 at 12:33
  • Thanks @NathanOliver but the OP's statement below " printing the weights of rewired graph will print weights with some NA entries. i hoped that weights will also be shuffled along with edges. but this is not happening...which is what i am interested in.???" makes it clear with regards to the NA edit and is not putting words into the OPs mouth. thanks though, I will ask a new separate question. Thanks for the meta link S.L Barth – user1320502 Aug 11 '16 at 12:33

2 Answers2

2

My version of igraph will happily rewire a weighted graph:

g <- graph.ring(10)
E(g)$weight <- seq_len(ecount(g))
E(g)$weight
# [1]  1  2  3  4  5  6  7  8  9 10
is.weighted(g)
# [1] TRUE
g2 <- rewire(g,niter=3)
plot(g2)
is.weighted(g2)
# [1] TRUE

Version is:

packageDescription("igraph")$Version
# [1] "0.6.6"
Gabor Csardi
  • 10,076
  • 1
  • 31
  • 49
Spacedman
  • 86,225
  • 12
  • 117
  • 197
  • 1
    this much is true. but i have a graph in edglist form. first two columns are nodes and third columns is weight assigned to each edge. now when i rewire the weighted graph (that i made using read.graph(file.txt)), this rewires the graph, but i dont know what it do with the weights. printing the weights of rewired graph will print weights with some NA entries. i hoped that weights will also be shuffled along with edges. but this is not happening...which is what i am interested in.??? – user3197361 Jan 18 '14 at 18:47
  • 3
    Give us some example code that shows this and edit your question. – Spacedman Jan 19 '14 at 23:56
1

Using version 1.0.1 of igraph, try the following:

# SAME EXAMPLE AS IN PREVIOUS ANSWER AND COMMENTS 
g <- graph.ring(10)
E(g)$weight <- seq_len(ecount(g))
E(g)$weight
# [1]  1  2  3  4  5  6  7  8  9 10
is.weighted(g)
# [1] TRUE
g2 <- rewire(g, with=each_edge(0.5)) #rewire vertices with constant probability
E(g2)$weight <- sample(E(g)$weight) #shuffle initial weights and assign them randomly to edges
plot(g2)
is.weighted(g2)
# [1] TRUE
E(g2)$weight
# [1]  3  6  2  4 10  1  9  8  7  5

Note that this approach might lead to multiedges or loops.