Mercurial > octave
annotate scripts/statistics/skewness.m @ 33617:ec2635a02328 bytecode-interpreter tip
maint: Merge default to bytecode-interpreter.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Tue, 21 May 2024 18:29:03 +0200 |
parents | 2e484f9f1f18 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 ## Copyright (C) 1996-2024 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26596
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
3200 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24512
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
3200 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24512
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
3200 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
3200 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24512
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
3200 | 25 |
3367 | 26 ## -*- texinfo -*- |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
27 ## @deftypefn {} {@var{y} =} skewness (@var{x}) |
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
28 ## @deftypefnx {} {@var{y} =} skewness (@var{x}, @var{flag}) |
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
29 ## @deftypefnx {} {@var{y} =} 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
|
30 ## 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
|
31 ## |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
32 ## The sample skewness is defined as |
3367 | 33 ## @tex |
34 ## $$ | |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
35 ## {\rm skewness} (@var{x}) = {{{1\over N}\, |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
36 ## \sum_{i=1}^N (x_i - \bar{x})^3} \over \sigma^3}, |
3367 | 37 ## $$ |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
38 ## where $N$ is the length of @var{x}, $\bar{x}$ its mean and $\sigma$ |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
39 ## its (uncorrected) standard deviation. |
3367 | 40 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
41 ## @ifnottex |
3426 | 42 ## |
3367 | 43 ## @example |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
44 ## @group |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
45 ## 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
|
46 ## skewness (@var{X}) = ------------------------. |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
47 ## std (@var{x}).^3 |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
48 ## @end group |
3367 | 49 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10669
diff
changeset
|
50 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
51 ## @end ifnottex |
3426 | 52 ## |
3367 | 53 ## @noindent |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
54 ## 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
|
55 ## 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
|
56 ## 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
|
57 ## 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
|
58 ## @tex |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
59 ## $$ |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
60 ## {\rm skewness} (@var{x}) = {\sqrt{N (N - 1)} \over N - 2} \times \, |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
61 ## {{{1 \over N} \sum_{i=1}^N (x_i - \bar{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
|
62 ## $$ |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
63 ## @end tex |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
64 ## @ifnottex |
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 ## @example |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
67 ## @group |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
68 ## 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
|
69 ## skewness (@var{X}, 0) = -------------- * ------------------------. |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
70 ## (N - 2) std (@var{x}).^3 |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
71 ## @end group |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
72 ## @end example |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
73 ## |
24985
d85b2485af9e
doc: grammarcheck m-files ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24547
diff
changeset
|
74 ## @noindent |
24511
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
75 ## where @math{N} is the length of the @var{x} vector. |
4f0e6ee6c9b8
Make documentation Sec 26.1 more consistent and Sec 25.4 clearer (bug #52685)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
23219
diff
changeset
|
76 ## |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
77 ## @end ifnottex |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
78 ## 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
|
79 ## 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
|
80 ## |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
81 ## 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
|
82 ## the skewness along the first non-singleton dimension. If the optional |
4885 | 83 ## @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
|
84 ## |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
85 ## @seealso{var, kurtosis, moment} |
3367 | 86 ## @end deftypefn |
3200 | 87 |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
88 function y = skewness (x, flag, dim) |
3200 | 89 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
27985
diff
changeset
|
90 if (nargin < 1) |
6046 | 91 print_usage (); |
3200 | 92 endif |
93 | |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
94 if (! (isnumeric (x) || islogical (x))) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
95 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
|
96 endif |
cab3b148d4e4
Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
97 |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 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
|
102 endif |
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
103 |
4885 | 104 nd = ndims (x); |
105 sz = size (x); | |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
106 if (nargin < 3) |
4886 | 107 ## Find the first non-singleton dimension. |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
108 (dim = find (sz > 1, 1)) || (dim = 1); |
3200 | 109 else |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
21308
diff
changeset
|
110 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
|
111 error ("skewness: DIM must be an integer and a valid dimension"); |
4885 | 112 endif |
113 endif | |
114 | |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
21308
diff
changeset
|
115 n = size (x, dim); |
4886 | 116 sz(dim) = 1; |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
117 |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 y(! idx) = NaN; |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
124 |
17590
a53a97faf61a
skewness.m: Fix comment
Julien Bect <julien.bect@supelec.fr>
parents:
17587
diff
changeset
|
125 ## 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
|
126 if (flag == 0) |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
127 if (n > 2) |
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
128 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
|
129 else |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
130 y(:) = NaN; |
17583
4cb05034f1c6
skewness.m: Use long-form of 'end' keyword in cset ab75e72c5b36.
Rik <rik@octave.org>
parents:
17582
diff
changeset
|
131 endif |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
132 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
133 |
3200 | 134 endfunction |
7411 | 135 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
136 |
17581
ab75e72c5b36
skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
137 %!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
|
138 %!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
|
139 %!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
|
140 %!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
|
141 %!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
|
142 %!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
|
143 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
144 %!test |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
145 %! x = [0; 0; 0; 1]; |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11401
diff
changeset
|
146 %! y = [x, 2*x]; |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
147 %! 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
|
148 |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
149 %!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
|
150 %!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
|
151 %!assert (skewness ([1:5 10; 1:5 10], [], 2), 1.051328089232020 * [1; 1], 2*eps) |
7411 | 152 |
21308
c53bfd6d8e08
maint: Use American spelling for "behavior".
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
153 ## Test behavior on single input |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
154 %!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
|
155 %!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
|
156 |
26596
cc0d942d0e20
Remove inconsistent warning "Octave:divide-by-zero" (bug #46650).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
26376
diff
changeset
|
157 ## Verify no 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
|
158 %!test |
20515
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20174
diff
changeset
|
159 %! lastwarn (""); # clear last warning |
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20174
diff
changeset
|
160 %! skewness (1); |
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20174
diff
changeset
|
161 %! 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
|
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 |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
164 %!error <Invalid call> skewness () |
17582
7004c733412f
skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents:
17581
diff
changeset
|
165 %!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
|
166 %!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
|
167 %!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
|
168 %!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
|
169 %!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
|
170 %!error <DIM must be .* a valid dimension> skewness (1, [], 0) |