annotate scripts/statistics/base/skewness.m @ 21309:7fbecef105ca

Allow statistics functions to work over non-existent dimension (bug #33523). * var.m, center.m, kurtosis.m, mean.m, meansq.m, median.m, moment.m, skewness.m, std.m: Remove check for input dimension being within the range of ndims (x). Add BIST tests for new behavior and update input validation tests.
author Rik <rik@octave.org>
date Fri, 19 Feb 2016 21:27:03 -0800
parents c53bfd6d8e08
children bac0d6f07a3e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
1 ## Copyright (C) 2013-2015 Julien Bect
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
2 ## Copyright (C) 1996-2015 John W. Eaton
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
3 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
5 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
9 ## your option) any later version.
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
10 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
14 ## General Public License for more details.
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
15 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
18 ## <http://www.gnu.org/licenses/>.
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
19
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
20 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20515
diff changeset
21 ## @deftypefn {} {} skewness (@var{x})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20515
diff changeset
22 ## @deftypefnx {} {} skewness (@var{x}, @var{flag})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20515
diff changeset
23 ## @deftypefnx {} {} skewness (@var{x}, @var{flag}, @var{dim})
20174
d9341b422488 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
24 ## Compute the sample skewness of the elements of @var{x}.
d9341b422488 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
25 ##
d9341b422488 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
26 ## The sample skewness is defined as
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
27 ## @tex
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
28 ## $$
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
29 ## {\rm skewness} (@var{x}) = {{{1\over N}\,
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
30 ## \sum_{i=1}^N (@var{x}_i - \bar{@var{x}})^3} \over \sigma^3},
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
31 ## $$
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
32 ## where $N$ is the length of @var{x}, $\bar{@var{x}}$ its mean and $\sigma$
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
33 ## its (uncorrected) standard deviation.
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
34 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7411
diff changeset
35 ## @ifnottex
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3367
diff changeset
36 ##
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
37 ## @example
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
38 ## @group
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
39 ## mean ((@var{x} - mean (@var{x})).^3)
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
40 ## skewness (@var{X}) = ------------------------.
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
41 ## std (@var{x}).^3
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
42 ## @end group
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
43 ## @end example
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10669
diff changeset
44 ##
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7411
diff changeset
45 ## @end ifnottex
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3367
diff changeset
46 ##
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
47 ## @noindent
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
48 ## The optional argument @var{flag} controls which normalization is used.
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
49 ## If @var{flag} is equal to 1 (default value, used when @var{flag} is omitted
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
50 ## or empty), return the sample skewness as defined above. If @var{flag} is
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
51 ## equal to 0, return the adjusted skewness coefficient instead:
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
52 ## @tex
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
53 ## $$
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
54 ## {\rm skewness} (@var{x}) = {\sqrt{N (N - 1)} \over N - 2} \times \,
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
55 ## {{{1 \over N} \sum_{i=1}^N (@var{x}_i - \bar{@var{x}})^3} \over \sigma^3}
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
56 ## $$
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
57 ## @end tex
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
58 ## @ifnottex
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
59 ##
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
60 ## @example
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
61 ## @group
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
62 ## sqrt (N*(N-1)) mean ((@var{x} - mean (@var{x})).^3)
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
63 ## skewness (@var{X}, 0) = -------------- * ------------------------.
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
64 ## (N - 2) std (@var{x}).^3
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
65 ## @end group
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
66 ## @end example
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
67 ##
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
68 ## @end ifnottex
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
69 ## The adjusted skewness coefficient is obtained by replacing the sample second
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
70 ## and third central moments by their bias-corrected versions.
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
71 ##
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
72 ## If @var{x} is a matrix, or more generally a multi-dimensional array, return
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
73 ## the skewness along the first non-singleton dimension. If the optional
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
74 ## @var{dim} argument is given, operate along this dimension.
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
75 ##
12575
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
76 ## @seealso{var, kurtosis, moment}
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
77 ## @end deftypefn
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
78
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5307
diff changeset
79 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
80 ## Created: 29 July 1994
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
81 ## Adapted-By: jwe
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
82
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
83 function y = skewness (x, flag, dim)
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
84
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
85 if (nargin < 1) || (nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5428
diff changeset
86 print_usage ();
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
87 endif
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
88
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
89 if (! (isnumeric (x) || islogical (x)))
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
90 error ("skewness: X must be a numeric vector or matrix");
10669
cab3b148d4e4 Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
91 endif
cab3b148d4e4 Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
92
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
93 if (nargin < 2 || isempty (flag))
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
94 flag = 1; # default: do not use the "bias corrected" version
21309
7fbecef105ca Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents: 21308
diff changeset
95 elseif (! isscalar (flag) || (flag != 0 && flag != 1))
7fbecef105ca Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents: 21308
diff changeset
96 error ("skewness: FLAG must be 0 or 1");
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
97 endif
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
98
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
99 nd = ndims (x);
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
100 sz = size (x);
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
101 if (nargin < 3)
4886
54b076a24718 [project @ 2004-04-30 04:31:51 by jwe]
jwe
parents: 4885
diff changeset
102 ## Find the first non-singleton dimension.
12656
6b2f14af2360 Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
103 (dim = find (sz > 1, 1)) || (dim = 1);
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
104 else
21309
7fbecef105ca Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents: 21308
diff changeset
105 if (! (isscalar (dim) && dim == fix (dim) && dim > 0))
10669
cab3b148d4e4 Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
106 error ("skewness: DIM must be an integer and a valid dimension");
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
107 endif
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
108 endif
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
109
21309
7fbecef105ca Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents: 21308
diff changeset
110 n = size (x, dim);
4886
54b076a24718 [project @ 2004-04-30 04:31:51 by jwe]
jwe
parents: 4885
diff changeset
111 sz(dim) = 1;
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
112
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
113 x = center (x, dim); # center also promotes integer, logical to double
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
114 s = std (x, 1, dim); # Normalize with 1/N
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
115 y = sum (x .^ 3, dim);
17586
8334144458a4 skewness.m: Fix "division by zero" warnings. Improve input validation for FLAG.
Julien Bect <julien.bect@supelec.fr>
parents: 17583
diff changeset
116 idx = (s != 0);
8334144458a4 skewness.m: Fix "division by zero" warnings. Improve input validation for FLAG.
Julien Bect <julien.bect@supelec.fr>
parents: 17583
diff changeset
117 y(idx) ./= (n * s(idx) .^ 3);
8334144458a4 skewness.m: Fix "division by zero" warnings. Improve input validation for FLAG.
Julien Bect <julien.bect@supelec.fr>
parents: 17583
diff changeset
118 y(! idx) = NaN;
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
119
17590
a53a97faf61a skewness.m: Fix comment
Julien Bect <julien.bect@supelec.fr>
parents: 17587
diff changeset
120 ## Apply bias correction to the second and third central sample moment
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
121 if (flag == 0)
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
122 if (n > 2)
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
123 y *= sqrt (n * (n - 1)) / (n - 2);
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
124 else
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
125 y(:) = NaN;
17583
4cb05034f1c6 skewness.m: Use long-form of 'end' keyword in cset ab75e72c5b36.
Rik <rik@octave.org>
parents: 17582
diff changeset
126 endif
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
127 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
128
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
129 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
130
12656
6b2f14af2360 Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
131
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
132 %!assert (skewness ([-1, 0, 1]), 0)
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
133 %!assert (skewness ([-2, 0, 1]) < 0)
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
134 %!assert (skewness ([-1, 0, 2]) > 0)
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
135 %!assert (skewness ([-3, 0, 1]) == -1 * skewness ([-1, 0, 3]))
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
136 %!assert (skewness (ones (3, 5)), NaN (1, 5))
21309
7fbecef105ca Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents: 21308
diff changeset
137 %!assert (skewness (1, [], 3), NaN)
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
138
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
139 %!test
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
140 %! x = [0; 0; 0; 1];
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
141 %! y = [x, 2*x];
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
142 %! assert (skewness (y), 1.154700538379251 * [1 1], 5*eps);
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
143
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
144 %!assert (skewness ([1:5 10; 1:5 10], 0, 2), 1.439590274527954 * [1; 1], eps)
17586
8334144458a4 skewness.m: Fix "division by zero" warnings. Improve input validation for FLAG.
Julien Bect <julien.bect@supelec.fr>
parents: 17583
diff changeset
145 %!assert (skewness ([1:5 10; 1:5 10], 1, 2), 1.051328089232020 * [1; 1], 2*eps)
8334144458a4 skewness.m: Fix "division by zero" warnings. Improve input validation for FLAG.
Julien Bect <julien.bect@supelec.fr>
parents: 17583
diff changeset
146 %!assert (skewness ([1:5 10; 1:5 10], [], 2), 1.051328089232020 * [1; 1], 2*eps)
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
147
21308
c53bfd6d8e08 maint: Use American spelling for "behavior".
Rik <rik@octave.org>
parents: 20852
diff changeset
148 ## Test behavior on single input
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
149 %!assert (skewness (single ([1:5 10])), single (1.0513283), eps ("single"))
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
150 %!assert (skewness (single ([1 2]), 0), single (NaN))
12656
6b2f14af2360 Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
151
17683
279d4bde41d5 skewness.m: Correct %!test for "divide-by-zero"
Rik <rik@octave.org>
parents: 17605
diff changeset
152 ## Verify no "divide-by-zero" warnings
17586
8334144458a4 skewness.m: Fix "division by zero" warnings. Improve input validation for FLAG.
Julien Bect <julien.bect@supelec.fr>
parents: 17583
diff changeset
153 %!test
20515
76f67400649e Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents: 20174
diff changeset
154 %! warning ("on", "Octave:divide-by-zero", "local");
76f67400649e Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents: 20174
diff changeset
155 %! lastwarn (""); # clear last warning
76f67400649e Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents: 20174
diff changeset
156 %! skewness (1);
76f67400649e Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents: 20174
diff changeset
157 %! assert (lastwarn (), "");
17586
8334144458a4 skewness.m: Fix "division by zero" warnings. Improve input validation for FLAG.
Julien Bect <julien.bect@supelec.fr>
parents: 17583
diff changeset
158
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
159 ## Test input validation
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
160 %!error skewness ()
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
161 %!error skewness (1, 2, 3)
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
162 %!error <X must be a numeric vector or matrix> skewness (['A'; 'B'])
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
163 %!error <FLAG must be 0 or 1> skewness (1, 2)
17586
8334144458a4 skewness.m: Fix "division by zero" warnings. Improve input validation for FLAG.
Julien Bect <julien.bect@supelec.fr>
parents: 17583
diff changeset
164 %!error <FLAG must be 0 or 1> skewness (1, [1 0])
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
165 %!error <DIM must be an integer> skewness (1, [], ones (2,2))
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
166 %!error <DIM must be an integer> skewness (1, [], 1.5)
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
167 %!error <DIM must be .* a valid dimension> skewness (1, [], 0)
20515
76f67400649e Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents: 20174
diff changeset
168