]> gitweb.factorcode.org Git - factor.git/commitdiff
math.statistics: adding z-score.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 7 Feb 2013 23:50:34 +0000 (15:50 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 7 Feb 2013 23:50:34 +0000 (15:50 -0800)
basis/math/statistics/statistics-docs.factor
basis/math/statistics/statistics.factor

index 78f2109f172f7f62809ee68a13dec58d64eed53d..ca726a159b1e0224cd1d96bef67880e571529f2a 100644 (file)
@@ -267,6 +267,10 @@ HELP: collect-index-by
     }
 } ;
 
+HELP: z-score
+{ $values { "seq" sequence } { "n" number } }
+{ $description "Calculates the Z-Score for " { $snippet "seq" } "." } ;
+
 ARTICLE: "histogram" "Computing histograms"
 "Counting elements in a sequence:"
 { $subsections
index e68817ec375865212d043dad26e8b0125eedb4d5..195d9906dd5a54ad102ad95cd23061c8d8f71335 100644 (file)
@@ -388,3 +388,6 @@ ALIAS: std sample-std
         [ values ] map [ 0 [ length + ] accumulate nip ] [ ] bi zip
     ] [ length f <array> ] bi
     [ '[ first2 [ _ set-nth ] with each ] each ] keep ;
+
+: z-score ( seq -- n )
+    dup [ mean ] [ sample-std ] bi '[ _ - _ / ] map ;