[R] eigenvalues and correlation matrices

dM/ david.n.menezes at gmail.com
Fri May 27 23:40:39 CEST 2011


Thanks Sarah.  Silly mistake.  I wrote the syntax when testing the
correlation matrix, hence the symmetric = TRUE statement.  I then
thought, hang on a minute; I better check that and forgot to unwind
the condition.

At least I'm not going mad!

On May 27, 8:40 pm, Sarah Goslee <sarah.gos... at gmail.com> wrote:
> Hi,
>
> How about because of this:
>
> > #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
>
> [1] 4 2 1
>
> Sarah
>
>
>
>
>
>
>
>
>
> On Fri, May 27, 2011 at 11:55 AM, dM/ <david.n.mene... 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
> > answers.  What gives?
>
> > #test std 3 x 3:
> >  setwd("S:/790/Actuarial/Computing and VBA/R development/
> > Eigenvalues")
> >  testmatrix<-data.frame(read.csv("threeBythree.csv",header=FALSE))
>
> >  testmatrix
>
> > #check that the matrix drawn in is correct
> >  nrow(testmatrix)
> >  ncol(testmatrix)
>
> > #calculate the eigenvalues
> >  eigen(testmatrix,symmetric = TRUE,only.value=TRUE)
>
> --
> Sarah Gosleehttp://www.functionaldiversity.org
>
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list