annotate scripts/statistics/base/skewness.m @ 17583:4cb05034f1c6

skewness.m: Use long-form of 'end' keyword in cset ab75e72c5b36. * scripts/statistics/base/skewness.m: Replace 'end' with 'endif'.
author Rik <rik@octave.org>
date Sun, 06 Oct 2013 19:48:25 -0700
parents 7004c733412f
children 8334144458a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
1 ## Copyright (C) 2013 Julien Bect
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13279
diff changeset
2 ## Copyright (C) 1996-2012 John W. Eaton
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
3 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
5 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
9 ## your option) any later version.
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
10 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
14 ## General Public License for more details.
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
15 ##
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6754
diff changeset
18 ## <http://www.gnu.org/licenses/>.
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
19
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
20 ## -*- texinfo -*-
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
21 ## @deftypefn {Function File} {} skewness (@var{x})
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
22 ## @deftypefnx {Function File} {} skewness (@var{x}, @var{flag})
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
23 ## @deftypefnx {Function File} {} skewness (@var{x}, @var{flag}, @var{dim})
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
24 ## Compute the sample skewness of the elements of @var{x}:
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
25 ## @tex
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
26 ## $$
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
27 ## {\rm skewness} (@var{x}) = {{{1\over N}\,
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
28 ## \sum_{i=1}^N (@var{x}_i - \bar{@var{x}})^3} \over \sigma^3},
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
29 ## $$
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
30 ## where $N$ is the length of @var{x}, $\bar{@var{x}}$ its mean and $\sigma$
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
31 ## its (uncorrected) standard deviation.
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
32 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7411
diff changeset
33 ## @ifnottex
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3367
diff changeset
34 ##
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
35 ## @example
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
36 ## @group
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
37 ## mean ((@var{x} - mean (@var{x})).^3)
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
38 ## skewness (@var{X}) = ------------------------.
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
39 ## std (@var{x}).^3
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
40 ## @end group
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
41 ## @end example
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10669
diff changeset
42 ##
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7411
diff changeset
43 ## @end ifnottex
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3367
diff changeset
44 ##
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
45 ## @noindent
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
46 ## The optional argument @var{flag} controls which normalization is used.
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
47 ## If @var{flag} is equal to 1 (default value, used when @var{flag} is omitted
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
48 ## or empty), return the sample skewness as defined above. If @var{flag} is
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
49 ## equal to 0, return the adjusted skewness coefficient instead:
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
50 ## @tex
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
51 ## $$
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
52 ## {\rm skewness} (@var{x}) = {\sqrt{N (N - 1)} \over N - 2} \times \,
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
53 ## {{{1 \over N} \sum_{i=1}^N (@var{x}_i - \bar{@var{x}})^3} \over \sigma^3}
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
54 ## $$
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
55 ## @end tex
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
56 ## @ifnottex
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
57 ##
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
58 ## @example
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
59 ## @group
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
60 ## sqrt (N*(N-1)) mean ((@var{x} - mean (@var{x})).^3)
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
61 ## skewness (@var{X}, 0) = -------------- * ------------------------.
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
62 ## (N - 2) std (@var{x}).^3
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
63 ## @end group
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
64 ## @end example
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
65 ##
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
66 ## @end ifnottex
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
67 ## The adjusted skewness coefficient is obtained by replacing the sample second
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
68 ## and third central moments by their bias-corrected versions.
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
69 ##
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
70 ## If @var{x} is a matrix, or more generally a multi-dimensional array, return
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
71 ## the skewness along the first non-singleton dimension. If the optional
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
72 ## @var{dim} argument is given, operate along this dimension.
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
73 ##
12575
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
74 ## @seealso{var, kurtosis, moment}
3367
0748b03c3510 [project @ 1999-11-20 14:52:38 by jwe]
jwe
parents: 3200
diff changeset
75 ## @end deftypefn
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
76
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5307
diff changeset
77 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
78 ## Created: 29 July 1994
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
79 ## Adapted-By: jwe
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
80
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
81 function y = skewness (x, flag, dim)
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
82
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
83 if (nargin < 1) || (nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5428
diff changeset
84 print_usage ();
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
85 endif
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
86
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
87 if (! (isnumeric (x) || islogical (x)))
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
88 error ("skewness: X must be a numeric vector or matrix");
10669
cab3b148d4e4 Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
89 endif
cab3b148d4e4 Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
90
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
91 if (nargin < 2 || isempty (flag))
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
92 flag = 1; # default: do not use the "bias corrected" version
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
93 else
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
94 flag = double (flag);
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
95 if (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
96 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
97 endif
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
98 endif
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
99
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
100 nd = ndims (x);
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
101 sz = size (x);
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
102 if (nargin < 3)
4886
54b076a24718 [project @ 2004-04-30 04:31:51 by jwe]
jwe
parents: 4885
diff changeset
103 ## Find the first non-singleton dimension.
12656
6b2f14af2360 Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
104 (dim = find (sz > 1, 1)) || (dim = 1);
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
105 else
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
106 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
107 error ("skewness: DIM must be an integer and a valid dimension");
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
108 endif
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
109 endif
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
110
12656
6b2f14af2360 Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
111 n = sz(dim);
4886
54b076a24718 [project @ 2004-04-30 04:31:51 by jwe]
jwe
parents: 4885
diff changeset
112 sz(dim) = 1;
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
113
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
114 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
115 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
116 y = sum (x .^ 3, dim);
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
117 y ./= (n * s .^ 3);
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
118 y(s == 0) = NaN;
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
119
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
120 ## Apply bias correction to the third central sample moment
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
121 if (flag == 0)
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
122 if (n > 2)
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
123 y *= sqrt (n * (n - 1)) / (n - 2);
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
124 else
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
125 y(:) = NaN;
17583
4cb05034f1c6 skewness.m: Use long-form of 'end' keyword in cset ab75e72c5b36.
Rik <rik@octave.org>
parents: 17582
diff changeset
126 endif
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
127 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
128
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
129 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
130
12656
6b2f14af2360 Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
131
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
132 %!assert (skewness ([-1, 0, 1]), 0)
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
133 %!assert (skewness ([-2, 0, 1]) < 0)
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
134 %!assert (skewness ([-1, 0, 2]) > 0)
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
135 %!assert (skewness ([-3, 0, 1]) == -1 * skewness ([-1, 0, 3]))
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
136 %!assert (skewness (ones (3, 5)), NaN (1, 5))
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
137
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
138 %!test
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
139 %! x = [0; 0; 0; 1];
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
140 %! y = [x, 2*x];
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
141 %! assert (skewness (y), 1.154700538379251 * [1 1], 5*eps);
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
142
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
143 %!assert (skewness ([1:5 10; 1:5 10], 0, 2), 1.439590274527954 * [1; 1], eps)
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
144 %!assert (skewness ([1:5 10; 1:5 10], 1, 2), 1.051328089232020 * [1; 1], eps)
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], [], 2), 1.051328089232020 * [1; 1], eps)
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
146
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
147 ## Test behaviour on single input
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
148 %!assert (skewness (single ([1:5 10])), single (1.0513283), eps ("single"))
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
149 %!assert (skewness (single ([1 2]), 0), single (NaN))
12656
6b2f14af2360 Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
150
17581
ab75e72c5b36 skewness.m: Improve compatibility with Matlab's skewness function
Julien Bect <julien.bect@supelec.fr>
parents: 14363
diff changeset
151 ## Test input validation
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
152 %!error skewness ()
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11401
diff changeset
153 %!error skewness (1, 2, 3)
17582
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
154 %!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
155 %!error <FLAG must be 0 or 1> skewness (1, 2)
7004c733412f skewness.m: Update cset 3ef7d28833f3 to Octave coding conventions.
Rik <rik@octave.org>
parents: 17581
diff changeset
156 %!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
157 %!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
158 %!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
159 %!error <DIM must be .* a valid dimension> skewness (1, [], 3)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
160