3200
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
3426
|
2 ## |
3200
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
3426
|
7 ## |
3200
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
11 ## General Public License for more details. |
|
12 ## |
3200
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this file. If not, write to the Free Software Foundation, |
|
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
16 |
3453
|
17 ## -*- texinfo -*- |
|
18 ## @deftypefn {Function File} {} studentize (@var{x}) |
|
19 ## If @var{x} is a vector, subtract its mean and divide by its standard |
3200
|
20 ## deviation. |
|
21 ## |
3453
|
22 ## If @var{x} is a matrix, do the above for each column. |
|
23 ## @end deftypefn |
3200
|
24 |
3456
|
25 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
26 ## Description: Subtract mean and divide by standard deviation |
3200
|
27 |
|
28 function t = studentize (x) |
3426
|
29 |
3200
|
30 if (nargin != 1) |
|
31 usage ("studentize (x)"); |
|
32 endif |
|
33 |
|
34 if is_vector (x) |
|
35 if (std (x) == 0) |
|
36 t = zeros (size (x)); |
|
37 else |
|
38 t = (x - mean (x)) / std (x); |
|
39 endif |
|
40 elseif is_matrix (x) |
|
41 l = ones (rows (x), 1); |
|
42 t = x - l * mean (x); |
3388
|
43 t = t ./ (l * max ([(std (t)); (! any (t))])); |
3200
|
44 else |
3456
|
45 error ("studentize: x must be a vector or a matrix."); |
3200
|
46 endif |
|
47 |
|
48 endfunction |