1## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2005, 2006, 2007
4## This file is part of Octave.
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
8## the Free Software Foundation; either version 3 of the License, or (at
9## your option) any later version.
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.
16## You should have received a copy of the GNU General Public License
17## along with Octave; see the file COPYING. If not, see
18## <http://www.gnu.org/licenses/>.
21## @deftypefn {Function File} {} spearman (@var{x}, @var{y})
22## Compute Spearman's rank correlation coefficient @var{rho} for each of
23## the variables specified by the input arguments.
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.
28## @code{spearman (@var{x})} is equivalent to @code{spearman (@var{x},
31## For two data vectors @var{x} and @var{y}, Spearman's @var{rho} is the
32## correlation of the ranks of @var{x} and @var{y}.
34## If @var{x} and @var{y} are drawn from independent distributions,
35## @var{rho} has zero mean and variance @code{1 / (n - 1)}, and is
36## asymptotically normally distributed.
39## Author: KH <Kurt.Hornik@wu-wien.ac.at>
40## Description: Spearman's rank correlation rho
42function rho = spearman (x, y)
44 if ((nargin < 1) || (nargin > 2))
54 rho = cor (ranks (x));
60 error ("spearman: x and y must have the same number of observations");
62 rho = cor (ranks (x), ranks (y));