>  Docs Center  >  IDL Reference  >  Advanced Math and Stats  >  IMSL_PRINC_COMP

IMSL_PRINC_COMP

IMSL_PRINC_COMP

The IMSL_PRINC_COMP function computes principal components.

This routine requires an IDL Advanced Math and Stats license. For more information, contact your sales or technical support representative.

The IMSL_PRINC_COMP function 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.

Examples


Example 1

In this example, principal components are computed for a nine-variable covariance matrix.

covariances = $
[[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]]
values = IMSL_PRINC_COMP(covariances)
PM, values, Title = 'Eigenvalues:'

Result:

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.

values = IMSL_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)'

IDL prints:

PM, a, Title = 'Matrix A:', FORMAT = '(9f7.2)' 

IDL prints:

PM, [[values], [stdev], [cp]], Title = 'Eigenvalue	STD	PCT', $
  FORMAT = '(3(3x,F5.2))'

IDL prints:

Errors


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.

Syntax


Result = IMSL_PRINC_COMP(Covariances [, /COV_MATRIX] [, /CORR_MATRIX] [, CORRELATIONS=variable] [, CUM_PERCENT=variable] [, DF=variable] [, /DOUBLE] [, EIGENVECTORS=variable] [, STDEV=variable])

Return Value


One-dimensional array containing the eigenvalues of covariances ordered from largest to smallest.

Arguments


covariances

Two-dimensional square matrix containing the covariance or correlation matrix.

Keywords


COV_MATRIX (optional)

If present and nonzero, treats the input matrix covariances as a covariance matrix. The keywords COV_MATRIX and CORR_MATRIX cannot be used together. Default: 1

CORR_MATRIX (optional)

If present and nonzero, treats the input matrix covariances as a correlation matrix. The keywords COV_MATRIX and CORR_MATRIX cannot be used together.

CORRELATIONS (optional)

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.

CUM_PERCENT (optional)

Named variable into which the one-dimensional array containing the cumulative percent of the total variances explained by each principal component is stored.

DF (optional)

Named variable into which the number of degrees of freedom in covariances is stored. The keywords DF and STDEV must be used together.

DOUBLE (optional)

If present and nonzero, double precision is used.

EIGENVECTORS (optional)

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.

STDEV (optional)

Named variable into which the one-dimensional array containing the estimated asymptotic standard errors of the eigenvalues is stored. The keywords DF and STDEV must be used together.

Version History


6.4

Introduced



© 2019 Harris Geospatial Solutions, Inc. |  Legal
My Account    |    Store    |    Contact Us