1 USING: debugger hashtables help.markup help.syntax kernel math
6 { $values { "seq" sequence } { "x" "a non-negative real number" } }
7 { $description "Computes the geometric mean of all elements in " { $snippet "seq" } ". The geometric mean measures the central tendency of a data set and minimizes the effects of extreme values." }
8 { $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } geometric-mean ." "1.8171205928321397" } }
9 { $errors "Throws a " { $link signal-error. } " (square-root of 0) if the sequence is empty." } ;
12 { $values { "seq" sequence } { "x" "a non-negative real number" } }
13 { $description "Computes the harmonic mean of the elements in " { $snippet "seq" } ". The harmonic mean is appropriate when the average of rates is desired." }
14 { $notes "Positive reals only." }
15 { $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } harmonic-mean ." "1+7/11" } }
16 { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
19 { $values { "seq" sequence } { "k" integer } { "elt" object } }
20 { $description "Returns the kth smallest element. This is semantically equivalent to " { $snippet "swap natural-sort nth" } ", and is therefore zero-indexed. " { $snippet "k" } " may not be larger than the highest index of " { $snippet "sequence" } "." }
21 { $examples { $example "USING: math.statistics prettyprint ;" "{ 3 1 2 } 1 kth-smallest ." "2" } } ;
24 { $values { "seq" sequence } { "x" "a non-negative real number" } }
25 { $description "Computes the arithmetic mean of the elements in " { $snippet "seq" } "." }
26 { $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } mean ." "2" } }
27 { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." }
28 { $see-also geometric-mean harmonic-mean } ;
31 { $values { "seq" sequence } { "x" "a non-negative real number" } }
32 { $description "Computes the median of " { $snippet "seq" } " by finding the middle element of the sequence using " { $link kth-smallest } ". If there is an even number of elements in the sequence, the median is not unique, so the mean of the two middle values is output." }
34 { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } median ." "2" }
35 { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 4 } median ." "2+1/2" } }
36 { $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
39 { $values { "seq" sequence } { "x" "a non-negative real number" } }
40 { $description "Computes the difference of the maximum and minimum values in " { $snippet "seq" } "." }
42 { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } range ." "2" }
43 { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 4 } range ." "3" } } ;
46 { $values { "seq" sequence } { "min" real } { "max" real } }
47 { $description "Finds the minimum and maximum elements of " { $snippet "seq" } " in one pass. Throws an error on an empty sequence." }
49 { $example "USING: arrays math.statistics prettyprint ;"
50 "{ 1 2 3 } minmax 2array ."
56 { $values { "seq" sequence } { "x" "a non-negative real number" } }
57 { $description "Computes the sample standard deviation of " { $snippet "seq" } ", which is the square root of the sample variance. It measures how widely spread the values in a sequence are about the mean for a random subset of a dataset." }
59 { $example "USING: math.statistics prettyprint ;" "{ 7 8 9 } sample-std ." "1.0" } } ;
62 { $values { "seq" sequence } { "x" "a non-negative real number" } }
63 { $description "Computes the standard error of the mean for " { $snippet "seq" } ". It's defined as the standard deviation divided by the square root of the length of the sequence, and measures uncertainty associated with the estimate of the mean." }
65 { $example "USING: math.statistics prettyprint ;" "{ -2 2 } sample-ste ." "2.0" }
69 { $values { "seq" sequence } { "x" "a non-negative real number" } }
70 { $description "Computes the variance of " { $snippet "seq" } ". It's a measurement of the spread of values in a sequence." }
71 { $notes "If the number of elements in " { $snippet "seq" } " is 1 or less, it outputs 0." }
73 { $example "USING: math.statistics prettyprint ;" "{ 1 } sample-var ." "0" }
74 { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } sample-var ." "1" }
75 { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 4 } sample-var ." "1+2/3" } } ;
78 { $values { "x-seq" sequence } { "y-seq" sequence } { "cov" "a real number" } }
79 { $description "Computes the covariance of two sequences, " { $snippet "x-seq" } " and " { $snippet "y-seq" } "." } ;
82 { $values { "x-seq" sequence } { "y-seq" sequence } { "corr" "a real number" } }
83 { $description "Computes the correlation of two sequences, " { $snippet "x-seq" } " and " { $snippet "y-seq" } "." } ;
86 { $values { "x-seq" sequence } { "y-seq" sequence } { "corr" "a real number" } }
87 { $description "Computes the Spearman's correlation of two sequences, " { $snippet "x-seq" } " and " { $snippet "y-seq" } "." $nl "For more information see " { $url "https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient" } "." } ;
92 { "hashtable" hashtable }
94 { $description "Returns a hashtable where the keys are the elements of the sequence and the values are the number of times they appeared in that sequence." }
96 { $example "! Count the number of times an element appears in a sequence."
97 "USING: prettyprint math.statistics ;"
98 "\"aaabc\" histogram ."
99 "H{ { 97 3 } { 98 1 } { 99 1 } }"
107 { "quot" { $quotation ( x -- bin ) } }
108 { "hashtable" hashtable }
110 { $description "Returns a hashtable where the keys are the elements of the sequence binned by being passed through " { $snippet "quot" } ", and the values are the number of times members of each bin appeared in that sequence." }
112 { $unchecked-example "! Count the number of times letters and non-letters appear in a sequence."
113 "USING: prettyprint math.statistics unicode ;"
114 "\"aaa123bc\" [ letter? ] histogram-by ."
115 "H{ { t 5 } { f 3 } }"
121 { "hashtable" hashtable } { "seq" sequence }
123 { $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurrences of each element." }
125 { $example "! Count the number of times the elements of two sequences appear."
126 "USING: prettyprint math.statistics ;"
127 "\"aaabc\" histogram \"aaaaaabc\" histogram! ."
128 "H{ { 97 9 } { 98 2 } { 99 2 } }"
132 HELP: sorted-histogram
135 { "alist" "an array of key/value pairs" }
137 { $description "Outputs a " { $link histogram } " of a sequence sorted by number of occurrences from lowest to highest." }
139 { $example "USING: prettyprint math.statistics ;"
140 "\"abababbbbbbc\" sorted-histogram ."
141 "{ { 99 1 } { 97 3 } { 98 8 } }"
146 { $values { "seq" sequence } { "seq'" sequence } }
147 { $description "Returns the cumulative sum of " { $snippet "seq" } "." }
149 { $example "USING: math.statistics prettyprint ;"
150 "{ 1 -1 2 -1 4 } cum-sum ."
156 { $values { "seq" sequence } { "seq'" sequence } }
157 { $description "Returns the cumulative sum of " { $snippet "seq" } " starting with 0 and not including the whole sum." }
159 { $example "USING: math.statistics prettyprint ;"
160 "{ 1 -1 2 -1 4 } cum-sum0 ."
166 { $values { "seq" sequence } { "quot" { $quotation ( elt -- ? ) } } { "seq'" sequence } }
167 { $description "Returns the cumulative count of how many times " { $snippet "quot" } " returns true." }
169 { $example "USING: math math.statistics prettyprint ;"
170 "{ 1 -1 2 -1 4 } [ 0 < ] cum-count ."
177 { $values { "seq" sequence } { "seq'" sequence } }
178 { $description "Returns the cumulative product of " { $snippet "seq" } "." }
180 { $example "USING: math.statistics prettyprint ;"
181 "{ 2 3 4 } cum-product ."
187 { $values { "seq" sequence } { "seq'" sequence } }
188 { $description "Returns the cumulative product of " { $snippet "seq" } " starting with 1 and not including the whole product." }
190 { $example "USING: math.statistics prettyprint ;"
191 "{ 2 3 4 } cum-product1 ."
197 { $values { "seq" sequence } { "seq'" sequence } }
198 { $description "Returns the cumulative mean of " { $snippet "seq" } "." }
200 { $example "USING: math.statistics prettyprint ;"
201 "{ 1.0 2.0 3.0 } cum-mean ."
207 { $values { "seq" sequence } { "seq'" sequence } }
208 { $description "Returns the cumulative min of " { $snippet "seq" } "." }
210 { $example "USING: math.statistics prettyprint ;"
211 "{ 5 3 4 1 } cum-min ."
217 { $values { "seq" sequence } { "seq'" sequence } }
218 { $description "Returns the cumulative max of " { $snippet "seq" } "." }
220 { $example "USING: math.statistics prettyprint ;"
221 "{ 1 -1 3 5 } cum-max ."
227 { $values { "u" sequence } { "v" sequence } }
228 { $description "Shifts and rescales the elements of " { $snippet "u" } " to have zero mean and unit sample variance." } ;
231 { $values { "u" sequence } { "v" sequence } }
232 { $description "Returns the successive differences of elements in " { $snippet "u" } "." } ;
235 { $values { "u" sequence } { "v" sequence } }
236 { $description "Returns " { $snippet "u" } " rescaled to run from 0 to 1 over the range min to max." } ;
239 { $values { "seq" sequence } { "n" number } }
240 { $description "Calculates the Z-Score for " { $snippet "seq" } "." } ;
244 { "scores" sequence }
247 { $description "Calculates the discounted cumulative gain from a list of scores. The discounted cumulative gain can be used to compare two lists of results against each other given scores for each of the results."
249 " See " { $url "https://en.wikipedia.org/wiki/Discounted_cumulative_gain" }
254 { "scores" sequence }
257 { $description "Calculates the normalized discounted cumulative gain from a list of scores. The ndcg is the discounted cumulative gain divided by the theoretical maximum dcg for the given list."
259 "See " { $url "https://en.wikipedia.org/wiki/Discounted_cumulative_gain" }
262 { dcg ndcg } related-words
264 ARTICLE: "histogram" "Computing histograms"
265 "Counting elements in a sequence:"
273 ARTICLE: "cumulative" "Computing cumulative sequences"
274 "Cumulative words build on " { $link accumulate } " and " { $link accumulate* } "."
283 "Cumulative comparisons:"
288 "Cumulative counting:"
293 ARTICLE: "math.statistics" "Statistics"
294 "Computing the mean:"
295 { $subsections mean geometric-mean harmonic-mean }
296 "Computing the median:"
297 { $subsections median lower-median upper-median medians }
298 "Computing the mode:"
299 { $subsections mode }
300 "Computing the population standard deviation, standard error, and variance:"
301 { $subsections population-std population-ste population-var }
302 "Computing the sample standard deviation, standard error, and variance:"
303 { $subsections sample-std sample-ste sample-var }
304 "Computing the nth delta-degrees-of-freedom statistics:"
305 { $subsections std-ddof ste-ddof var-ddof }
306 "Computing the range and minimum and maximum elements:"
307 { $subsections range minmax }
308 "Computing the kth smallest element:"
309 { $subsections kth-smallest }
310 "Counting the frequency of occurrence of elements:"
311 { $subsections "histogram" }
312 "Computing cumulative sequences:"
313 { $subsections "cumulative" }
314 "Calculating discounted cumulative gain:"
315 { $subsections dcg ndcg } ;
317 ABOUT: "math.statistics"
319 { var-ddof population-var sample-var } related-words
320 { std-ddof population-std sample-std } related-words
321 { ste-ddof population-ste sample-ste } related-words
322 { corr-ddof population-corr sample-corr } related-words
323 { cov-ddof population-cov sample-cov } related-words
325 { sum-of-squares sum-of-cubes sum-of-quads } related-words