Variance and standard deviation caluculation using variance's algorithm
Table of Contents
Introduction
Go implementation of variance’s method for one-pass variance computation with D. H. D. West improved methods.
Highlights
- Merging of several multiple sets of statistics
- Add weighted values
Abstract
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
Installation
go get
Install using go get github.com/axiomhq/variance
Install from source
git clone https://github.com/axiomhq/variance.git
cd variance
make # Run code generators, linters, sanitizers and test suits
Usage
package variance_test
import (
"fmt"
"github.com/axiomhq/variance"
)
func Example() {
stats1 := variance.New()
stats1.Add(1)
stats1.Add(1)
stats1.Add(1)
stats1.Add(0)
stats1.Add(0)
stats1.Add(0)
fmt.Println(
stats1.Mean(),
stats1.Variance(),
stats1.StandardDeviation(),
stats1.VariancePopulation(),
stats1.StandardDeviationPopulation(),
stats1.NumDataValues(),
)
stats2 := variance.New()
stats2.Add(3)
// Merge the values of stats2 into stats1.
stats1.Merge(stats2)
// Reset the values in stats2.
stats2.Clear()
// Output: 0.5 0.3 0.5477225575051661 0.25 0.5 6
}
Contributing
Feel free to submit PRs or to fill Issues.
License
© Axiom, Inc., 2021
Distributed under MIT License (The MIT License
).
See LICENSE for more information.