home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 6.ddi / CHEM.DI$ / PCRCROSS.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.2 KB  |  40 lines

  1. function cross = pcrcross(a, c, vc, maxrank)
  2. % PCRCROSS  Calculate cross-validation for standards.
  3. %
  4. %             PCRCROSS calculates cross-validation for standards
  5. %             as a function of the number of factors used.
  6. %
  7. %  cross = pcrcross(a, c, vc, maxrank)
  8. %
  9. % Where:
  10. %
  11. %  cross    is the matrix containing information on the cross-validation
  12. %  a        is the absorbance matrix
  13. %  c        is the concentration matrix
  14. %  vc       is the matrix containing the eigenvectors (factors)
  15. %  maxrank  is optional limit to the number of factors tested
  16. %
  17. % cross contains the squares of the error for the
  18. % cross-validation on the standard set by leaving out one standard
  19. % at a time and treating it as an unknown.
  20. %
  21.  
  22. % Copyright (c) 1989-92 by The MathWorks, Inc.
  23.  
  24. [i, j] = size(vc);
  25. cross(i,1)=0;
  26.  
  27. if nargin == 4, i = maxrank; end
  28.  
  29. for n = 1:i
  30.    factors = vc(:, 1:n);
  31.    [k, l] = size(a);
  32.    for p = 1:(l - 1);
  33.       proj = factors' * a(:, [1:(p-1), (p+1):l]);
  34.       f = c(:, [1:(p-1), (p+1):l]) * proj' * inv(proj*proj') * factors';
  35.       error = (f * a(:, p)) - c(:, p);
  36.       errorsq(p) = sum(error .* error);
  37.    end
  38.    cross(n) = sum(errorsq);
  39. end
  40.