Skip to content

Go implementation of variance's method for one-pass variance computation with D. H. D. West improved methods which features merging of several multiple sets of statistics and adding weighted values.

License

Notifications You must be signed in to change notification settings

axiomhq/variance

Repository files navigation

variance Go Reference Workflow Latest Release License

Go implementation of Welford's method for one-pass variance computation with D. H. D. West improved methods.

Install

go get github.com/axiomhq/variance

Usage

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.

Features

  • 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

Reference

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

License

MIT

About

Go implementation of variance's method for one-pass variance computation with D. H. D. West improved methods which features merging of several multiple sets of statistics and adding weighted values.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5