# What is the meaning of warning .c:348 in eigen\_centrality?

**URL:** <https://igraph.discourse.group/t/what-is-the-meaning-of-warning-c-348-in-eigen-centrality/1266>\
**Category:** Usage\
**Tags:** R\
**Created:** [23 June 2022 13:58 UTC](https://igraph.discourse.group/t/what-is-the-meaning-of-warning-c-348-in-eigen-centrality/1266 "2022-06-23T13:58:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![KeesP](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@KeesP](https://igraph.discourse.group/u/KeesP)\
**Post date:** [23 June 2022 13:58 UTC](https://igraph.discourse.group/t/what-is-the-meaning-of-warning-c-348-in-eigen-centrality/1266/1 "2022-06-23T13:58:58Z")

</div>

Program:

```auto
if (!require(igraph)) q()
igraph_version()

# -x^3 + 1/4x + 1/2
mg <- matrix(c(0, 0, 0.5, 1, 0, 0, 0.5, 1, 0), ncol=3)
g <- graph_from_adjacency_matrix(
  mg,
  mode = c("directed"),
  weighted = TRUE,
  diag = TRUE,
  add.colnames = NULL,
  add.rownames = NA
)

eigen_centrality(
  g,
  directed = TRUE,
  scale = TRUE,
  weights = NULL,
  options = arpack_defaults
)

```

gives the following warning:

Warning message:  
In eigen\_centrality(g, directed = TRUE, scale = TRUE, weights = NULL, :  
: At core/centrality/centrality\_other.c:348 : Weighted directed graph in eigenvector centrality.

And how to interpret the result: 0.5566931 0.6198144 1.0000000 ?

---

<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:** [23 June 2022 15:17 UTC](https://igraph.discourse.group/t/what-is-the-meaning-of-warning-c-348-in-eigen-centrality/1266/2 "2022-06-23T15:17:11Z")

</div>

Thanks for pointing out this confusing message. This should be improved. I am in fact not sure why it was added (over 12 years ago) but the likely reason is that eigenvector centrality is not well-defined for all inputs, and directed graphs can be problematic. Generally, people use hub and authority scores in directed graphs.

Eigenvector centrality is usually justified through the [Perron-Frobenius theorem](https://en.wikipedia.org/wiki/Perron%E2%80%93Frobenius_theorem#Non-negative_matrices). In short, this guarantees that there is a unique non-negative solution to the problem if the graph is strongly connected and all weights are positive. Most directed networks you will come across are not strongly connected, and eigenvector centrality may not be meaningful. For example, there may be more than one solution to the problem, but igraph will only return one (without warning) or may fail entirely.

---

<div class="post-metadata">

**Author:** ![KeesP](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@KeesP](https://igraph.discourse.group/u/KeesP)\
**Post date:** [23 June 2022 15:57 UTC](https://igraph.discourse.group/t/what-is-the-meaning-of-warning-c-348-in-eigen-centrality/1266/3 "2022-06-23T15:57:43Z")

</div>

The documentation states:

> Eigenvector centrality scores correspond to the values of the first eigenvector of the graph adjacency matrix.

This is well defined but only unique if the graph is strongly connected as in this example (from Edmund Landau in _Über Preisverteilung bei Spielturnieren_) as you pointed out.

The result I expect is:

```auto
> pev <- Re(eigen(g[])$vector[,1]) # Principle/first eigenvalue
> pev / pev[3] # normalize
[1] 1.796322 1.113386 1.000000

```

However the result from eigen\_centrality in this example is different, e.g.

```auto
[1] 0.5566931 0.6198144 1.0000000

```

Which result is correct?

---

<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:** [23 June 2022 16:03 UTC](https://igraph.discourse.group/t/what-is-the-meaning-of-warning-c-348-in-eigen-centrality/1266/4 "2022-06-23T16:03:50Z")

</div>

igraph computes the left eigenvalue, i.e. the score of a vertex is proportional to the sum of the scores of vertices _pointing to it_ (not the vertices it points to). With `eigen` you computed the right eigenvalue.

There is more extensive documentation here:

[https://igraph.org/c/html/latest/igraph-Structural.html#igraph\_eigenvector\_centrality](https://igraph.org/c/html/latest/igraph-Structural.html#igraph_eigenvector_centrality)

---

<div class="post-metadata">

**Author:** ![KeesP](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@KeesP](https://igraph.discourse.group/u/KeesP)\
**Post date:** [23 June 2022 17:19 UTC](https://igraph.discourse.group/t/what-is-the-meaning-of-warning-c-348-in-eigen-centrality/1266/5 "2022-06-23T17:19:34Z")

</div>

If I am right I have to reverse the arrows of the graph to get the right eigenvector of the graph.

Unfortunately this does not seem to work as is shown in the following code:

```auto
> tg <- g %>% get.edgelist %>% .[, 2:1] %>% graph_from_edgelist(directed=TRUE) # transpose graph
> ec <- 
+ eigen_centrality(
+ tg,
+ directed = TRUE,
+ scale = TRUE,
+ weights = NULL,
+ options = arpack_defaults
+ )$vector
> ec <- ec / ec[3]
> ec
[1] 1.3247180 0.7548777 1.0000000

```

---

<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:** [23 June 2022 17:33 UTC](https://igraph.discourse.group/t/what-is-the-meaning-of-warning-c-348-in-eigen-centrality/1266/6 "2022-06-23T17:33:29Z")

</div>

After recreating the graph with reversed edges, you did not transfer the original weights.

There’s ongoing work to add a function for reversing edges without losing attributes, as well as for adding a `mode` argument to `eigen_centrality()`:

- [Wishlist: Reverse the direction of edges while preserving attributes · Issue #1477 · igraph/igraph · GitHub](https://github.com/igraph/igraph/issues/1477)
- [Add 'mode' argument for eigenvector\_centrality · Issue #2095 · igraph/igraph · GitHub](https://github.com/igraph/igraph/issues/2095)

Vote for these issues to indicate your interest, then we might resolve them sooner.

---

<div class="post-metadata">

**Author:** ![KeesP](https://avatars.discourse-cdn.com/v4/letter/k/2bfe46/32.png) [@KeesP](https://igraph.discourse.group/u/KeesP)\
**Post date:** [23 June 2022 18:26 UTC](https://igraph.discourse.group/t/what-is-the-meaning-of-warning-c-348-in-eigen-centrality/1266/7 "2022-06-23T18:26:21Z")

</div>

Thanks for pointing this out.

```auto
tg <- g %>% get.edgelist %>% .[, 2:1] %>% graph_from_edgelist(directed=TRUE) # transpose graph
E(tg)$weight <- E(g)$weight
tg <- permute(tg, match(V(tg)$name, V(g)$name)) # restore original order of vertices
identical(V(tg)$name, V(sg)$name)

 ec <- 
  eigen_centrality(
   tg,
   directed = TRUE,
   scale = TRUE,
   weights = NULL,
   options = arpack_defaults
)$vector

Warning message:
In eigen_centrality(tg, directed = TRUE, scale = TRUE, weights = NULL, :
  At core/centrality/centrality_other.c:348 : Weighted directed graph in eigenvector centrality.
> ec / ec[3]
[1] 1.796322 1.113386 1.000000
> 

```

Which is correct indeed.

Transpose(g) would be a nice name for a function to reverse edges.  
See [Transpose graph - Wikipedia](https://en.wikipedia.org/wiki/Transpose_graph)
