# Eigfact and eigen in R seems does not match

**URL:** <https://discourse.julialang.org/t/eigfact-and-eigen-in-r-seems-does-not-match/7341>\
**Category:** Numerics\
**Created:** [November 28, 2017, 12:43am UTC](https://discourse.julialang.org/t/eigfact-and-eigen-in-r-seems-does-not-match/7341 "2017-11-28T00:43:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![babaq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/babaq/32/891_2.png) [@babaq](https://discourse.julialang.org/u/babaq)\
**Post date:** [November 28, 2017, 12:43am UTC](https://discourse.julialang.org/t/eigfact-and-eigen-in-r-seems-does-not-match/7341/1 "2017-11-28T00:43:14Z")

</div>

In the process of converting some R code to Julia, i found the matrix Eigen decomposition produce different result compared to R. the following code is tested in Julia 0.6, and R 3.3.3 through RCall 0.8.1

```plaintext
using RCall
a=rand(1:5,5,5)
a=a'*a

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/7/074e963933f26619c7bf04a4c57d803dc1145350.png)

the R eigenvalues are in descending order, but they are the same as in Julia. however, some of the corresponding eigenvectors are different.

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [November 28, 2017, 12:48am UTC](https://discourse.julialang.org/t/eigfact-and-eigen-in-r-seems-does-not-match/7341/2 "2017-11-28T00:48:09Z")

</div>

They seem to be identical up to a minus sign in the value eigenvector of the smallest eigenvalue. Should be fairly simple to find out which of them two signs is correct.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 28, 2017, 1:29am UTC](https://discourse.julialang.org/t/eigfact-and-eigen-in-r-seems-does-not-match/7341/3 "2017-11-28T01:29:53Z")

</div>

> [@Keno](#):
>
> They seem to be identical up to a minus sign in the value eigenvector of the smallest eigenvalue. Should be fairly simple to find out which of them two signs is correct.

Both signs are correct. An eigenvector multiplied by any (nonzero) scalar is still an eigenvector.

For real-symmetric matrices, the usual convention is to return real orthonormal eigenvectors, but you can multiply by ±1 without changing the unit-length normalization. Which sign it picks is fairly random as far as I know.

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [November 28, 2017, 1:33am UTC](https://discourse.julialang.org/t/eigfact-and-eigen-in-r-seems-does-not-match/7341/4 "2017-11-28T01:33:18Z")

</div>

Sorry, temporary brain malfunction 😉 - I briefly thought changing the sign of the eigenvector would flip the sign of the eigenvalue, but this is of course not the case.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [November 28, 2017, 3:49am UTC](https://discourse.julialang.org/t/eigfact-and-eigen-in-r-seems-does-not-match/7341/5 "2017-11-28T03:49:53Z")

</div>

@babaq what is the ultimate goal of the computation? @stevengj is 100% correct, the signs shouldn’t matter if you are trying to project onto the basis or do common operations with the vectors.

---

<div class="post-metadata">

**Author:** ![babaq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/babaq/32/891_2.png) [@babaq](https://discourse.julialang.org/u/babaq)\
**Post date:** [November 28, 2017, 5:58am UTC](https://discourse.julialang.org/t/eigfact-and-eigen-in-r-seems-does-not-match/7341/6 "2017-11-28T05:58:24Z")

</div>

as @stevengj explained, i realized that the sign difference doesn’t matter in the context of Eigen factorization, as it’s showed that both factorization is correct. it did show that Julia and R code has some difference of choosing the signs.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/3/c3a0d29b03b10929d9ed341fa96246d359162aeb.png)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/3/634a2eaf9dc8d195d0f308fe983e3ba731c3c797.png)
