Go implementation of Welford's method for one-pass variance computation with D. H. D. West improved methods.
go get github.com/axiomhq/variance
package main
import (
"fmt"
"github.com/axiomhq/variance"
)
func main() {
stats := variance.New()
stats.Add(1)
stats.Add(1)
stats.Add(1)
stats.Add(0)
stats.Add(0)
stats.Add(0)
fmt.Println(
stats.Mean(),
stats.Variance(),
stats.StandardDeviation(),
stats.VariancePopulation(),
stats.StandardDeviationPopulation(),
stats.NumDataValues(),
)
}
For more examples, check out the example or run it on pkg.go.dev.
- One-pass variance computation
- Merging of multiple sets of statistics
- Support for weighted values
- Stable and accurate computation using D. H. D. West's improved method
A method of improved efficiency is given for updating the mean and variance of weighted sampled data when an additional data value is included in the set. Evidence is presented that the method is stable and at least as accurate as the best existing updating method.
-- Updating mean and variance estimates: an improved method - D. H. D. West