Mercurial > hg > octave-lyh
annotate scripts/deprecated/cor.m @ 12856:cad4cba03f19
Deprecate corrcoef, cor and replace with Matlab equivalent corr
The value calculated by Octave's corrcoef and cor are the
same as the value calculated by the Matlab function corr.
Use MathWorks naming convention for this functionality.
* corr.m: New file with functionality of corrcoef.m
* cov.m, kendall.m, spearman.m, cor_test.m: Adjust scripts to call corr()
* statistics/base/module.mk, deprecated/module.mk: Inform Automake about
deprecated functions
* NEWS: Inform users about deprecation
* stats.txi: Add corr() to documentation.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 16 Jul 2011 20:38:00 -0700 |
parents | scripts/statistics/base/cor.m@6b2f14af2360 |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 Kurt Hornik |
3426 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3200 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3200 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3200 | 18 |
3453 | 19 ## -*- texinfo -*- |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
20 ## @deftypefn {Function File} {} cor (@var{x}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
21 ## @deftypefnx {Function File} {} cor (@var{x}, @var{y}) |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
22 ## Compute matrix of correlation coefficients. |
3200 | 23 ## |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
24 ## This is an alias for @code{corrcoef}. |
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
25 ## @seealso{corrcoef} |
3453 | 26 ## @end deftypefn |
3200 | 27 |
12555
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
28 function retval = cor (x, y = x) |
3200 | 29 |
12856
cad4cba03f19
Deprecate corrcoef, cor and replace with Matlab equivalent corr
Rik <octave@nomad.inbox5.com>
parents:
12656
diff
changeset
|
30 persistent warned = false; |
cad4cba03f19
Deprecate corrcoef, cor and replace with Matlab equivalent corr
Rik <octave@nomad.inbox5.com>
parents:
12656
diff
changeset
|
31 if (! warned) |
cad4cba03f19
Deprecate corrcoef, cor and replace with Matlab equivalent corr
Rik <octave@nomad.inbox5.com>
parents:
12656
diff
changeset
|
32 warned = true; |
cad4cba03f19
Deprecate corrcoef, cor and replace with Matlab equivalent corr
Rik <octave@nomad.inbox5.com>
parents:
12656
diff
changeset
|
33 warning ("Octave:deprecated-function", |
cad4cba03f19
Deprecate corrcoef, cor and replace with Matlab equivalent corr
Rik <octave@nomad.inbox5.com>
parents:
12656
diff
changeset
|
34 "cor is obsolete and will be removed from a future version of Octave; please use corr instead"); |
cad4cba03f19
Deprecate corrcoef, cor and replace with Matlab equivalent corr
Rik <octave@nomad.inbox5.com>
parents:
12656
diff
changeset
|
35 endif |
cad4cba03f19
Deprecate corrcoef, cor and replace with Matlab equivalent corr
Rik <octave@nomad.inbox5.com>
parents:
12656
diff
changeset
|
36 |
3200 | 37 if (nargin < 1 || nargin > 2) |
6046 | 38 print_usage (); |
3200 | 39 endif |
40 | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
41 retval = corrcoef (x, y); |
3200 | 42 |
43 endfunction | |
11436
e151e23f73bc
Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
44 |
12656
6b2f14af2360
Overhaul functions in statistics/base directory.
Rik <octave@nomad.inbox5.com>
parents:
12557
diff
changeset
|
45 |
12555
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
46 %!test |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
47 %! x = rand (10, 2); |
12557
4715ce9f911d
cor.m: Increase tolerance of %!tests using random data to assure passage.
Rik <octave@nomad.inbox5.com>
parents:
12555
diff
changeset
|
48 %! assert (cor (x), corrcoef (x), 5*eps); |
12555
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
49 %! assert (cor (x(:,1), x(:,2)) == corrcoef (x(:,1), x(:,2))); |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
50 |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
51 %% Test input validation |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
52 %!error corrcoef (); |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
53 %!error corrcoef (1, 2, 3); |
422a7a7e9b6e
cor.m: fix operation with only single input (bug #32961)
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
54 |