Remove documentation duplication in math.statistics
parent
c3f05eaaa1
commit
47d268d894
|
@ -10,6 +10,7 @@ HELP: geometric-mean
|
|||
HELP: harmonic-mean
|
||||
{ $values { "seq" "a sequence of numbers" } { "n" "a non-negative real number"} }
|
||||
{ $description "Computes the harmonic mean of the elements in " { $snippet "seq" } ". The harmonic mean is appropriate when the average of rates is desired." }
|
||||
{ $notes "Positive reals only." }
|
||||
{ $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } harmonic-mean ." "6/11" } }
|
||||
{ $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
|
||||
|
||||
|
@ -36,7 +37,7 @@ HELP: range
|
|||
|
||||
HELP: std
|
||||
{ $values { "seq" "a sequence of numbers" } { "x" "a non-negative real number"} }
|
||||
{ $description "Computes the standard deviation of " { $snippet "seq" } " by squaring the variance of the sequence. It measures how widely spread the values in a sequence are about the mean." }
|
||||
{ $description "Computes the standard deviation of " { $snippet "seq" } ", which is the square root of the variance. It measures how widely spread the values in a sequence are about the mean." }
|
||||
{ $examples
|
||||
{ $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } std ." "1.0" }
|
||||
{ $example "USING: math.statistics prettyprint ;" "{ 1 2 3 4 } std ." "1.290994448735806" } } ;
|
||||
|
|
|
@ -5,20 +5,15 @@ USING: arrays combinators kernel math math.analysis math.functions sequences
|
|||
IN: math.statistics
|
||||
|
||||
: mean ( seq -- n )
|
||||
#! arithmetic mean, sum divided by length
|
||||
[ sum ] [ length ] bi / ;
|
||||
|
||||
: geometric-mean ( seq -- n )
|
||||
#! geometric mean, nth root of product
|
||||
[ length ] [ product ] bi nth-root ;
|
||||
|
||||
: harmonic-mean ( seq -- n )
|
||||
#! harmonic mean, reciprocal of sum of reciprocals.
|
||||
#! positive reals only
|
||||
[ recip ] sigma recip ;
|
||||
|
||||
: median ( seq -- n )
|
||||
#! middle number if odd, avg of two middle numbers if even
|
||||
natural-sort dup length even? [
|
||||
[ midpoint@ dup 1- 2array ] keep nths mean
|
||||
] [
|
||||
|
@ -26,11 +21,10 @@ IN: math.statistics
|
|||
] if ;
|
||||
|
||||
: range ( seq -- n )
|
||||
#! max - min
|
||||
minmax swap - ;
|
||||
|
||||
: var ( seq -- x )
|
||||
#! variance, normalize by N-1
|
||||
#! normalize by N-1
|
||||
dup length 1 <= [
|
||||
drop 0
|
||||
] [
|
||||
|
@ -39,11 +33,9 @@ IN: math.statistics
|
|||
] if ;
|
||||
|
||||
: std ( seq -- x )
|
||||
#! standard deviation, sqrt of variance
|
||||
var sqrt ;
|
||||
|
||||
: ste ( seq -- x )
|
||||
#! standard error, standard deviation / sqrt ( length of sequence )
|
||||
[ std ] [ length ] bi sqrt / ;
|
||||
|
||||
: ((r)) ( mean(x) mean(y) {x} {y} -- (r) )
|
||||
|
|
Loading…
Reference in New Issue