Mercurial > octave
annotate scripts/statistics/kurtosis.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 1996-2020 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
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26596
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26596
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26596
diff
changeset
|
5 ## |
3200 | 6 ## |
7 ## This file is part of Octave. | |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24512
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
3200 | 10 ## 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
|
11 ## 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
|
12 ## (at your option) any later version. |
3200 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
3200 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
7016 | 20 ## 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
|
21 ## <https://www.gnu.org/licenses/>. |
3200 | 22 |
3367 | 23 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20515
diff
changeset
|
24 ## @deftypefn {} {} kurtosis (@var{x}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20515
diff
changeset
|
25 ## @deftypefnx {} {} kurtosis (@var{x}, @var{flag}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20515
diff
changeset
|
26 ## @deftypefnx {} {} 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
|
27 ## 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
|
28 ## |
d9341b422488
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
29 ## The sample kurtosis is defined as |
3367 | 30 ## @tex |
31 ## $$ | |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
32 ## \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
|
33 ## \sum_{i=1}^N (x_i - \bar{x})^4} \over \sigma^4}, |
3367 | 34 ## $$ |
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
|
35 ## 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
|
36 ## its (uncorrected) standard deviation. |
3367 | 37 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
38 ## @ifnottex |
3426 | 39 ## |
3367 | 40 ## @example |
14399
d931d9b458fc
kurtosis.m: Make docstring equation prettier in Info format
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
41 ## @group |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
42 ## 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
|
43 ## k1 = ------------------------ |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
44 ## std (@var{x}).^4 |
14399
d931d9b458fc
kurtosis.m: Make docstring equation prettier in Info format
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
45 ## @end group |
3367 | 46 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10669
diff
changeset
|
47 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
48 ## @end ifnottex |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
49 ## |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
50 ## @noindent |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
51 ## 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
|
52 ## 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
|
53 ## 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
|
54 ## 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
|
55 ## @tex |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
56 ## $$ |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
57 ## \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
|
58 ## \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
|
59 ## $$ |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
60 ## @end tex |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
61 ## @ifnottex |
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 ## @example |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
64 ## @group |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
65 ## N - 1 |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
66 ## 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
|
67 ## (N - 2)(N - 3) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
68 ## @end group |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
69 ## @end example |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
70 ## |
24985
d85b2485af9e
doc: grammarcheck m-files ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24547
diff
changeset
|
71 ## @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
|
72 ## 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
|
73 ## |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
74 ## @end ifnottex |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
75 ## 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
|
76 ## 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
|
77 ## 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
|
78 ## |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
79 ## 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
|
80 ## 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
|
81 ## @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
|
82 ## |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
83 ## @seealso{var, skewness, moment} |
3367 | 84 ## @end deftypefn |
3200 | 85 |
5428 | 86 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3200 | 87 ## Created: 29 July 1994 |
88 ## Adapted-By: jwe | |
89 | |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
90 function y = kurtosis (x, flag, dim) |
3200 | 91 |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
92 if (nargin < 1) || (nargin > 3) |
6046 | 93 print_usage (); |
3200 | 94 endif |
95 | |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
96 if (! (isnumeric (x) || islogical (x))) |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
97 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
|
98 endif |
cab3b148d4e4
Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
99 |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
100 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
|
101 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
|
102 else |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
103 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
|
104 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
|
105 endif |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
106 endif |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
107 |
4885 | 108 nd = ndims (x); |
109 sz = size (x); | |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
110 if (nargin < 3) |
4886 | 111 ## Find the first non-singleton dimension. |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
112 (dim = find (sz > 1, 1)) || (dim = 1); |
3200 | 113 else |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
21308
diff
changeset
|
114 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
|
115 error ("kurtosis: DIM must be an integer and a valid dimension"); |
4885 | 116 endif |
117 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
118 |
21309
7fbecef105ca
Allow statistics functions to work over non-existent dimension (bug #33523).
Rik <rik@octave.org>
parents:
21308
diff
changeset
|
119 n = size (x, dim); |
4886 | 120 sz(dim) = 1; |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
121 |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 idx = (v != 0); |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
126 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
|
127 y(! idx) = NaN; |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
128 |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
129 ## 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
|
130 if (flag == 0) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
131 if (n > 3) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
132 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
|
133 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
|
134 else |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
135 y(:) = NaN; |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
136 endif |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
137 endif |
4885 | 138 |
3200 | 139 endfunction |
7411 | 140 |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
141 |
7411 | 142 %!test |
143 %! x = [-1; 0; 0; 0; 1]; | |
144 %! 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
|
145 %! 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
|
146 |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
147 %!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
|
148 %!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
|
149 %!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
|
150 |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
151 %!assert (kurtosis ([1:5 10; 1:5 10], 0, 2), 5.4377317925288901 * [1; 1], 8 * eps) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
152 %!assert (kurtosis ([1:5 10; 1:5 10], 1, 2), 2.9786509002956195 * [1; 1], 8 * eps) |
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
153 %!assert (kurtosis ([1:5 10; 1:5 10], [], 2), 2.9786509002956195 * [1; 1], 8 * eps) |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
154 |
21308
c53bfd6d8e08
maint: Use American spelling for "behavior".
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
155 ## 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
|
156 %!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
|
157 %!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
|
158 |
26596
cc0d942d0e20
Remove inconsistent warning "Octave:divide-by-zero" (bug #46650).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
26376
diff
changeset
|
159 ## Verify no warnings |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
160 %!test |
20515
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20174
diff
changeset
|
161 %! lastwarn (""); # clear last warning |
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20174
diff
changeset
|
162 %! kurtosis (1); |
76f67400649e
Use '-local' option to warning to simplify BIST tests.
Rik <rik@octave.org>
parents:
20174
diff
changeset
|
163 %! assert (lastwarn (), ""); |
7411 | 164 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
165 ## Test input validation |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
166 %!error kurtosis () |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
167 %!error kurtosis (1, 2, 3) |
17697
f0e777cf348f
kurtosis.m: Improve compatibility with Matlab's kurtosis function
Julien Bect <julien.bect@supelec.fr>
parents:
14399
diff
changeset
|
168 %!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
|
169 %!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
|
170 %!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
|
171 %!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
|
172 %!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
|
173 %!error <DIM must be .* a valid dimension> kurtosis (1, [], 0) |