PRINC_COMP Function
Computes principal components.
Usage
result = PRINC_COMP(covariances)
Input Parameters
covariances—Two-dimensional square matrix containing the covariance or correlation matrix.
Returned Value
result—One-dimensional array containing the eigenvalues of covariances ordered from largest to smallest.
Input Keywords
Double—If present and nonzero, double precision is used.
Cov_Matrix—If present and nonzero, treats the input matrix covariances as a covariance matrix. Keywords Cov_Matrix and Corr_Matrix cannot be used together. Default: Cov_Matrix = 1
Corr_Matrix—If present and nonzero, treats the input matrix covariances as a correlation matrix.
Output Keywords
Cum_Percent—Named variable into which the one-dimensional array containing the cumulative percent of the total variances explained by each principal component is stored.
Eigenvectors—Named variable into which the two-dimensional array containing the eigenvectors of covariances, stored columnwise, is stored. Each vector is normalized to have Euclidean length equal to the value 1. Also, the sign of each vector is set so that the largest component in magnitude (the first of the largest if ties exist) is made positive.
Correlations—Named variable into which the one-dimensional array of length containing the correlations of the principal components (the columns) with the observed/standardized variables (the rows) is stored. If Cov_Matrix is present and nonzero, the correlations are with the observed variables; otherwise, the correlations are with the standardized variables (to a variance of 1.0). In the principal component model for factor analysis, matrix Correlations is the matrix of unrotated factor loadings.
Df—Named variable into which the number of degrees of freedom in covariances is stored. Keywords Df and Stdev must be used together.
Stdev—Named variable into which the one-dimensional array containing the estimated asymptotic standard errors of the eigenvalues is stored. Keywords Df and Stdev must be used together.
Discussion
Function PRINC_COMP finds the principal components of a set of variables from a sample covariance or correlation matrix. The characteristic roots, characteristic vectors, standard errors for the characteristic roots, and the correlations of the principal component scores with the original variables are computed. Principal components obtained from correlation matrices are the same as principal components obtained from standardized variables (to unit variance).
The principal component scores are the elements of the vector y = ΓTx, where Γ is the matrix whose columns are the characteristic vectors (eigenvectors) of the sample covariance (or correlation) matrix and x is the vector of observed (or standardized) random variables. The variances of the principal component scores are the characteristic roots (eigenvalues) of the covariance (correlation) matrix.
Asymptotic variances for the characteristic roots were first obtained by Girschick (1939) and are given more recently by Kendall et al. (1983, p. 331). These variances are computed either for covariance matrices or for correlation matrices.
The correlations of the principal components with the observed (or standardized) variables are given in the matrix correlations. When the principal components are obtained from a correlation matrix, Correlations is the same as the matrix of unrotated factor loadings obtained for the principal components model for factor analysis.
Example 1
In this example, principal components are computed for a nine-variable covariance matrix. This example opens a file, cov.dat, and reads in the covariance matrix using the RMF procedure. The file cov.dat contains the following data:
1.0 0.523 0.395 0.471 0.346 0.426 0.576 0.434 0.639
0.523 1.0 0.479 0.506 0.418 0.462 0.547 0.283 0.645
0.395 0.479 1.0 0.355 0.27 0.254 0.452 0.219 0.504
0.471 0.506 0.355 1.0 0.691 0.791 0.443 0.285 0.505
0.346 0.418 0.27 0.691 1.0 0.679 0.383 0.149 0.409
0.426 0.462 0.254 0.791 0.679 1.0 0.372 0.314 0.472
0.576 0.547 0.452 0.443 0.383 0.372 1.0 0.385 0.68
0.434 0.283 0.219 0.285 0.149 0.314 0.385 1.0 0.47
0.639 0.645 0.504 0.505 0.409 0.472 0.68 0.47 1.0
OPENR, unit, 'cov.dat', /Get_Lun
RMF, unit, covariances, 9, 9
CLOSE, unit
values = PRINC_COMP(covariances)
PM, values, Title = 'Eigenvalues:'
; PV-WAVE prints the following:
; Eigenvalues:
; 4.67692
; 1.26397
; 0.844450
; 0.555027
; 0.447076
; 0.429125
; 0.310241
; 0.277006
; 0.196197
Example 2
In this example, principal components are computed for a nine-variable correlation matrix. This example uses the same data as the first example.
OPENR, unit, 'cov.dat', /Get_Lun
RMF, unit, covariances, 9, 9
CLOSE, unit
values = PRINC_COMP(covariances, /Corr_Matrix, $
Eigenvectors = ev, $
Stdev = stdev, $
Df = 100, $
Cum_Percent = cp, $
Correlations = a)
PM, [[values],[ev]], Title = 'Eigenvalue Eigenvector:',$
Format = '(f7.2, 2x, 9f7.2)'
; PV-WAVE prints the following:
; Eigenvalue Eigenvector:
; 4.68 0.35 -0.24 0.14 -0.33 -0.11 0.80 0.17 -0.12 -0.05
; 1.26 0.35 -0.11 -0.28 -0.22 0.77 -0.20 0.14 -0.30 -0.01
; 0.84 0.28 -0.27 -0.56 0.69 -0.15 0.15 0.01 -0.04 -0.10
; 0.56 0.37 0.40 0.04 0.12 0.00 0.12 -0.40 -0.12 0.71
; 0.45 0.31 0.50 -0.07 -0.02 -0.28 -0.18 0.73 0.01 0.00
; 0.43 0.35 0.46 0.18 0.11 0.12 0.07 -0.37 0.09 -0.68
; 0.31 0.35 -0.27 -0.07 -0.35 -0.52 -0.44 -0.29 -0.34 -0.11
; 0.28 0.24 -0.32 0.74 0.43 0.09 -0.20 0.19 -0.16 0.05
; 0.20 0.38 -0.25 -0.01 -0.15 0.05 -0.15 -0.03 0.85 0.12
PM, a, Title = 'Matrix A:', Format = '(9f7.2)'
; PV-WAVE prints the following:
; Matrix A:
; 0.75 -0.26 0.13 -0.25 -0.07 0.52 0.10 -0.07 -0.02
; 0.76 -0.12 -0.26 -0.16 0.51 -0.13 0.08 -0.16 -0.00
; 0.60 -0.30 -0.51 0.52 -0.10 0.10 0.01 -0.02 -0.04
; 0.79 0.45 0.04 0.09 0.00 0.08 -0.22 -0.06 0.31
; 0.68 0.56 -0.07 -0.02 -0.19 -0.12 0.41 0.00 0.00
; 0.75 0.51 0.17 0.08 0.08 0.05 -0.21 0.05 -0.30
; 0.75 -0.31 -0.07 -0.26 -0.35 -0.29 -0.16 -0.18 -0.05
; 0.52 -0.36 0.68 0.32 0.06 -0.13 0.10 -0.09 0.02
; 0.83 -0.28 -0.01 -0.11 0.03 -0.10 -0.01 0.45 0.05
PM, [[values], [stdev], [cp]], Title = 'Eigenvalue STD PCT', $
Format = '(3(3x,F5.2))'
; PV-WAVE prints the following:
; Eigenvalue STD PCT
; 4.68 0.65 0.52
; 1.26 0.18 0.66
; 0.84 0.10 0.75
; 0.56 0.09 0.82
; 0.45 0.09 0.87
; 0.43 0.09 0.91
; 0.31 0.09 0.95
; 0.28 0.10 0.98
; 0.20 0.11 1.00
Warning Errors
STAT_100_DF—Because the number of degrees of freedom in Covariances and Df is less than or equal to zero, 100 degrees of freedom will be used.
STAT_COV_NOT_NONNEG_DEF—Keyword Eigenvectors(#) = #. One or more eigenvalues much less than zero are computed. The matrix Covariances is not nonnegative definite. In order to continue computations of Eigenvectors and Correlations, these eigenvalues are treated as zero.
STAT_FAILED_TO_CONVERGE—Iteration for the eigenvalue failed to converge in 100 iterations before deflating.