New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/thorstenrie/lpstats

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/thorstenrie/lpstats

  • v1.3.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

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.

Godoc

Go Report Card

Open Source Insights

FAQs

Package last updated on 17 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc