Mercurial > octave-nkf
annotate scripts/statistics/base/skewness.m @ 10549:95c3e38098bf
Untabify .m scripts
author | Rik <code@nomad.inbox5.com> |
---|---|
date | Fri, 23 Apr 2010 11:28:50 -0700 |
parents | f0c3d3fc4903 |
children | cab3b148d4e4 |
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} {} skewness (@var{x}, @var{dim}) |
3499 | 22 ## If @var{x} is a vector of length @math{n}, return the skewness |
3367 | 23 ## @tex |
24 ## $$ | |
25 ## {\rm skewness} (x) = {1\over N \sigma(x)^3} \sum_{i=1}^N (x_i-\bar{x})^3 | |
26 ## $$ | |
6754 | 27 ## where $\bar{x}$ is the mean value of $x$. |
3367 | 28 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
29 ## @ifnottex |
3426 | 30 ## |
3367 | 31 ## @example |
32 ## skewness (x) = N^(-1) std(x)^(-3) sum ((x - mean(x)).^3) | |
33 ## @end example | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
34 ## @end ifnottex |
3426 | 35 ## |
3367 | 36 ## @noindent |
4885 | 37 ## of @var{x}. If @var{x} is a matrix, return the skewness along the |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
38 ## first non-singleton dimension of the matrix. If the optional |
4885 | 39 ## @var{dim} argument is given, operate along this dimension. |
3367 | 40 ## @end deftypefn |
3200 | 41 |
5428 | 42 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3200 | 43 ## Created: 29 July 1994 |
44 ## Adapted-By: jwe | |
45 | |
4885 | 46 function retval = skewness (x, dim) |
3200 | 47 |
4885 | 48 if (nargin != 1 && nargin != 2) |
6046 | 49 print_usage (); |
3200 | 50 endif |
51 | |
4885 | 52 nd = ndims (x); |
53 sz = size (x); | |
54 if (nargin != 2) | |
4886 | 55 ## Find the first non-singleton dimension. |
4885 | 56 dim = 1; |
4886 | 57 while (dim < nd + 1 && sz(dim) == 1) |
4885 | 58 dim = dim + 1; |
59 endwhile | |
60 if (dim > nd) | |
61 dim = 1; | |
3200 | 62 endif |
63 else | |
4886 | 64 if (! (isscalar (dim) && dim == round (dim)) |
10549 | 65 && dim > 0 |
66 && dim < (nd + 1)) | |
4885 | 67 error ("skewness: dim must be an integer and valid dimension"); |
68 endif | |
69 endif | |
70 | |
71 if (! ismatrix (x)) | |
3458 | 72 error ("skewness: x has to be a matrix or a vector"); |
3200 | 73 endif |
74 | |
4886 | 75 c = sz(dim); |
4885 | 76 idx = ones (1, nd); |
77 idx (dim) = c; | |
78 x = x - repmat (mean (x, dim), idx); | |
4886 | 79 sz(dim) = 1; |
4885 | 80 retval = zeros (sz); |
81 s = std (x, [], dim); | |
82 ind = find (s > 0); | |
83 x = sum (x .^ 3, dim); | |
4886 | 84 retval(ind) = x(ind) ./ (c * s(ind) .^ 3); |
4885 | 85 |
3200 | 86 endfunction |
7411 | 87 |
88 %!error skewness (); | |
89 | |
90 %!error skewness (1, 2, 3); | |
91 |