Calulate residuals from principal component analysis
The following code
 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)
Produces the following output
n1 = 28.460 n2 = 12.201 n3 = 1.6870 n4 = 2.4163e-14
Package: statistics