g_pca(G;S;XX;Z)

Returns a model corresponding to the principal component analysis of one or more variables.

Function type

Vector only

Syntax

g_pca(G;S;XX;Z)

Input

Argument Type Description
G any A space- or comma-separated list of column names

Rows are in the same group if their values for all of the columns listed in G are the same.

If G is omitted, all rows are considered to be in the same group.

If any of the columns listed in G contain N/A, the N/A value is considered a valid grouping value.

S integer The name of a column in which every row evaluates to a 1 or 0, which determines whether or not that row is selected to be included in the calculation

If S is omitted, all rows will be considered by the function (subject to any prior row selections).

If any of the values in S are neither 1 nor 0, an error is returned.

XX integer or decimal A space- or comma-separated list of column names

This denotes the data for the principal component analysis.

Z text A list of pairs of option names and option values specifying the method to be used and/or method-specific parameters (optional)
Z may be:
  • 'method''cov' to compute PCA using the covariance matrix of the data (default)
  • 'method''corr' to compute PCA using the correlation matrix of the data (i.e., to standardize XX into z-scores before doing PCA)

Return Value

For every row in each group defined by G (and for those rows where S=1, if specified), g_pca carries out a principal component analysis for the data in XX and returns a special type representing a model for each group in the data.

The model that g_pca returns can be used as an argument to:
  • param(M;P;I) to extract the eigenvalues and eigenvectors, or
  • score(XX;M;Z) to return the principal components of the data set
Assuming M is the column containing the result of g_pca, use the following function calls to obtain the desired information:
score(XX;M;J)
Jth principal component of XX according to the PCA model M

J must be between 1 and the number of data columns.

param(M;'evals';I)
Ith eigenvalue of the covariance/correlation matrix I from PCA model M

I must be between 1 and the number of data columns.

param(M;'evecs';J I)
Ith element of the Jth eigenvector from PCA model M

I and J must each be between 1 and the number of data columns.

param(M;'valcnt';)
Count of valid observations (those where XX are all non-N/A) used in the analysis
param(M;'center';J)
Mean of the Jth column of XX
param(M;'scale';J)
Standard deviation of the Jth column of XX (if method is corr; returns 1.0 otherwise)