Function Reference: pcares

statistics: residuals = pcares (x, ndim)
statistics: [residuals, reconstructed] = pcares (x, ndim)

Calculate residuals from principal component analysis.

residuals = pcares (x, ndim) returns the residuals obtained by retaining ndim principal components of the N×D matrix x. Rows of x correspond to observations, columns of x correspond to variables. ndim is a scalar and must be less than or equal to D. residuals is a matrix of the same size as x. Use the data matrix, not the covariance matrix, with this function.

[residuals, reconstructed] = pcares (x, ndim) returns the reconstructed observations, i.e. the approximation to x obtained by retaining its first ndim principal components.

pcares does not normalize the columns of x. Use pcares (zscore (x), ndim) in order to perform the principal components analysis based on standardized variables, i.e. based on correlations. Use pcacov in order to perform principal components analysis directly on a covariance or correlation matrix without constructing residuals.

References

  1. Jolliffe, I. T., Principal Component Analysis, 2nd Edition, Springer, 2002

See also: factoran, pcacov, pca

Source Code: pcares

Example: 1

 

 x = [ 7    26     6    60;
       1    29    15    52;
      11    56     8    20;
      11    31     8    47;
       7    52     6    33;
      11    55     9    22;
       3    71    17     6;
       1    31    22    44;
       2    54    18    22;
      21    47     4    26;
       1    40    23    34;
      11    66     9    12;
      10    68     8    12];

 ## As we increase the number of principal components, the norm
 ## of the residuals matrix will decrease
 r1 = pcares (x,1);
 n1 = norm (r1)
 r2 = pcares (x,2);
 n2 = norm (r2)
 r3 = pcares (x,3);
 n3 = norm (r3)
 r4 = pcares (x,4);
 n4 = norm (r4)

n1 = 28.460
n2 = 12.201
n3 = 1.6870
n4 = 3.3717e-14