diff --git a/basis/math/statistics/statistics-tests.factor b/basis/math/statistics/statistics-tests.factor index 5c323f0b2a..dd02341232 100644 --- a/basis/math/statistics/statistics-tests.factor +++ b/basis/math/statistics/statistics-tests.factor @@ -48,7 +48,6 @@ FROM: math.ranges => [a,b] ; { 3 } [ { 1 2 3 4 5 } lower-median ] unit-test { 3 } [ { 1 2 3 4 5 } upper-median ] unit-test - { 1 } [ { 1 } lower-median ] unit-test { 1 } [ { 1 } upper-median ] unit-test { 1 } [ { 1 } median ] unit-test @@ -162,6 +161,10 @@ FROM: math.ranges => [a,b] ; { 18.9375 40.0 42.8125 } .00001 v~ ] unit-test +{ 75 } [ + { 7 7 31 31 47 75 87 115 116 119 119 155 177 } midhinge +] unit-test + { 0x1.02eb63cff3f8p0 } [ { 1 2 3 } entropy ] unit-test { 1.0 } [ 0.5 binary-entropy ] unit-test diff --git a/basis/math/statistics/statistics.factor b/basis/math/statistics/statistics.factor index 32e0ce184e..4950dd983c 100644 --- a/basis/math/statistics/statistics.factor +++ b/basis/math/statistics/statistics.factor @@ -201,6 +201,15 @@ PRIVATE> : quartile ( seq -- seq' ) { 1/4 1/2 3/4 } quantile5 ; +: interquartile ( seq -- q1 q3 ) + quartile [ first ] [ last ] bi ; + +: interquartile-range ( seq -- n ) + interquartile - ; + +: midhinge ( seq -- n ) + interquartile + 2 / ; + : trimean ( seq -- x ) quartile first3 [ 2 * ] dip + + 4 / ; @@ -231,6 +240,9 @@ PRIVATE> : range ( seq -- x ) minmax swap - ; +: fivenum ( seq -- seq' ) + [ quartile ] [ minmax ] bi [ prefix ] [ suffix ] bi* ; + : var-ddof ( seq n -- x ) 2dup [ length ] dip - 0 <= [ 2drop 0