-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode.m
63 lines (55 loc) · 1.9 KB
/
code.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function y=code(x,minmax,opt) %,dummyvars) add later!!
% keywords: data scaling
% call: y=code(x,minmax,opt)
% The function gives the transformation between the original
% and coded variables x.
%
% INPUT: x A (n by p) matrix whose rows give the coordinates to
% be transformed.
% minmax A (2 by p) matrix giving the lower (1.row) and
% upper (2.row) values of the coordinates. By
% default 'minmax' correspond to the +-1 levels in
% the coded units, but see 'imax' below.
% opt Options for coding.
% opt = dire OR opt = [dire imax].
% dire The direction of the transformation.
% dire = 1: original --> coded (+1,-1)
% dire =-1: coded --> original
% imax imax = 1: the values in 'minmax' refer to the
% absolute min/max in a composite design, (i.e.,
% +- sqrt(n) instead of the usual +- 1)
% OPTIONAL, default: imax = 0
%
% OUTPUT y The transformed coordinates
% Copyright (c) 1994 by ProfMath Ltd
% $Revision: 1.4 $ $Date: 2004/10/04 10:57:09 $
[n m] = size(x);
if nargin < 3, error('Not enough input for CODE'); end
%if nargin == 3
% dummyvars=[]; % add this option later
%end
opt = opt(:);
if length(opt)==1,
inv = opt(1); imax = 0;
elseif length(opt)==2
inv = opt(1); imax = abs(opt(2));
else
error('False opt for CODE');
end
if imax == 1;
scale = sqrt(m);
else
scale = 1;
end
range=ones(n,1)*abs(minmax(2,:)-minmax(1,:))*.5/scale;
means=ones(n,1)*mean(minmax);
if any(range<=0)
error('max-min should be > 0')
end
if inv==1
y=(x-means)./range;
elseif inv==-1
y=range.*x+means;
else
error('opt(1) must be 1 or -1 in CODE');
end