Mercurial > octave-nkf
annotate scripts/statistics/base/skewness.m @ 20595:c1a6c31ac29a
eliminate more simple uses of error_state
* ov-classdef.cc: Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Oct 2015 00:20:02 -0400 |
parents | 76f67400649e |
children |
rev | line source |
---|---|
19731
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}) |
20209
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19867
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:
19867
diff
changeset
|
25 ## |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19867
diff
changeset
|
26 ## The sample skewness is defined as |
3367 | 27 ## @tex |
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 | 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 | 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 | 36 ## |
3367 | 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 | 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 | 46 ## |
3367 | 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 | 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 | 77 ## @end deftypefn |
3200 | 78 |
5428 | 79 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3200 | 80 ## Created: 29 July 1994 |
81 ## Adapted-By: jwe | |
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 | 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 | 86 print_usage (); |
3200 | 87 endif |
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 |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
95 else |
19867
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
96 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
|
97 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
|
98 endif |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
99 endif |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
100 |
4885 | 101 nd = ndims (x); |
102 sz = size (x); | |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
103 if (nargin < 3) |
4886 | 104 ## Find the first non-singleton dimension. |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
105 (dim = find (sz > 1, 1)) || (dim = 1); |
3200 | 106 else |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
107 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
|
108 error ("skewness: DIM must be an integer and a valid dimension"); |
4885 | 109 endif |
110 endif | |
111 | |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
112 n = sz(dim); |
4886 | 113 sz(dim) = 1; |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
114 |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 y(! idx) = NaN; |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
121 |
17590
a53a97faf61a
skewness.m: Fix comment
Julien Bect <julien.bect@supelec.fr>
parents:
17587
diff
changeset
|
122 ## 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
|
123 if (flag == 0) |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
124 if (n > 2) |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
125 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
|
126 else |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
127 y(:) = NaN; |
17583
4cb05034f1c6
skewness.m: Use long-form of 'end' keyword in cset ab75e72c5b36.
Rik <rik@octave.org>
parents:
17582
diff
changeset
|
128 endif |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
129 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
130 |
3200 | 131 endfunction |
7411 | 132 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
133 |
17581
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, 1]), 0) |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
135 %!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
|
136 %!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
|
137 %!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
|
138 %!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
|
139 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
140 %!test |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
141 %! x = [0; 0; 0; 1]; |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
142 %! y = [x, 2*x]; |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
143 %! 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
|
144 |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
145 %!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
|
146 %!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
|
147 %!assert (skewness ([1:5 10; 1:5 10], [], 2), 1.051328089232020 * [1; 1], 2*eps) |
7411 | 148 |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
149 ## Test behaviour on single input |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
150 %!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
|
151 %!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
|
152 |
17683
279d4bde41d5
skewness.m: Correct %!test for "divide-by-zero"
Rik <rik@octave.org>
parents:
17605
diff
changeset
|
153 ## 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
|
154 %!test |
20550
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20209
diff
changeset
|
155 %! warning ("on", "Octave:divide-by-zero", "local"); |
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20209
diff
changeset
|
156 %! lastwarn (""); # clear last warning |
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20209
diff
changeset
|
157 %! skewness (1); |
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20209
diff
changeset
|
158 %! 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
|
159 |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
160 ## Test input validation |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
161 %!error skewness () |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
162 %!error skewness (1, 2, 3) |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
163 %!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
|
164 %!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
|
165 %!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
|
166 %!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
|
167 %!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
|
168 %!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
|
169 %!error <DIM must be .* a valid dimension> skewness (1, [], 3) |
20550
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20209
diff
changeset
|
170 |