BrianHicks / elm-trend / Trend.Math

Math helpers for calculating trends.


type Error
    = NeedMoreValues Basics.Int
    | AllZeros

Indicate that something has gone wrong in the caculation of a trend line. Specifically:

mean : List Basics.Float -> Result Error Basics.Float

Calculate the mean (average) for some values.

mean [ 1, 2, 3, 4, 5 ]
    --> Ok 3

stddev : List Basics.Float -> Result Error Basics.Float

Calculate the standard deviation for some values.

stddev [ 1, 2, 3, 4, 5 ]
    --> Ok 1.4142135623730951

correlation : List ( Basics.Float, Basics.Float ) -> Result Error Basics.Float

Get the correlation coefficient for some values. The returned value will be between 0 (no correlation) and 1 (perfect correlation.)

correlation [ (1, 1), (2, 2), (3, 3), (4, 4) ]
    --> Ok 1

Minimum required values: 2

Under the covers, this is a Pearson correlation coefficient.