module Stats exposing
    ( NormalDistribution
    , getNormalDistribution
    , mean
    , stdDev
    , zscore
    )


type NormalDistribution
    = NormalDistribution Float Float -- mean, std dev.


getNormalDistribution : List Float -> NormalDistribution
getNormalDistribution xs =
    let
        n =
            toFloat (List.length xs)

        mu =
            List.sum xs / n

        variance =
            List.sum (List.map (\x -> (x - mu) ^ 2) xs) / n

        sigma =
            sqrt variance
    in
    NormalDistribution mu sigma


mean : NormalDistribution -> Float
mean (NormalDistribution m _) =
    m


stdDev : NormalDistribution -> Float
stdDev (NormalDistribution _ s) =
    s


zscore : Float -> NormalDistribution -> Float
zscore x (NormalDistribution m s) =
    (x - m) / s
