Consider a dataframe df
where the first two columns are node pairs and successive columns V1
, V2
, ..., Vn
represent flows between the nodes (potentially 0, implying no edge for that column's network). I would like to conduct analysis on degree, community detection, and other network measures using the flows as weights.
Then to analyze the graph with respect to the weights in V1
I do:
# create graph and explore unweighted degrees with respect to V1
g <- graph.data.frame( df[df$V1!=0,] )
qplot(degree(g))
x <- 0:max(degree(g))
qplot(x,degree.distribution(g))
# set weights and explore weighted degrees using V1
E(g)$weights <- E(g)$V1
qplot(degree(g))
The output from the third qplot is no different than the first. What am I doing wrong?
Update:
So graph.strength
is what I am looking for, but graph.strength(g)
in my case gives standard degree output followed by:
Warning message:
In graph.strength(g) :
At structural_properties.c:4928 :No edge weights for strength calculation,
normal degree
I must be setting the weights incorrectly, is it not sufficient to do E(g)$weights <- E(g)$V1
and why can g$weights
differ from E(g)$weights
?
In igraph edge weights are represented via an edge attribute, called 'weight'. The is_weighted function only checks that such an attribute exists. (It does not even checks that it is a numeric edge attribute.) Edge weights are used for different purposes by the different functions.
Description. The degree of a vertex is its most basic structural property, the number of its adjacent edges.
By counting how many nodes have each degree, we form the degree distribution Pdeg(k), defined by Pdeg(k)=fraction of nodes in the graph with degree k. For this undirected network, the degrees are k1=1, k2=3, k3=1, k4=1, k5=2, k6=5, k7=3, k8=3, k9=2, and k10=1.
The function graph.strength
can be given a weights vector with the weights
argument. I think what is going wrong in your code is that you should call the weights attribute E(g)$weight
not E(g)$weights
.
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