Mercurial > hg > octave-lyh
diff scripts/statistics/base/statistics.m @ 12656:6b2f14af2360
Overhaul functions in statistics/base directory.
Widen input validation to accept logicals.
Return correct class of output, e.g., 'single' depending on class of input.
Correct or add tests for above.
* center.m, cov.m, kendall.m, mean.m, meansq.m, median.m, mode.m, prctile.m,
quantile.m, ranks.m, run_count.m, runlength.m, spearman.m, statistics.m,
std.m, var.m, logistic_inv.m: Overhaul as described above
* corrcoef.m: Overhaul + remove input validation already done by cov().
* cor.m, logit.m, ppplot.m, table.m: Only align test blocks.
* gls.m, ols.m: Only correct class of output, no logical inputs for regression.
* histc.m: Only change spacing of code to be uniform.
* iqr.m: Overhaul + 2X speedup by calling empirical_inv just once.
* kurtosis.m: Overhaul + replace repmat instances with center().
* mahalanobis.m: Overhaul + use bsxfun for centering data.
* moment.m: Overhaul + replace repmat instances with center().
* probit.m, range.m: Redo input validation and add tests.
* skewness.m: Overhaul + replace repmat instances with center().
* zscore.m: Overhaul + replace repmat instances with center() + use bsxfun.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 07 May 2011 14:52:08 -0700 |
parents | d0b799dafede |
children | 984359717d71 |
line wrap: on
line diff
--- a/scripts/statistics/base/statistics.m +++ b/scripts/statistics/base/statistics.m @@ -38,7 +38,7 @@ print_usage (); endif - if (!isnumeric(x)) + if (! (isnumeric (x) || islogical (x))) error ("statistics: X must be a numeric vector or matrix"); endif @@ -46,10 +46,7 @@ sz = size (x); if (nargin != 2) ## Find the first non-singleton dimension. - dim = find (sz > 1, 1); - if (isempty (dim)) - dim = 1; - endif + (dim = find (sz > 1, 1)) || (dim = 1); else if (!(isscalar (dim) && dim == round (dim)) || !(1 <= dim && dim <= nd)) @@ -68,16 +65,22 @@ endfunction + %!test -%! x = rand(7,5); +%! x = rand (7,5); %! s = statistics (x); -%! m = median (x); -%! assert (m, s(3,:), eps); +%! assert (min (x), s(1,:), eps); +%! assert (median (x), s(3,:), eps); +%! assert (max (x), s(5,:), eps); +%! assert (mean (x), s(6,:), eps); +%! assert (std (x), s(7,:), eps); +%! assert (skewness (x), s(8,:), eps); +%! assert (kurtosis (x), s(9,:), eps); %% Test input validation %!error statistics () %!error statistics (1, 2, 3) -%!error statistics ([true true]) +%!error statistics (['A'; 'B']) %!error statistics (1, ones(2,2)) %!error statistics (1, 1.5) %!error statistics (1, 0)