# welford-online-mean-variance: Online computation of mean and variance using the Welford algorithm.

[ bsd3, library, statistics ] [ Propose Tags ]

## Modules

[Index] [Quick Jump]

## Downloads

#### Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

• No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.4, 0.2.0.0 CHANGELOG.md base (>=4.7 && <5), cereal, deepseq, vector [details] BSD-3-Clause 2023 Manuel Schneckenreither Manuel Schneckenreither manuel.schnecki@gmail.com Statistics https://github.com/schnecki/welford-online-mean-variance#readme https://github.com/schnecki/welford-online-mean-variance/issues head: git clone https://github.com/schnecki/welford-online-mean-variance by schnecki at 2023-01-30T12:30:03Z LTSHaskell:0.2.0.0, NixOS:0.2.0.0, Stackage:0.2.0.0 253 total (18 in the last 30 days) 2.0 (votes: 1) [estimated by Bayesian average] λ λ λ Docs available Last success reported on 2023-01-30

## Readme for welford-online-mean-variance-0.2.0.0

[back to package description]

# Welford: Online mean and variance computation

Example

example :: [Double] -> IO ()
example vals = do
let n = fromIntegral (length vals)
mean = sum vals / n
var = sum (map (\x -> (x - mean) ^ 2) vals) / (n - 1)
(wMean, _, wVarSample) = finalize \$ foldl' addValue WelfordExistingAggregateEmpty vals
print (mean, var)
print (wMean, wVarSample)

WelfordExistingAggregate is used to save the state. Use the function finalize to retrieve the current estimates for the mean, variance and sample variance.