# Re: [R] eigenvalues and correlation matrices

From: Sarah Goslee <sarah.goslee_at_gmail.com>
Date: Fri, 27 May 2011 15:40:19 -0400

Hi,

> #calculate the eigenvalues
> eigen(testmatrix,symmetric = TRUE,only.value=TRUE)

Your matrix isn't symmetric. If you claim that it is, R discards the upper triangle without checking. You really want this:

> testmatrix <- matrix(c(2, 1, 1, 1, 3, 2, -1, 1, 2), byrow=TRUE, nrow=3)
> testmatrix

[,1] [,2] [,3]

```[1,]    2    1    1
[2,]    1    3    2
[3,]   -1    1    2
```

> eigen(testmatrix)\$values

 4 2 1

Sarah

On Fri, May 27, 2011 at 11:55 AM, dM/ <david.n.menezes_at_gmail.com> wrote:
> I'm trying to test if a correlation matrix is positive semidefinite.
>
> My understanding is that a matrix is positive semidefinite if it is
> Hermitian and all its eigenvalues are positive.  The values in my
> correlation matrix are real and the layout means that it is symmetric.
> This seems to satisfy the Hermitian criterion so I figure that my real
> challenge is to check if the eigenvalues are all positive.
>
> I've tried to use eigen(base) to determine the eigenvalues. The
> results don't indicate any problems, but I thought I'd cross check the
> syntax by assessing the eigen values of the following simple 3 x 3
> matrix:
>
> row 1) 2,1,1
> row 2) 1,3,2
> row 3) -1,1,2
>
> The eigenvalues for this matrix are: 1,2 and 4.  I have confirmed this
> using the following site:
> http://www.akiti.ca/Eig3Solv.html
>
> However, when I run my code in R (see below), I get different
>
> #test std 3 x 3:
>  setwd("S:/790/Actuarial/Computing and VBA/R development/
> Eigenvalues")
>
>  testmatrix
>
> #check that the matrix drawn in is correct
>  nrow(testmatrix)
>  ncol(testmatrix)
>
> #calculate the eigenvalues
>  eigen(testmatrix,symmetric = TRUE,only.value=TRUE)
>

```--
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help