Variance Captured for Individual Variables in PCA

The function varcap.m calculates the percent variance of each original variable in a PCA model and outputs the results graphically and to the workspace. The figure below shows an example of the graphical output. Here the function was used on a 5 PC model of the NIR spectra in the nir_data.mat file in the PLS_Toolbox. The PCA model was built on mean centered spectra. The function varcap was called from the command line:

>>vc = varcap(mcx,loads,lamda);

where mcx was the mean centered spectra, loads are the loadings vectors from a PCA model and lamda was the axis for plotting against, in this case the wavelength. The output is the matrix of variance captured vc and the plot below. The plot shows the cumulative amount of variance captured for each variable, with each PC shown as a different color. It can be seen, for instance, that the model captures almost all of the variation in the data in the 1200-1300 nm range, but less than half around 880 nm. The second PC (light blue) is very important for describing variation at ~1220 nm, while the fifth PC (reddish brown) mostly describes variance around 880 nm.

Requirements for running varcap

  • MATLAB 5.0
  • No other toolboxes required

Developed by:

Barry M. Wise
Eigenvector Research, Inc.
bmw@eigenvector.com

Download varcap.m

To get it, simply click on varcap.m for Mac, or varcap.m for PC. Move the file to a folder on your MATLAB path and you're done.

Return to MATLAB User Area.