annotate scripts/deprecated/studentize.m @ 16033:23a7661e529a ss-3-7-2

snapshot version 3.7.2 * configure.ac (AC_INIT): Set version to 3.7.2. (OCTAVE_RELEASE_DATE): Set to 2013-02-09. (OCTAVE_COPYRIGHT): Update year.
author John W. Eaton <jwe@octave.org>
date Sun, 10 Feb 2013 00:59:19 -0500
parents 72c96de7a403
children 1c89599167a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 12586
diff changeset
1 ## Copyright (C) 1995-2012 Kurt Hornik
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3388
diff changeset
2 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3458
diff changeset
3 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3458
diff changeset
4 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3458
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3458
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3388
diff changeset
9 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3458
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3388
diff changeset
13 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3388
diff changeset
14 ##
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
18
3453
71d2e09c15a2 [project @ 2000-01-18 08:32:09 by jwe]
jwe
parents: 3426
diff changeset
19 ## -*- texinfo -*-
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
20 ## @deftypefn {Function File} {} studentize (@var{x})
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
21 ## @deftypefnx {Function File} {} studentize (@var{x}, @var{dim})
3453
71d2e09c15a2 [project @ 2000-01-18 08:32:09 by jwe]
jwe
parents: 3426
diff changeset
22 ## If @var{x} is a vector, subtract its mean and divide by its standard
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
23 ## deviation.
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
24 ##
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
25 ## If @var{x} is a matrix, do the above along the first non-singleton
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
26 ## dimension.
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
27 ## If the optional argument @var{dim} is given, operate along this dimension.
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
28 ## @seealso{center}
3453
71d2e09c15a2 [project @ 2000-01-18 08:32:09 by jwe]
jwe
parents: 3426
diff changeset
29 ## @end deftypefn
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
30
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5307
diff changeset
31 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
3456
434790acb067 [project @ 2000-01-19 06:58:51 by jwe]
jwe
parents: 3453
diff changeset
32 ## Description: Subtract mean and divide by standard deviation
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
33
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
34 function t = studentize (x, dim)
12586
f9b7aa3b88f8 Deprecate studentize(), replace with zscore().
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
35 persistent warned = false;
f9b7aa3b88f8 Deprecate studentize(), replace with zscore().
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
36 if (! warned)
f9b7aa3b88f8 Deprecate studentize(), replace with zscore().
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
37 warned = true;
f9b7aa3b88f8 Deprecate studentize(), replace with zscore().
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
38 warning ("Octave:deprecated-function",
f9b7aa3b88f8 Deprecate studentize(), replace with zscore().
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
39 "studentize is obsolete and will be removed from a future version of Octave; please use zscore instead");
f9b7aa3b88f8 Deprecate studentize(), replace with zscore().
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
40 endif
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3388
diff changeset
41
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
42 if (nargin != 1 && nargin != 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5428
diff changeset
43 print_usage ();
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
44 endif
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
45
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
46 if (! isnumeric(x))
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
47 error ("studentize: X must be a numeric vector or matrix");
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
48 endif
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
49
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
50 if (isinteger (x))
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
51 x = double (x);
10669
cab3b148d4e4 Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
52 endif
cab3b148d4e4 Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
53
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
54 nd = ndims (x);
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
55 sz = size (x);
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
56 if (nargin != 2)
4886
54b076a24718 [project @ 2004-04-30 04:31:51 by jwe]
jwe
parents: 4885
diff changeset
57 ## Find the first non-singleton dimension.
10669
cab3b148d4e4 Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
58 dim = find (sz > 1, 1);
cab3b148d4e4 Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
59 if (isempty (dim))
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
60 dim = 1;
3200
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
61 endif
781c930425fd [project @ 1998-10-29 05:23:08 by jwe]
jwe
parents:
diff changeset
62 else
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
63 if (!(isscalar (dim) && dim == fix (dim))
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 10669
diff changeset
64 || !(1 <= dim && dim <= nd))
10669
cab3b148d4e4 Improve validation of input arguments for base statistics functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
65 error ("studentize: DIM must be an integer and a valid dimension");
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
66 endif
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
67 endif
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
68
4886
54b076a24718 [project @ 2004-04-30 04:31:51 by jwe]
jwe
parents: 4885
diff changeset
69 c = sz(dim);
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
70 if (c == 0)
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
71 t = x;
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
72 else
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
73 idx = ones (1, nd);
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
74 idx(dim) = c;
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
75 t = x - repmat (mean (x, dim), idx);
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
76 t = t ./ repmat (max (cat (dim, std(t, [], dim), ! any (t, dim)), [], dim), idx);
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
77 endif
4885
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
78
28ab079d8f0e [project @ 2004-04-30 04:21:33 by jwe]
jwe
parents: 4030
diff changeset
79 endfunction
11436
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
80
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
81 %!assert(studentize ([1,2,3]), [-1,0,1])
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
82 %!assert(studentize (int8 ([1,2,3])), [-1,0,1])
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
83 #%!assert(studentize (ones (3,2,0,2)), zeros (3,2,0,2))
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
84 %!assert(studentize ([2,0,-2;0,2,0;-2,-2,2]), [1,0,-1;0,1,0;-1,-1,1])
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
85
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
86 %% Test input validation
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
87 %!error studentize ()
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
88 %!error studentize (1, 2, 3)
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
89 %!error studentize ([true true])
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
90 %!error studentize (1, ones(2,2))
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
91 %!error studentize (1, 1.5)
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
92 %!error studentize (1, 0)
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
93 %!error studentize (1, 3)
e151e23f73bc Overhaul base statistics functions and documentation of same.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
94