# Getting graph density on a graph with multiple edges

**URL:** <https://igraph.discourse.group/t/getting-graph-density-on-a-graph-with-multiple-edges/1693>\
**Category:** Usage\
**Tags:** R\
**Created:** [27 October 2023 18:29 UTC](https://igraph.discourse.group/t/getting-graph-density-on-a-graph-with-multiple-edges/1693 "2023-10-27T18:29:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cookiebarry](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@cookiebarry](https://igraph.discourse.group/u/cookiebarry)\
**Post date:** [27 October 2023 18:29 UTC](https://igraph.discourse.group/t/getting-graph-density-on-a-graph-with-multiple-edges/1693/1 "2023-10-27T18:29:01Z")

</div>

Hello everyone!

I am working on a swine movement network analysis. I am analyzing the inter-city movement of pigs in my country.

In the inter-city movement of pigs, I have 685 cities and 37138 shipments (name of network is Swine\_Graph). Each city can have 1 or more pig shipment creating multiple edges in each node.

When I ran my graph density in R, I wrote the following:  
graph.density(SwinePH\_Graph)

It gave me a value of 0.079 (does this mean my graph density is 7.9%)

However, when I looked into the igraph R manual, I saw this statement in graph.density → “Note that this function may return strange results for graph with multiple edges, density is ill-defined for graphs with multiple edges”

If this is the case, how should I properly compute my graph density if I have multiple edges in one node?

Appreciate your response on this

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [27 October 2023 22:49 UTC](https://igraph.discourse.group/t/getting-graph-density-on-a-graph-with-multiple-edges/1693/2 "2023-10-27T22:49:40Z")

</div>

> [@cookiebarry](#):
>
> However, when I looked into the igraph R manual, I saw this statement in graph.density → “Note that this function may return strange results for graph with multiple edges, density is ill-defined for graphs with multiple edges”

It seems you are using a rather outdated version. Why don’t you use the latest? The statement in the documentation is much clearer:

> **[Graph density — edge\_density](https://r.igraph.org/reference/edge_density.html)**
>
> The density of a graph is the ratio of the actual number of edges and the
> largest possible number of edges in the graph, assuming that no multi-edges
> are present.

> [@cookiebarry](#):
>
> If this is the case, how should I properly compute my graph density if I have multiple edges in one node?

The first questions to answer:

- What do you mean when you say “graph density”? Can you explain the concept?
- _Why_ are you trying to compute it?

While this may not sound like a response, in fact it is. I am trying to lead you onto the right path.

---

<div class="post-metadata">

**Author:** ![cookiebarry](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@cookiebarry](https://igraph.discourse.group/u/cookiebarry)\
**Post date:** [10 November 2023 20:18 UTC](https://igraph.discourse.group/t/getting-graph-density-on-a-graph-with-multiple-edges/1693/3 "2023-11-10T20:18:17Z")

</div>

Hello szhorvat,

I would like to know the density of my network. I am working to compute the density of pig shipments. From my research in several articles, I saw that the formula for a directed network is

total number of edges/(total number of nodes\*(total number of nodes - 1))

In my 1st network, my data seems to have a value of below 1:  
37128/(685\*684) = 0.079

However, in my second network where there are only few nodes (66 provinces), there seems to be a very big value:

31622/(66\*65) = 7.37

My data involves animal shipments (edges) in different provinces (nodes). It is very possible that there are multiple shipments in one province. There was a suggestion to me to use the following formula:

D= total number of edges / (total number of nodes\*(total number of nodes -1) \* multiplicity factor

The multiplicity factor represents the number of shipments between the same pair of nodes.

Does this seem to be a logical way of computing for density given the nature of my network?

Appreciate your help on this

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [12 November 2023 21:25 UTC](https://igraph.discourse.group/t/getting-graph-density-on-a-graph-with-multiple-edges/1693/4 "2023-11-12T21:25:37Z")

</div>

It seems to me that you are approaching this a bit backwards: “I want to calculate graph density, what is the formula/algorithm for it?”

_Why_ do you want to calculate the graph density? Graph density is simply the fraction of connections that are present between the given vertices, relative to how many there could be at most. In multigraphs, there is no upper bound on the number of connections, so the concept of graph density does not make sense.
