2 USING: kernel math sequences ;
5 #! arithmetic mean, sum divided by length
6 [ sum ] keep length / ;
8 : geometric-mean ( seq -- n )
9 #! geometric mean, nth root of product
10 [ product ] keep length swap nth-root ;
12 : harmonic-mean ( seq -- n )
13 #! harmonic mean, reciprocal of sum of reciprocals.
14 #! positive reals only
15 0 [ recip + ] reduce recip ;
18 #! middle number if odd, avg of two middle numbers if even
19 natural-sort dup length dup even? [
20 1- 2 / swap [ nth ] 2keep >r 1+ r> nth + 2 /
30 #! variance, normalize by N-1
31 dup length 1- dup zero? [
34 swap [ mean ] keep 0 [ pick - sq + ] reduce nip swap /
38 #! standard deviation, sqrt of variance