Mercurial > octave-nkf
annotate scripts/statistics/base/kendall.m @ 10793:be55736a0783
Grammarcheck the documentation from m-files.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 18 Jul 2010 20:35:16 -0700 |
parents | f0c3d3fc4903 |
children | 693e22af08ae |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2005, 2006, 2007, 2009 |
7017 | 2 ## Kurt Hornik |
3426 | 3 ## |
3922 | 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. | |
3426 | 10 ## |
3922 | 11 ## Octave is distributed in the hope that it will be useful, but |
3200 | 12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 14 ## General Public License for more details. |
15 ## | |
3200 | 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 |
3453 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} kendall (@var{x}, @var{y}) | |
22 ## Compute Kendall's @var{tau} for each of the variables specified by | |
23 ## the input arguments. | |
3200 | 24 ## |
25 ## For matrices, each row is an observation and each column a variable; | |
26 ## vectors are always observations and may be row or column vectors. | |
27 ## | |
3453 | 28 ## @code{kendall (@var{x})} is equivalent to @code{kendall (@var{x}, |
29 ## @var{x})}. | |
30 ## | |
31 ## For two data vectors @var{x}, @var{y} of common length @var{n}, | |
32 ## Kendall's @var{tau} is the correlation of the signs of all rank | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
33 ## differences of @var{x} and @var{y}; i.e., if both @var{x} and |
3453 | 34 ## @var{y} have distinct entries, then |
3200 | 35 ## |
3453 | 36 ## @tex |
37 ## $$ \tau = {1 \over n(n-1)} \sum_{i,j} {\rm sign}(q_i-q_j) {\rm sign}(r_i-r_j) $$ | |
38 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
39 ## @ifnottex |
3453 | 40 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
41 ## @group |
3453 | 42 ## 1 |
43 ## tau = ------- SUM sign (q(i) - q(j)) * sign (r(i) - r(j)) | |
44 ## n (n-1) i,j | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
45 ## @end group |
3453 | 46 ## @end example |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
47 ## @end ifnottex |
3200 | 48 ## |
3453 | 49 ## @noindent |
50 ## in which the | |
51 ## @tex | |
52 ## $q_i$ and $r_i$ | |
53 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
54 ## @ifnottex |
3453 | 55 ## @var{q}(@var{i}) and @var{r}(@var{i}) |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
56 ## @end ifnottex |
3453 | 57 ## are the ranks of |
58 ## @var{x} and @var{y}, respectively. | |
59 ## | |
60 ## If @var{x} and @var{y} are drawn from independent distributions, | |
61 ## Kendall's @var{tau} is asymptotically normal with mean 0 and variance | |
6754 | 62 ## @tex |
63 ## ${2 (2n+5) \over 9n(n-1)}$. | |
64 ## @end tex | |
65 ## @ifnottex | |
3453 | 66 ## @code{(2 * (2@var{n}+5)) / (9 * @var{n} * (@var{n}-1))}. |
6754 | 67 ## @end ifnottex |
3453 | 68 ## @end deftypefn |
3200 | 69 |
5428 | 70 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456 | 71 ## Description: Kendall's rank correlation tau |
3200 | 72 |
73 function tau = kendall (x, y) | |
3426 | 74 |
3200 | 75 if ((nargin < 1) || (nargin > 2)) |
6046 | 76 print_usage (); |
3200 | 77 endif |
78 | |
79 if (rows (x) == 1) | |
80 x = x'; | |
81 endif | |
82 [n, c] = size (x); | |
83 | |
84 if (nargin == 2) | |
85 if (rows (y) == 1) | |
86 y = y'; | |
87 endif | |
88 if (rows (y) != n) | |
3456 | 89 error ("kendall: x and y must have the same number of observations"); |
3200 | 90 else |
91 x = [x, y]; | |
92 endif | |
93 endif | |
3426 | 94 |
3200 | 95 r = ranks (x); |
96 m = sign (kron (r, ones (n, 1)) - kron (ones (n, 1), r)); | |
97 tau = cor (m); | |
3426 | 98 |
3200 | 99 if (nargin == 2) |
100 tau = tau (1 : c, (c + 1) : columns (x)); | |
101 endif | |
3426 | 102 |
6754 | 103 endfunction |