-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstat.ps
60 lines (55 loc) · 1.06 KB
/
stat.ps
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
% PostScript Statistics Procedures
% by Raymond Luckhurst, scriptit.uk
% constants
/MADK 1.4826 def % median absolute deviation consistency constant for normal distribution
% calc mean
% <sample> mean <mean>
/mean {
0 % sum
0 1 3 index length 1 sub {
2 index exch get add
} for % each value
exch length div % mean
} bind def
% calc median
% <sorted sample> median <median>
/median {
dup length 1 sub 2 div
dup floor cvi
exch ceiling cvi
2 copy eq {
pop get
}{
2 index exch get
3 1 roll get
add 2 div
} ifelse
} bind def
% calc median absolute deviation
% <sample> <median> mad <mad>
/mad {
1 index length array
0 1 4 index length 1 sub {
dup 4 index exch get 3 index sub abs 2 index 3 1 roll put
} for % each value
3 1 roll pop pop
{} insertionsort % sort
median
//MADK mul
} bind def
% calc standard deviation
% <sample> <mean> sd <sd>
/sd {
1 index length 1 sub
dup 0 ne {
0 % sum
0 1 3 index {
4 index exch get 3 index sub dup mul add
} for % each value
exch div sqrt % sd
exch pop exch pop
}{
pop pop pop
0
} ifelse
} bind def