Functions > Data Analysis > Principal Component Analysis > Example: Principal Component Analysis 1
Example: Principal Component Analysis 1
Use the Nipals, loadings, scores, PCAeigenvals and PCAvariance functions to perform Principal Component Analysis (PCA).
The Nipals Function
1. Define a data set where each column stands for one variable.
2. Plot the data set.
In this graph, the x-y plane and the x-z plane are superimposed to expose the trend in the data. The data is in fact an elliptical cloud of points that almost lies on a plane. The three variables are linearly related, and the deviation from a perfect plane is due to noise.
3. Use the rows and cols functions to define the row and column indices.
4. Use the mean function to find the mean of the data and then subtract it from each variable in order to center the data.
5. Plot the centered data.
 • The data is now centered about the origin. This is one of the steps that the Nipals function carries out automatically.• In many applications of PCA, it is also desirable to scale the data so that the variables have equal weights, for example when different variables have different units. Scaling each variable (each column of Data) to unit variance is common, but not appropriate for this data, so no scaling is used here.
6. Use the Nipals function to create a new variable space. Use three principal components, which is the maximum possible since there were only three variables to start with.
The output of the Nipals function is a nested matrix of 6 individual matrices. Use it to find the loadings, scores, eigenvals and eigenvecs of the data. If needed, use the Nipals2 function and the last two matrices to extract additional components.