Skip to content

thorstenrie/lpstats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

lpstats

Go package for simple statistics

Go Report Card CodeFactor OSS Lifecycle

PkgGoDev GitHub go.mod Go version Libraries.io dependency status for GitHub repo

GitHub release (latest by date) GitHub last commit GitHub commit activity GitHub code size in bytes GitHub Top Language GitHub

The package lpstats provides a simple interface for statistics. It provides functions for the calculation of mean and variance.

  • Simple: Without configuration, just function calls
  • Easy to use: Most functions take integer and float values as arguments
  • Tested: Unit tests with high code coverage
  • Dependencies: Only depends on the Go Standard Library and tserr

Usage

The package is installed with

go get github.com/thorstenrie/lpstats

In the Go app, the package is imported with

import "github.com/thorstenrie/lpstats"

External functions can be used with arguments of type integer or float. Type constraints are defined in constraints.go.

  • Number: number types, for example, func Square[T Number](x T) float64
  • Signed: signed number types, for example, func Sign[T Signed](a T) T
  • Sinteger: signed integer types, for example func EqualS[T Sinteger](x, y T) error
  • Uinteger: unsigned integer types, for example, func VarianceN[T Uinteger](n T) float64

Functions

The package provides mathematical and statistical functions

  • Absolute value
  • Arithmetic mean of a discrete value array
  • Equal for slices of signed integers
  • Expected value for a uniform distribution
  • Max (Depcrecated and will be removed in one of the next releases)
  • Min (Depcrecated and will be removed in one of the next releases)
  • Near equal
  • Sign
  • Square
  • Sum
  • Variance of a discrete value array
  • Variance of a uniform distribution

Example

package main

import (
	"fmt"

	"github.com/thorstenrie/lpstats"
)

func main() {
	var (
		i []int     = []int{1, 2, 3, 4, 5, 6}
		x []float64 = []float64{1.1, 2.1, 3.1, 4.1, 5.1, 6.1}
		n uint      = 6
	)

	im, _ := lpstats.ArithmeticMean(i)
	xm, _ := lpstats.ArithmeticMean(x)

	iv, _ := lpstats.Variance(i)
	xv, _ := lpstats.Variance(x)

	fmt.Printf("Mean(i) = %f, Variance(i) = %f\n", im, iv)
	fmt.Printf("Mean(f) = %f, Variance(x) = %f\n", xm, xv)

	fmt.Printf("Variance of a %d-sided die: %.2f\n", n, lpstats.VarianceN(n))
}

Known Limitations

  • Most calculations are based on floating point arithmetic. It is not suitable for arbitrary precision fixed-point decimal arithmetic.

Links

Godoc

Go Report Card

Open Source Insights