Mercurial > octave
annotate scripts/statistics/kurtosis.m @ 31706:597f3ee61a48 stable
update Octave Project Developers copyright for the new year
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 06 Jan 2023 13:11:27 -0500 |
parents | 5d3faba0342e |
children | 2e484f9f1f18 |
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 ## |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30875
diff
changeset
|
3 ## Copyright (C) 1996-2023 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} =} kurtosis (@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} =} kurtosis (@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} =} kurtosis (@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 kurtosis 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 kurtosis is defined as |
3367 | 33 ## @tex |
34 ## $$ | |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
35 ## \kappa_1 = {{{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})^4} \over \sigma^4}, |
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$ |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
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 |
14399
d931d9b458fc
kurtosis.m: Make docstring equation prettier in Info format
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
44 ## @group |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
45 ## mean ((@var{x} - mean (@var{x})).^4) |
17698
9bb5d3f63cdd
NEWS: Announce change in definition of kurtosis function for Matlab compatibility.
Rik <rik@octave.org>
parents:
17697
diff
changeset
|
46 ## k1 = ------------------------ |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
47 ## std (@var{x}).^4 |
14399
d931d9b458fc
kurtosis.m: Make docstring equation prettier in Info format
Rik <octave@nomad.inbox5.com>
parents:
14363
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 |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
52 ## |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
53 ## @noindent |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
54 ## The optional argument @var{flag} controls which normalization is used. |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
55 ## If @var{flag} is equal to 1 (default value, used when @var{flag} is omitted |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
56 ## or empty), return the sample kurtosis as defined above. If @var{flag} is |
17698
9bb5d3f63cdd
NEWS: Announce change in definition of kurtosis function for Matlab compatibility.
Rik <rik@octave.org>
parents:
17697
diff
changeset
|
57 ## equal to 0, return the @w{"bias-corrected"} kurtosis coefficient instead: |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
58 ## @tex |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
59 ## $$ |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
60 ## \kappa_0 = 3 + {\scriptstyle N - 1 \over \scriptstyle (N - 2)(N - 3)} \, |
17698
9bb5d3f63cdd
NEWS: Announce change in definition of kurtosis function for Matlab compatibility.
Rik <rik@octave.org>
parents:
17697
diff
changeset
|
61 ## \left( (N + 1)\, \kappa_1 - 3 (N - 1) \right) |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
62 ## $$ |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
63 ## @end tex |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
64 ## @ifnottex |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
65 ## |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
66 ## @example |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
67 ## @group |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
68 ## N - 1 |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
69 ## k0 = 3 + -------------- * ((N + 1) * k1 - 3 * (N - 1)) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
70 ## (N - 2)(N - 3) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
71 ## @end group |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
72 ## @end example |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
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 ## |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
77 ## @end ifnottex |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
78 ## The bias-corrected kurtosis coefficient is obtained by replacing the sample |
17698
9bb5d3f63cdd
NEWS: Announce change in definition of kurtosis function for Matlab compatibility.
Rik <rik@octave.org>
parents:
17697
diff
changeset
|
79 ## second and fourth central moments by their unbiased versions. It is an |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
80 ## unbiased estimate of the population kurtosis for normal populations. |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
81 ## |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
82 ## If @var{x} is a matrix, or more generally a multi-dimensional array, return |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
83 ## the kurtosis along the first non-singleton dimension. If the optional |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
84 ## @var{dim} argument is given, operate along this dimension. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
85 ## |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
86 ## @seealso{var, skewness, moment} |
3367 | 87 ## @end deftypefn |
3200 | 88 |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
89 function y = kurtosis (x, flag, dim) |
3200 | 90 |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
27985
diff
changeset
|
91 if (nargin < 1) |
6046 | 92 print_usage (); |
3200 | 93 endif |
94 | |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
95 if (! (isnumeric (x) || islogical (x))) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
96 error ("kurtosis: 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
|
97 endif |
cab3b148d4e4
Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
98 |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
99 if (nargin < 2 || isempty (flag)) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
100 flag = 1; # default: do not use the "bias corrected" version |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
101 else |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
102 if (! isscalar (flag) || (flag != 0 && flag != 1)) |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
103 error ("kurtosis: FLAG must be 0 or 1"); |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
104 endif |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
105 endif |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
106 |
4885 | 107 nd = ndims (x); |
108 sz = size (x); | |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
109 if (nargin < 3) |
4886 | 110 ## Find the first non-singleton dimension. |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
111 (dim = find (sz > 1, 1)) || (dim = 1); |
3200 | 112 else |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
21308
diff
changeset
|
113 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
|
114 error ("kurtosis: DIM must be an integer and a valid dimension"); |
4885 | 115 endif |
116 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
117 |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
21308
diff
changeset
|
118 n = size (x, dim); |
4886 | 119 sz(dim) = 1; |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
120 |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
121 x = center (x, dim); # center also promotes integer, logical to double |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
122 v = var (x, 1, dim); # normalize with 1/N |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
123 y = sum (x .^ 4, dim); |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
124 idx = (v != 0); |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
125 y(idx) = y(idx) ./ (n * v(idx) .^ 2); |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
126 y(! idx) = NaN; |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
127 |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
128 ## Apply bias correction to the second and fourth central sample moment |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
129 if (flag == 0) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
130 if (n > 3) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
131 C = (n - 1) / ((n - 2) * (n - 3)); |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
132 y = 3 + C * ((n + 1) * y - 3 * (n - 1)); |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
133 else |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
134 y(:) = NaN; |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
135 endif |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
136 endif |
4885 | 137 |
3200 | 138 endfunction |
7411 | 139 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
140 |
7411 | 141 %!test |
142 %! x = [-1; 0; 0; 0; 1]; | |
143 %! y = [x, 2*x]; | |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
144 %! assert (kurtosis (y), [2.5, 2.5], sqrt (eps)); |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
145 |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
146 %!assert (kurtosis ([-3, 0, 1]) == kurtosis ([-1, 0, 3])) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
147 %!assert (kurtosis (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
|
148 %!assert (kurtosis (1, [], 3), NaN) |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
149 |
30330
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
150 %!assert (kurtosis ([1:5 10; 1:5 10], 0, 2), |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
151 %! 5.4377317925288901 * [1; 1], 8 * eps) |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
152 %!assert (kurtosis ([1:5 10; 1:5 10], 1, 2), |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
153 %! 2.9786509002956195 * [1; 1], 8 * eps) |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
154 %!assert (kurtosis ([1:5 10; 1:5 10], [], 2), |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
155 %! 2.9786509002956195 * [1; 1], 8 * eps) |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
156 |
21308
c53bfd6d8e08
maint: Use American spelling for "behavior".
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
157 ## Test behavior on single input |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
158 %!assert (kurtosis (single ([1:5 10])), single (2.9786513), eps ("single")) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
159 %!assert (kurtosis (single ([1 2]), 0), single (NaN)) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
160 |
26596
cc0d942d0e20
Remove inconsistent warning "Octave:divide-by-zero" (bug #46650).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
26376
diff
changeset
|
161 ## Verify no warnings |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
162 %!test |
20515
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20174
diff
changeset
|
163 %! lastwarn (""); # clear last warning |
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20174
diff
changeset
|
164 %! kurtosis (1); |
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20174
diff
changeset
|
165 %! assert (lastwarn (), ""); |
7411 | 166 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
167 ## 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
|
168 %!error <Invalid call> kurtosis () |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
169 %!error <X must be a numeric vector or matrix> kurtosis (['A'; 'B']) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
170 %!error <FLAG must be 0 or 1> kurtosis (1, 2) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
171 %!error <FLAG must be 0 or 1> kurtosis (1, [1 0]) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
172 %!error <DIM must be an integer> kurtosis (1, [], ones (2,2)) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
173 %!error <DIM must be an integer> kurtosis (1, [], 1.5) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
174 %!error <DIM must be .* a valid dimension> kurtosis (1, [], 0) |