1 feb. 2015

Comparing PRCOMP and SVD for the eigenvalues calculation


PRCOMP calculates the Standard Deviation with the standard divisor (N-1), so in the output value “sdev”, we get the standard deviation of the column of the score matrix (n.a).

For example:
head(X1_prcomp$sdev)
3.21983981   0.54314465     0.41112799      0.08351649     
0.06957348     0.02994683

The square of this values are the variances
head(X1_prcomp$sdev^2)
1.036737e+01   2.950061e-01    1.690262e-01    6.975004e-03    
4.840470e-03  8.968124e-04

Using SVD, we get an output value “d”, with the square root of the eigenvalues. Using the same data:
head(X1_svd_d)
39.9571612  6.7402479  5.1019641  1.0364124  0.8633842  0.3716303

The square of these value are the “eigenvalues”:
head(X1_svd_d^2)
1596.5747310   45.4309414   26.0300382    1.0741506    0.7454323    0.1381091

In order to get the “eigenvalues” for the PRCOMP, we have to consider that they are divided by (N-1). In our case we have 155 samples, so (N-1) = 154.
head(X1_prcomp$sdev^2*(154))
1596.5747310   45.4309414   26.0300382    1.0741506    0.7454323    0.1381091

To see the % of explained variance we can use the value of each eigenvalue divided the sum of all of them
head(X1_svd_d^2/sum(X1_svd_d^2)*100)
95.59      2.72      1.559    0.064     0.045     

This information is provided  with the summary in PRCOMP:
summary(X1_prcomp)

Importance of components:
                             PC1        PC2       PC3       PC4       PC5 
Standard deviation          3.2198    0.5431    0.41113   0.08352   0.06957
Proportion of Variance      0.9559    0.0272    0.01559   0.00064   0.00045
Cumulative Proportion       0.9559    0.9831    0.99873   0.99937   0.99982

No hay comentarios:

Publicar un comentario