home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / stat / base / qqplot.m < prev    next >
Text File  |  1999-04-29  |  3KB  |  77 lines

  1. ## Copyright (C) 1995, 1996, 1997  Kurt Hornik
  2. ## 
  3. ## This program is free software; you can redistribute it and/or modify
  4. ## it under the terms of the GNU General Public License as published by
  5. ## the Free Software Foundation; either version 2, or (at your option)
  6. ## any later version.
  7. ## 
  8. ## This program is distributed in the hope that it will be useful, but
  9. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11. ## General Public License for more details. 
  12. ## 
  13. ## You should have received a copy of the GNU General Public License
  14. ## along with this file.  If not, write to the Free Software Foundation,
  15. ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16.  
  17. ## usage:  [q, s] = qqplot (x [, dist [, params]])
  18. ##
  19. ## Performs a QQ-plot (quantile plot).
  20. ##
  21. ## If F is the CDF of the distribution `dist' with parameters `params'
  22. ## and G its inverse, and x a sample vector of length n, the QQ-plot
  23. ## graphs ordinate s(i) = i-th largest element of x versus abscissa q(i)
  24. ## = G((i - 0.5)/n).
  25. ##
  26. ## If the sample comes from F except for a transformation of location
  27. ## and scale, the pairs will approximately follow a straight line.
  28. ##
  29. ## The default for `dist' is the standard normal distribution.  The
  30. ## optional argument `params' contains a list of parameters of
  31. ## `dist'. E.g., for a quantile plot of the uniform distribution on
  32. ## [2,4] and x, use `qqplot (x, "uniform", 2, 4)'.
  33. ##
  34. ## If no output arguments are given, the data are plotted directly.
  35.  
  36. ## Author:  KH <Kurt.Hornik@ci.tuwien.ac.at>
  37. ## Description:  Perform a QQ-plot (quantile plot)
  38.  
  39. function [q, s] = qqplot (x, dist, ...)
  40.   
  41.   if (nargin < 1)
  42.     usage ("qqplot (x [,dist [,params]])");
  43.   endif
  44.   
  45.   if !(is_vec(x))
  46.     error ("qqplot:  x must be a vector.");
  47.   endif
  48.  
  49.   s = sort (x);
  50.   n = length (x);
  51.   t = ((1 : n)' - .5) / n;
  52.   if (nargin == 1)
  53.     f = "stdnorm_inv";
  54.   else
  55.     f = sprintf ("%s_inv", dist);
  56.   endif;
  57.   if (nargin <= 2)
  58.     q = feval (f, t);
  59.     q_label = f;
  60.   else
  61.     param_string = sprintf ("%g", va_arg ());
  62.     for k = 2 : (nargin - 2);
  63.       param_string = sprintf ("%s, %g", param_string, va_arg ())
  64.     endfor
  65.     q = eval (sprintf ("%s (t, %s);", f, param_string));
  66.     q_label = sprintf ("%s with parameter(s) %s", f, param_string);
  67.   endif
  68.   
  69.   if (nargout == 0)
  70.     xlabel (q_label);
  71.     ylabel ("sample points");
  72.     set nokey;
  73.     plot (q, s);
  74.   endif
  75.  
  76. endfunction
  77.