Principal component analysis by several decomposition

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Principal component analysis by several decomposition

onewayenzyme
Hello,
   I am coping with PCA obtained after several matrix decomposition of a
data matrix containing biological information (for sake of completeness,
matrix of metabolites and samples). I have a few of doubts about the
procedure and results, then I will be greatfull to everyone who will address
some (or all) of my issues.

1. Be X a m x n data matrix (n are variables/metabolites, m
observables/samples), n is much greater than m;
2. I applied a scaling by Xm=zscore(X);
3. performed svd by [U S W]=svd(Xm);

Assuming that W contains the principal components (PCs) of Xm (is it right,
or I have to compute W'*Xm' to get them?), I can plot PCs one by one for
each sample obtaining a biplot; now, how can I get the coefficients
associated to each variables for each PCs?

In addition, it seems that a more ready procedure is to compute pca by
"princomp":

[coeff,score,latent]=princomp(Xm)

and in that case the coefficients are within the "coeff" matrix, but where
are the PCs stored? Are they in "score"?

Again, by computing PCs by eigenval decomposition:

[V,D]=eig(cov(Xm));

I will get the reconstructed V'*Xm' matrix which contains the PCs, but where
are the coefficients?



Thank you in advance




--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Principal component analysis by several decomposition

Andreas Stahel
onewayenzyme wrote

> Hello,
>    I am coping with PCA obtained after several matrix decomposition of a
> data matrix containing biological information (for sake of completeness,
> matrix of metabolites and samples). I have a few of doubts about the
> procedure and results, then I will be greatfull to everyone who will
> address
> some (or all) of my issues.
>
> 1. Be X a m x n data matrix (n are variables/metabolites, m
> observables/samples), n is much greater than m;
> 2. I applied a scaling by Xm=zscore(X);
> 3. performed svd by [U S W]=svd(Xm);
>
> Assuming that W contains the principal components (PCs) of Xm (is it
> right,
> or I have to compute W'*Xm' to get them?), I can plot PCs one by one for
> each sample obtaining a biplot; now, how can I get the coefficients
> associated to each variables for each PCs?
>
> In addition, it seems that a more ready procedure is to compute pca by
> "princomp":
>
> [coeff,score,latent]=princomp(Xm)
>
> and in that case the coefficients are within the "coeff" matrix, but where
> are the PCs stored? Are they in "score"?
>
> Again, by computing PCs by eigenval decomposition:
>
> [V,D]=eig(cov(Xm));
>
> I will get the reconstructed V'*Xm' matrix which contains the PCs, but
> where
> are the coefficients?
>
>
>
> Thank you in advance
>
>
>
>
> --
> Sent from:
> https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

Have a look at the source of  pcacov will most likely help you to answer
your questions.
Look for the file pcacov.m on your disk, it is part of the statistics
package

function [COEFF, latent, explained] = pcacov(X)
  [U,S,V] = svd(X);
  if nargout == 1
    COEFF     = U;
  elseif nargout == 2
    COEFF     = U;
    latent    = diag(S);
  else
    COEFF     = U;
    latent    = diag(S);
    explained = 100*latent./sum(latent);
  end
endfunction






--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Principal component analysis by several decomposition

onewayenzyme
Thank you for your reply.

My major issue now is:

by eigendecomposition of the covariance matrix, says Xm in my example, I
obtain PCs from

W=V'*Xm' (ordering the eigenvectors in V according to eigenvalues);

however according to svd

[U S T]=svd(Xm);
PC=T';

but W does not match with the PCs obtained after SVD.

Which are the relationships among the matrices obatined by
eigendecomposition and SVD? In particular how can I get the same PCs and
coefficients from the two decomposition in such a way thay are equal?

 





--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Principal component analysis by several decomposition

Andreas Stahel
onewayenzyme wrote

> Thank you for your reply.
>
> My major issue now is:
>
> by eigendecomposition of the covariance matrix, says Xm in my example, I
> obtain PCs from
>
> W=V'*Xm' (ordering the eigenvectors in V according to eigenvalues);
>
> however according to svd
>
> [U S T]=svd(Xm);
> PC=T';
>
> but W does not match with the PCs obtained after SVD.
>
> Which are the relationships among the matrices obatined by
> eigendecomposition and SVD? In particular how can I get the same PCs and
> coefficients from the two decomposition in such a way thay are equal?
>
>  
>
>
>
>
>
> --
> Sent from:
> https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

For symmetric matrices there is a simple relation between eigenvectors and
the SVD, and it applies in the context of PCA.
Have a look at the draft of my lecture notes at
https://web.sha1.bfh.science/NumMethods/NumMethods.pdf
Find the connection between eigenvectors and SVD on page 149.
On pages 151-161 the path from Gaussian distributions to eigenvalues to PCA,
incuding SVD, is spelled out.

I hope it helps

Andreas




--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html