Hello,.. Apologies for the newbie question but... I have a matrix R, and I know that *B %*% t(b) = R* *I'm trying to solve for B *(aka. 'factoring the correlation matrix' I think) Please help! I've read that 'to solve for B we define the eigenvalues of R and then apply the techniques of Principal Component Analysis' This made me reach for princomp() but now I'm stuck. I think to understand, that I should be doing this: pc<-princomp(covmat=R, cor=TRUE) This gives me : Standard deviations: Comp.1 Comp.2 Comp.3 1.208492 1.076105 0.617694 But what do I do with that, in order to construct B ?? Thanks for any help anyone can give,... even if it's just a pointer to an example... free beer to anyone who can save me. /Shawn p.s. I read/understand Thursstone_1944 which gives a graphical method of Factoring the Correlation Matrix, which I understand... but surely R provides me a way of determining B? And I know that the answer is encrypted in Harman_1960. p.p.s. Here's my R (in case you're curious and want to help): R<-matrix(c(0.6099, 0.2558, 0.1858, 0.2558, 0.5127, -.1384, 0.1858, -0.1384, 0.9351 ), nrow=3, ncol=3, byrow=TRUE) [[alternative HTML version deleted]]
Hello. I found a solution that may interest others. Recall that my problem was how to use R to decompose a matrix into the product of a matrix and its transpose. or, symbolically: For known matrix M (3x3 matrix) and unknown matrix F and its transpose t(F) where F * t(F) = M determine F The solution using R seems to be : U=eigen(M)$vectors D=diag(x=eigen(M)$values) F=U %*% sqrt(D) But now I have two new questions: 1. How can I find a solution where F is a triangular matrix. 2. How can I find solutions to non-square matrices? /shawn p.s. Here's a numerical example that demonstrates the above. > M [,1] [,2] [,3] [1,] 0.6098601 0.2557882 0.1857773 [2,] 0.2557882 0.5127065 -0.1384238 [3,] 0.1857773 -0.1384238 0.9351089 > U=eigen(M)$vectors > D=diag(x=eigen(M)$values) > F=U %*% sqrt(D) > *F %*% t(F)* [,1] [,2] [,3] [1,] 0.6098601 0.2557882 0.1857773 [2,] 0.2557882 0.5127065 -0.1384238 [3,] 0.1857773 -0.1384238 0.9351089 [[alternative HTML version deleted]]
BTW, The same solution can be found using SVD (Singular Value Decomposition) example, ## Define the matrix that we want to decompose into the product of a matrix and its transform M<-matrix(c(0.6098601, 0.2557882, 0.1857773, 0.2557882, 0.5127065, -0.1384238, 0.1857773, -0.1384238, 0.9351089 ), nrow=3, ncol=3, byrow=TRUE) ## Compute the singular-value decomposition, and construct F from its pieces SVD=svd(M, nu=3, nv=3) U=SVD$u D=diag(SVD$d) V=SVD$v U %*% D %*% t(V) F = U %*% sqrt(diag(SVD$d)) ## Test to see of the product of F with its transpose is equal to M F %*% t(F) # [,1] [,2] [,3] [1,] 0.6098601 0.2557882 0.1857773 [2,] 0.2557882 0.5127065 -0.1384238 [3,] 0.1857773 -0.1384238 0.9351089 /Shawn p.s. HOWEVER I would still like to find a solution that gives me a diagonal matrix for F. For example, I would like this result:, > F [,1] [,2] [,3] [1,] 0.781 0.000 0.000 [2,] 0.328 0.637 0.000 [3,] 0.238 -0.341 0.873 [[alternative HTML version deleted]]
I gave you a solution for the triangular matrix. Can you explain why that is not what you need?> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On > Behalf Of Shawn Koppenhoefer > Sent: Tuesday, April 12, 2011 11:37 AM > To: r-help at r-project.org > Subject: Re: [R] B %*% t(B) = R , then solve for B > Importance: High > > BTW, > The same solution can be found using SVD (Singular Value Decomposition) > > example, > > ## Define the matrix that we want to decompose into the product of a > matrix and its transform > M<-matrix(c(0.6098601, 0.2557882, 0.1857773, > 0.2557882, 0.5127065, -0.1384238, > 0.1857773, -0.1384238, 0.9351089 ), > nrow=3, ncol=3, byrow=TRUE) > > ## Compute the singular-value decomposition, and construct F from its pieces > SVD=svd(M, nu=3, nv=3) > U=SVD$u > D=diag(SVD$d) > V=SVD$v > U %*% D %*% t(V) > F = U %*% sqrt(diag(SVD$d)) > > ## Test to see of the product of F with its transpose is equal to M > F %*% t(F) # > [,1] [,2] [,3] > [1,] 0.6098601 0.2557882 0.1857773 > [2,] 0.2557882 0.5127065 -0.1384238 > [3,] 0.1857773 -0.1384238 0.9351089 > > > /Shawn > > > p.s. > HOWEVER I would still like to find a solution that gives me a diagonal > matrix for F. > For example, I would like this result:, > > > F > [,1] [,2] [,3] > [1,] 0.781 0.000 0.000 > [2,] 0.328 0.637 0.000 > [3,] 0.238 -0.341 0.873 > > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Solution found... Sorry for not having known this,... Apparently, what I was after is called a "Choleski factorization". The solution pops right out of R, as follows: > M<-matrix(c(0.6098601, 0.2557882, 0.1857773, + 0.2557882, 0.5127065, -0.1384238, + 0.1857773, -0.1384238, 0.9351089 ), + nrow=3, ncol=3, byrow=TRUE) > chol(M) [,1] [,2] [,3] [1,] 0.7809354 0.3275408 0.2378907 [2,] 0.0000000 0.6367288 -0.3397722 [3,] 0.0000000 0.0000000 0.8735398 > Thanks again for all your help! /shawn
Correct. In the example I gave you yesterday, I used a different matrix, but showed this solution because it also answered the other question you had about doing it on non-square matrices. Of course, Spencer Graves also gave a very useful answer suggesting QR decomposition. I also gave you the example in the context of linear regression because that is commonly why statisticians will use these factorizations. If your matrix is small, chol() works fine. If your matrix is big and sparse, see Cholesky() in the matrix package (a package that I often refer to as a God-send)> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On > Behalf Of Shawn Koppenhoefer > Sent: Tuesday, April 12, 2011 12:33 PM > To: r-help at r-project.org > Subject: Re: [R] B %*% t(B) = R , then solve for B > Importance: High > > Solution found... > > Sorry for not having known this,... > > Apparently, what I was after is called a "Choleski factorization". > > > The solution pops right out of R, as follows: > > > M<-matrix(c(0.6098601, 0.2557882, 0.1857773, > + 0.2557882, 0.5127065, -0.1384238, > + 0.1857773, -0.1384238, 0.9351089 ), > + nrow=3, ncol=3, byrow=TRUE) > > chol(M) > [,1] [,2] [,3] > [1,] 0.7809354 0.3275408 0.2378907 > [2,] 0.0000000 0.6367288 -0.3397722 > [3,] 0.0000000 0.0000000 0.8735398 > > > > > > Thanks again for all your help! > > > /shawn > > ______________________________________________ > 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.