Mercurial > hg > octave-lyh
diff scripts/statistics/base/qqplot.m @ 11436:e151e23f73bc
Overhaul base statistics functions and documentation of same.
Add or improve input validation.
Add input validation tests.
Add functional tests.
Improve or re-write documentation strings.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 03 Jan 2011 21:23:08 -0800 |
parents | 95c3e38098bf |
children | fd0a3ac60b0e |
line wrap: on
line diff
--- a/scripts/statistics/base/qqplot.m +++ b/scripts/statistics/base/qqplot.m @@ -18,7 +18,9 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{dist}, @var{params}) +## @deftypefn {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}) +## @deftypefnx {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{dist}) +## @deftypefnx {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{dist}, @var{params}) ## Perform a QQ-plot (quantile plot). ## ## If F is the CDF of the distribution @var{dist} with parameters @@ -27,7 +29,7 @@ ## largest element of x versus abscissa @var{q}(@var{i}f) = G((@var{i} - ## 0.5)/@var{n}). ## -## If the sample comes from F except for a transformation of location +## If the sample comes from F, except for a transformation of location ## and scale, the pairs will approximately follow a straight line. ## ## The default for @var{dist} is the standard normal distribution. The @@ -40,8 +42,9 @@ ## @end example ## ## @noindent -## @var{dist} can be any string for which a function @var{dist_inv} -## that calculates the inverse CDF of distribution @var{dist} exists. +## @var{dist} can be any string for which a function @var{distinv} or +## @var{dist_inv} exists that calculates the inverse CDF of distribution +## @var{dist}. ## ## If no output arguments are given, the data are plotted directly. ## @end deftypefn @@ -55,18 +58,24 @@ print_usage (); endif - if (! (isvector(x))) - error ("qqplot: x must be a vector"); + if (!(isnumeric (x) && isvector(x))) + error ("qqplot: X must be a numeric vector"); endif + if (nargin == 1) + f = @stdnormal_inv; + else + if ( exist (invname = sprintf ("%sinv", dist)) + || exist (invname = sprintf ("%s_inv", dist))) + f = str2func (invname); + else + error ("qqplot: no inverse CDF found for distribution DIST"); + endif + endif; + s = sort (x); n = length (x); t = ((1 : n)' - .5) / n; - if (nargin == 1) - f = @stdnormal_inv; - else - f = str2func (sprintf ("%s_inv", dist)); - endif; if (nargin <= 2) q = feval (f, t); q_label = func2str (f); @@ -77,8 +86,8 @@ else tmp = ""; endif - q_label = sprintf ("%s with parameter(s) %g%s", func2str (f), - varargin{1}, tmp); + q_label = sprintf ("%s with parameter(s) %g%s", + func2str (f), varargin{1}, tmp); endif if (nargout == 0)