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

  1. function plsprs = plspress(av, cv, p, q, w, b, rank)
  2. % PLSPRESS    Calculate PRESS as a function of the number of factors used
  3. %
  4. % Copyright (c) 1989-92 by The MathWorks, Inc.
  5. %
  6. %  plsprs = plspress(av, cv, p, q, w, b, rank)
  7. %
  8. % Where:
  9. %
  10. %  plsprs is the matrix containing press
  11. %  av     is the validation set absorbance matrix
  12. %  cv     is the validation set concentration matrix
  13. %  p      is the matrix of PLS spectral factors
  14. %  q      is the matrix of PLS concentration factors
  15. %  w      is the matrix of PLS weights
  16. %  b      is the vector containing the PLS inner relationships
  17. %  rank   is optional limit to the number of factors tested
  18. %
  19. [i, j] = size(p);
  20. plsprs(i,1)=0;
  21.  
  22. if nargin == 7, i = rank; end
  23.  
  24. for n = 1:i
  25.     x = av';
  26.     c = 0;
  27.     for h=1:n
  28.         t(:,h) = x * w(h,:)';
  29.         x = x - t(:,h) * p(h,:);
  30.         c = c + b(h) * t(:,h) * q(h,:);
  31.     end
  32.     c = c';
  33.     error = c - cv;
  34.        plsprs(n, 1) = sum(sum(error .* error));
  35. end
  36.