From: Sarah Goslee <sarah.goslee_at_gmail.com>

Date: Fri, 27 May 2011 15:40:19 -0400

*> eigen(testmatrix)$values
*

[1] 4 2 1

Date: Fri, 27 May 2011 15:40:19 -0400

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

[1] 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
**> 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 Goslee http://www.functionaldiversity.org ______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.Received on Fri 27 May 2011 - 19:42:09 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Fri 27 May 2011 - 22:30:10 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*