Mercurial > hg > octave-nkf
changeset 17714:e243a3a19831
qqplot.m: Accept 2nd vector and use empirical_inv for compatibility w/Matlab (bug #39938).
* scripts/statistics/base/qqplot.m: Update docstring. Rename output variables
so they are not automatically returned unless nargout > 0. When plotting, avoid
TeX markup of '_inv'. Strip anonymous function header from xlabel.
author | Muhali <muhali@shaw.ca> |
---|---|
date | Mon, 21 Oct 2013 12:58:42 -0700 |
parents | ccc0576641f9 |
children | 8dd280b64de1 |
files | scripts/statistics/base/qqplot.m |
diffstat | 1 files changed, 25 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/statistics/base/qqplot.m +++ b/scripts/statistics/base/qqplot.m @@ -18,8 +18,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}) +## @deftypefnx {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{y}) ## @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}) +## @deftypefnx {Function File} {[@var{q}, @var{s}] =} qqplot (@var{x}, @var{y}, @var{params}) ## @deftypefnx {Function File} {} qqplot (@dots{}) ## Perform a QQ-plot (quantile plot). ## @@ -32,6 +33,9 @@ ## If the sample comes from F, except for a transformation of location ## and scale, the pairs will approximately follow a straight line. ## +## If the second argument is a vector @var{y} the empirical CDF of @var{y} +## is used as @var{dist}. +## ## The default for @var{dist} is the standard normal distribution. The ## optional argument @var{params} contains a list of parameters of ## @var{dist}. For example, for a quantile plot of the uniform @@ -52,7 +56,7 @@ ## Author: KH <Kurt.Hornik@wu-wien.ac.at> ## Description: Perform a QQ-plot (quantile plot) -function [q, s] = qqplot (x, dist, varargin) +function [qout, sout] = qqplot (x, dist, varargin) if (nargin < 1) print_usage (); @@ -65,8 +69,10 @@ if (nargin == 1) f = @stdnormal_inv; else - if ( exist (invname = sprintf ("%sinv", dist)) - || exist (invname = sprintf ("%s_inv", dist))) + if (isnumeric (dist)) + f = @(y) empirical_inv (y, dist); + elseif (ischar (dist) && (exist (invname = [dist "inv"]) + || exist (invname = [dist "%s_inv"]))) f = str2func (invname); else error ("qqplot: no inverse CDF found for distribution DIST"); @@ -77,24 +83,32 @@ n = length (x); t = ((1 : n)' - .5) / n; if (nargin <= 2) - q = feval (f, t); + q = f (t); q_label = func2str (f); else - q = feval (f, t, varargin{:}); - if (nargin > 3) - tmp = sprintf (", %g", varargin{2:end}); + q = f (t, varargin{:}); + if (nargin == 3) + q_label = sprintf ("%s with parameter %g", func2str (f), varargin{1}); else - tmp = ""; + q_label = sprintf ("%s with parameters %g", func2str (f), varargin{1}); + param_str = sprintf (", %g", varargin{2:end}); + q_label = [q_label param_str]; endif - q_label = sprintf ("%s with parameter(s) %g%s", - func2str (f), varargin{1}, tmp); endif if (nargout == 0) plot (q, s); + q_label = strrep (q_label, '_inv', '\_inv'); + if (q_label(1) == '@') + q_label = q_label(6:end); # Strip "@(y) " from anon. function + endif xlabel (q_label); ylabel ("sample points"); + else + qout = q; + sout = s; endif endfunction +