问题
I have tried using 'rewire' in igraph in R, but it works only for unweighted networks. Any help???
回答1:
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"
回答2:
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.
来源:https://stackoverflow.com/questions/21179746/how-do-you-rewire-a-weighted-network-using-igraph-in-r