Mercurial > octave
annotate scripts/statistics/base/skewness.m @ 19833:9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Try to trim long lines to < 80 chars.
Use '##' for single line comments.
Use '(...)' around tests for if/elseif/switch/while.
Abut cell indexing operator '{' next to variable.
Abut array indexing operator '(' next to variable.
Use space between negation operator '!' and following expression.
Use two newlines between endfunction and start of %!test or %!demo code.
Remove unnecessary parens grouping between short-circuit operators.
Remove stray extra spaces (typos) between variables and assignment operators.
Remove stray extra spaces from ends of lines.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 23 Feb 2015 14:54:39 -0800 |
parents | 4197fc428c7d |
children | d9341b422488 |
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 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3200 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3200 | 19 |
3367 | 20 ## -*- texinfo -*- |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
21 ## @deftypefn {Function File} {} skewness (@var{x}) |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
22 ## @deftypefnx {Function File} {} skewness (@var{x}, @var{flag}) |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
23 ## @deftypefnx {Function File} {} skewness (@var{x}, @var{flag}, @var{dim}) |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
24 ## Compute the sample skewness of the elements of @var{x}: |
3367 | 25 ## @tex |
26 ## $$ | |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
27 ## {\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
|
28 ## \sum_{i=1}^N (@var{x}_i - \bar{@var{x}})^3} \over \sigma^3}, |
3367 | 29 ## $$ |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
30 ## 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
|
31 ## its (uncorrected) standard deviation. |
3367 | 32 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
33 ## @ifnottex |
3426 | 34 ## |
3367 | 35 ## @example |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
36 ## @group |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
37 ## 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
|
38 ## skewness (@var{X}) = ------------------------. |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
39 ## std (@var{x}).^3 |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
40 ## @end group |
3367 | 41 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10669
diff
changeset
|
42 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
43 ## @end ifnottex |
3426 | 44 ## |
3367 | 45 ## @noindent |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
46 ## 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
|
47 ## 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
|
48 ## 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
|
49 ## 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
|
50 ## @tex |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
51 ## $$ |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
52 ## {\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
|
53 ## {{{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
|
54 ## $$ |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
55 ## @end tex |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
56 ## @ifnottex |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
57 ## |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
58 ## @example |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
59 ## @group |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
60 ## 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
|
61 ## skewness (@var{X}, 0) = -------------- * ------------------------. |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
62 ## (N - 2) std (@var{x}).^3 |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
63 ## @end group |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
64 ## @end example |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
65 ## |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
66 ## @end ifnottex |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
67 ## 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
|
68 ## 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
|
69 ## |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
70 ## 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
|
71 ## the skewness along the first non-singleton dimension. If the optional |
4885 | 72 ## @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
|
73 ## |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
74 ## @seealso{var, kurtosis, moment} |
3367 | 75 ## @end deftypefn |
3200 | 76 |
5428 | 77 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3200 | 78 ## Created: 29 July 1994 |
79 ## Adapted-By: jwe | |
80 | |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
81 function y = skewness (x, flag, dim) |
3200 | 82 |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
83 if (nargin < 1) || (nargin > 3) |
6046 | 84 print_usage (); |
3200 | 85 endif |
86 | |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
87 if (! (isnumeric (x) || islogical (x))) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
88 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
|
89 endif |
cab3b148d4e4
Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
90 |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
91 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
|
92 flag = 1; # default: do not use the "bias corrected" version |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
93 else |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
94 if (! isscalar (flag) || (flag != 0 && flag != 1)) |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
95 error ("skewness: FLAG must be 0 or 1"); |
17583
4cb05034f1c6
skewness.m: Use long-form of 'end' keyword in cset ab75e72c5b36.
Rik <rik@octave.org>
parents:
17582
diff
changeset
|
96 endif |
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 | 99 nd = ndims (x); |
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 | 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 | 104 else |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
105 if (!(isscalar (dim) && dim == fix (dim)) || !(1 <= dim && dim <= nd)) |
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 | 107 endif |
108 endif | |
109 | |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
110 n = sz(dim); |
4886 | 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 | 129 endfunction |
7411 | 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)) |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
137 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
138 %!test |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
139 %! x = [0; 0; 0; 1]; |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
140 %! y = [x, 2*x]; |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
141 %! 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
|
142 |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
143 %!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
|
144 %!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
|
145 %!assert (skewness ([1:5 10; 1:5 10], [], 2), 1.051328089232020 * [1; 1], 2*eps) |
7411 | 146 |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
147 ## Test behaviour on single input |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
148 %!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
|
149 %!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
|
150 |
17683
279d4bde41d5
skewness.m: Correct %!test for "divide-by-zero"
Rik <rik@octave.org>
parents:
17605
diff
changeset
|
151 ## 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
|
152 %!test |
17605
8f2f8c9b2620
skewness.m: Backout cset a13ff4521538 until fix for bug #40199 is found.
Rik <rik@octave.org>
parents:
17590
diff
changeset
|
153 %! wstate = warning ("query", "Octave:divide-by-zero"); |
17683
279d4bde41d5
skewness.m: Correct %!test for "divide-by-zero"
Rik <rik@octave.org>
parents:
17605
diff
changeset
|
154 %! warning ("on", "Octave:divide-by-zero"); |
17605
8f2f8c9b2620
skewness.m: Backout cset a13ff4521538 until fix for bug #40199 is found.
Rik <rik@octave.org>
parents:
17590
diff
changeset
|
155 %! unwind_protect |
8f2f8c9b2620
skewness.m: Backout cset a13ff4521538 until fix for bug #40199 is found.
Rik <rik@octave.org>
parents:
17590
diff
changeset
|
156 %! lastwarn (""); # clear last warning |
8f2f8c9b2620
skewness.m: Backout cset a13ff4521538 until fix for bug #40199 is found.
Rik <rik@octave.org>
parents:
17590
diff
changeset
|
157 %! skewness (1); |
8f2f8c9b2620
skewness.m: Backout cset a13ff4521538 until fix for bug #40199 is found.
Rik <rik@octave.org>
parents:
17590
diff
changeset
|
158 %! assert (lastwarn (), ""); |
8f2f8c9b2620
skewness.m: Backout cset a13ff4521538 until fix for bug #40199 is found.
Rik <rik@octave.org>
parents:
17590
diff
changeset
|
159 %! unwind_protect_cleanup |
8f2f8c9b2620
skewness.m: Backout cset a13ff4521538 until fix for bug #40199 is found.
Rik <rik@octave.org>
parents:
17590
diff
changeset
|
160 %! warning (wstate, "Octave:divide-by-zero"); |
8f2f8c9b2620
skewness.m: Backout cset a13ff4521538 until fix for bug #40199 is found.
Rik <rik@octave.org>
parents:
17590
diff
changeset
|
161 %! end_unwind_protect |
17586
8334144458a4
skewness.m: Fix "division by zero" warnings. Improve input validation for FLAG.
Julien Bect <julien.bect@supelec.fr>
parents:
17583
diff
changeset
|
162 |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
163 ## Test input validation |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
164 %!error skewness () |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
165 %!error skewness (1, 2, 3) |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
166 %!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
|
167 %!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
|
168 %!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
|
169 %!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
|
170 %!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
|
171 %!error <DIM must be .* a valid dimension> skewness (1, [], 0) |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
172 %!error <DIM must be .* a valid dimension> skewness (1, [], 3) |