Dear all,
I am trying to calculate the betweenness centrality with valued ties, but I do not figure it out. Here are the dataset and codes.
- This is an example dataset with only four nodes/individuals. When collecting the network data, I asked the participants to answer the question about friendship tie on a 7-point Likert scale. So, this is a directed and valued network. Moreover, when inputting the network data, I adopted the edge list format and saved it into a CSV file. The details of the data are as follows:
Actor Target Friend
1001 1002 5
1001 1003 6
1001 1004 5
1002 1001 6
1002 1003 6
1002 1004 6
1003 1001 4
1003 1002 4
1003 1004 4
1004 1001 6
1004 1002 6
1004 1003 6
- Then I ran the following codes to calculate the betweenness centrality:
library(igraph)
#Step 1. read the edgelist format dataset into R
Mydata <- read.table("Example.csv", header=TRUE, sep=",")
#Step 2. convert an edgelist matrix with valued edges/ties into a graph
Mygraph <- graph_from_data_frame(Mydata, directed=TRUE)
#Step 3. calculate betweenness centrality but fail to account for the value/weight of the tie
betweenness(Mygraph, directed = T, normalized = T)
- The results came out are as follows:
1001 1002 1003 1004
0 0 0 0
It seems that the package treated the dataset as that the four members mutually nominated each other as friends while ignored the strength of the tie. Therefore, each of them was connected to the others and no one had the opportunity to be a broker.
I have searched archival of the list, but I failed to locate the information that can completely solve my problem. So, I am wondering whether any colleagues here could share with me any information about this. I would be grateful if you can provide me any suggestions or references. Many thanks in advance!
Best,
Chuding
The betweenness centrality of a vertex is, roughly speaking, the number of shortest paths that pass through that vertex. In your graph, all shortest paths consist of a single edge. None of the shortest paths pass through any intermediate vertices. Therefore, all betweenness values are zero.
The strengths of links are not ignored, but even so all shortest paths consist of a single edge.
I am not familiar with the Likert scale, I just wanted to warn you that with betweenness calculations, edge âweightsâ are taken to mean edge lengths. Thus, the larger the number, the weaker the tie. The larger the number, the âfurtherâ the nodes it connects are.
Thanks for your prompt reply. And thanks for pointing out my example might be an extreme case that no one is occupying a âbrokerâ position. However, when I try with degree centrality, the results come out are still equal for each vertex, which is not consistent with the reality in the network. Here are the codes:
library(igraph)
#read the edgelist format dataset into R
Mydata <- read.table("Example.csv", header=TRUE, sep=",")
#convert an edgelist matrix with valued edges/ties into a graph
graph <- graph_from_data_frame(Mydata, directed=TRUE)
#calculate degree centrality but fail to account for the value/weight of the tie
degree(graph)
1001 1002 1003 1004
6 6 6 6
How do you think about this?
Best,
Chuding
Edge weights have two different interpretations. They can be interpreted as the strength of a tie (e.g. friendship, volume of trade, communication frequency), or as a cost that needs to be paid somehow (e.g. travel time, friction, distance).
Centrality measures based on shortest paths are only meaningful in the second interpretation. Shortest paths refer to paths that have the lowest total weight, and hence higher weights indicate edges that are less likely to be chosen as a shortest path. Centrality measures that use this interpretation are betweennness centrality and closeness centrality.
Centrality measures based on random walks, or eigenvectors, are meaningful in the former interpretation. Higher weights indicate edges that are more likely to be chosen, for example for a random walk, or weigh the importance of a node higher. Centrality measures that are consistent with this interpretation include PageRank and eigenvector centrality.
When using edge weights for calculating centrality, make sure that the interpretation of the weights is in line with the interpretation of weights as used in the centrality measure.
In short, in this context, centrality measures such as PageRank of eigenvector centrality make more sense.
Note that the degree does not account for the weight of edges, you would use the strength, i.e. the weighted degree, in this context.
1 Like
Thanks for your explanation, now I have better understood the interpretation of different centrality measures. And for the degree centrality with valued ties, I tried with you suggestion. Here are the codes and results:
> strength(graph, mode="in")
1001 1002 1003 1004
3 3 3 3
It seems that the package still ignores the weight in each tie. And I think I need to do some manipulation on the object/graph to be proceeded before I call for strength command. But I donât know how to do it. Could you give me some suggestions?
Best,
Chuding
You need to indicate which edge attribute you want to use as the weight, see igraph R manual pages.
It is still reporting errors:
strength(graph, mode = âinâ, weights = âFriendâ)
Error in strength(graph, mode = âinâ, weights = âFriendâ) :
At structural_properties.c:6014 : Invalid weight vector length, Invalid value
The graph doesnât seem to have the edge attribute âFriendâ. You can check the attributes by calling edge_attr
.
I checked and it seems that the edge attributes have been included in. Would you please have me take a look at the data in the attachment and the codes as follows:
Example.csv (177 Bytes)
library(igraph)
#read the edgelist format dataset into R
Mydata <- read.table("Example.csv", header=TRUE, sep=",")
#convert an edgelist matrix with valued edges/ties into a graph
graph <- graph_from_data_frame(Mydata, directed=TRUE)
#check the edge attributes
edge.attributes(graph)
$Friend
[1] 5 6 5 6 6 6 4 4 4 6 6 6
#calculate degree centrality but fail to account for the value/weight of the tie
strength(graph, mode="in")
1001 1002 1003 1004
3 3 3 3
Please place all code into code blocks when posting. You can use the formatting toolbar, or write Markdown, like this: How to use this forum?
Thanks for the clear explanation. When handling graphs where weights indicate strength of tie, would it make sense to define an edge attribute, cost
, that is the inverse of weight (1/weight), to use when calculating betweenness or closeness centrality?
That might be a possibility. A shortest path is then defined as the path that minimizes
\sum_e \frac{1}{w_e}
where w_e is the weight of edge e. This means that it would be better to have two edges of relatively large weight than a single edge of relatively low weight. Whether that is really what you want is up for debate.
Another alternative that I have thought about sometimes is to use -\log w_e if w_e \leq 1 for all e (which means that -\log w_e \geq 0). The shortest path is then the path that minimizes
\sum_e - \log(w_e)
which means it maximizes
\sum_e \log(w_e) = \log \prod_e w_e,
and since \log is concave, it maximizes
\prod_e w_e.
If w_e is interpreted as some probability that edge e functions (or can be travelled in some way), then this is the probability that each edge in the path functions, i.e. that the path as a whole is likely to function.
Thanks! I read up on this some more (in Opsahl et al.) and found that it is customary to use a positive âtuning parameter,â \alpha, when calculating inverse edge weights: \frac{1}{(w_e)^\alpha}. A common value is for \alpha is 0.5.
1 Like
Sorry, my mistake, apparently you cannot pass just the edge attribute, you must explicitly pass the vector, i.e.
strength(graph, mode="in", weights=E(graph)$Friend)
The results come out are: 13 8 14 13, which is not consistent with those I calculate manually: 16 15 18 15. What is wrong with this code?
If I run the code above, I get the result
> strength(graph, mode="in", weights=E(graph)$Friend)
1001 1002 1003 1004
16 15 18 15
Sorry for the trouble caused. Yes, it works when a restart R session. Many thanks!
And I have another question: how can I process a dataset with adjacency matrix format? Here is the dataset and codes, with which I failed to get the results:
Example 6.csv (54 Bytes)
library(igraph)
Mydata â read.table(âExample 6.csvâ, header=TRUE, sep=â,â)
Mygraph â graph_from_adjacency_matrix(Mydata, mode = c(âdirectedâ), weighted = TRUE)
strength(Mygraph, mode=âinâ, weights=E(graph)$Friend)