Mercurial > octave-nkf
annotate scripts/statistics/base/kurtosis.m @ 9051:1bf0ce0930be
Grammar check TexInfo in all .m files
Cleanup documentation sources to follow a few consistent rules.
Spellcheck was NOT done. (but will be in another changeset)
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Fri, 27 Mar 2009 22:31:03 -0700 |
parents | eb63fbe60fab |
children | f0c3d3fc4903 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2004, 2005, 2006, |
8920 | 2 ## 2007, 2008, 2009 John W. Eaton |
3200 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3200 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3200 | 19 |
3367 | 20 ## -*- texinfo -*- |
4885 | 21 ## @deftypefn {Function File} {} kurtosis (@var{x}, @var{dim}) |
3499 | 22 ## If @var{x} is a vector of length @math{N}, return the kurtosis |
3367 | 23 ## @iftex |
24 ## @tex | |
25 ## $$ | |
26 ## {\rm kurtosis} (x) = {1\over N \sigma(x)^4} \sum_{i=1}^N (x_i-\bar{x})^4 - 3 | |
27 ## $$ | |
6754 | 28 ## where $\bar{x}$ is the mean value of $x$. |
3367 | 29 ## @end tex |
30 ## @end iftex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
31 ## @ifnottex |
3426 | 32 ## |
3367 | 33 ## @example |
34 ## kurtosis (x) = N^(-1) std(x)^(-4) sum ((x - mean(x)).^4) - 3 | |
35 ## @end example | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
36 ## @end ifnottex |
3426 | 37 ## |
3367 | 38 ## @noindent |
4885 | 39 ## of @var{x}. If @var{x} is a matrix, return the kurtosis over the |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
40 ## first non-singleton dimension. The optional argument @var{dim} |
4885 | 41 ## can be given to force the kurtosis to be given over that |
42 ## dimension. | |
3367 | 43 ## @end deftypefn |
3200 | 44 |
5428 | 45 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3200 | 46 ## Created: 29 July 1994 |
47 ## Adapted-By: jwe | |
48 | |
4885 | 49 function retval = kurtosis (x, dim) |
3200 | 50 |
4885 | 51 if (nargin != 1 && nargin != 2) |
6046 | 52 print_usage (); |
3200 | 53 endif |
54 | |
4885 | 55 nd = ndims (x); |
56 sz = size (x); | |
57 if (nargin != 2) | |
4886 | 58 ## Find the first non-singleton dimension. |
4885 | 59 dim = 1; |
4886 | 60 while (dim < nd + 1 && sz(dim) == 1) |
4885 | 61 dim = dim + 1; |
62 endwhile | |
63 if (dim > nd) | |
64 dim = 1; | |
3200 | 65 endif |
66 else | |
4886 | 67 if (! (isscalar (dim) && dim == round (dim)) |
68 && dim > 0 | |
69 && dim < (nd + 1)) | |
4885 | 70 error ("kurtosis: dim must be an integer and valid dimension"); |
71 endif | |
72 endif | |
73 | |
74 if (! ismatrix (x)) | |
3458 | 75 error ("kurtosis: x has to be a matrix or a vector"); |
3200 | 76 endif |
77 | |
4886 | 78 c = sz(dim); |
79 sz(dim) = 1; | |
4885 | 80 idx = ones (1, nd); |
4886 | 81 idx(dim) = c; |
4885 | 82 x = x - repmat (mean (x, dim), idx); |
83 retval = zeros (sz); | |
84 s = std (x, [], dim); | |
85 x = sum(x.^4, dim); | |
86 ind = find (s > 0); | |
4886 | 87 retval(ind) = x(ind) ./ (c * s(ind) .^ 4) - 3; |
4885 | 88 |
3200 | 89 endfunction |
7411 | 90 |
91 %!test | |
92 %! x = [-1; 0; 0; 0; 1]; | |
93 %! y = [x, 2*x]; | |
94 %! assert(all (abs (kurtosis (y) - [-1.4, -1.4]) < sqrt (eps))); | |
95 | |
96 %!error kurtosis (); | |
97 | |
98 %!error kurtosis (1, 2, 3); | |
99 |