stat

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 6 Imported by: 4

README

goulash/stat

GoDoc

Package stat provides functions and data structures for statistics.

There are several sub-packages:

For more information, see the documentation! :-)

This package is licensed under the MIT license.

Documentation

Overview

Package stat provides statistic functions and types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(s Series, f func(float64) float64)

Apply modifies the series by replacing each value v with f(v).

func Autocor

func Autocor(s Series, lag int) float64

Autocor returns the sample correlation of s with itself lag values later. The series s must be at least 2 longer than lag, else NaN is returned.

func Autocov

func Autocov(s Series, lag int) float64

Autocov returns the sample covariance of s with itself lag values later. The series s must be at least 2 longer than lag, else NaN is returned.

func Cor

func Cor(s, t Series) float64

Cor returns the sample correlation of two series s and t.

If the series do not have the same lengths, this function panics. If s is empty or has only one element, one cannot speak of variance, and NaN is returned.

NOTE: This is the same as the population correlation of two series, hence there is no CorP.

func Cov

func Cov(s, t Series) float64

Cov returns the sample covariance of two series s and t.

If the series do not have the same lengths, this function panics. If s is empty or has only one element, one cannot speak of variance, and NaN is returned.

func CovP

func CovP(s, t Series) float64

CovP returns the population covariance of two series s and t.

If the series do not have the same lengths, this function panics. If s is empty or has only one element, one cannot speak of variance, and NaN is returned.

func Fold

func Fold(s Series, a float64, f func(float64, float64) float64) float64

Fold a series into a single value by repeatedly applying a = f(a, x).

For example, to find the maximum value:

Fold(s, math.Inf(-1), math.Max)

func Max

func Max(s Series) float64

Max returns the maximum value in the series, or -∞ if the series is empty.

func Mean

func Mean(s Series) float64

Mean returns the empirical mean of the series s.

The mean calculated here is the running mean, which ensures that an answer is given regardless of how long s is. The accuracy of the answer suffers however.

If s is empty, NaN is returned.

func Median

func Median(s Series) float64

Median returns the median of the series s.

If s has an even number of elements, the mean of the two middle elements is returned.

If s is empty or has only one element, NaN is returned.

Calculating the median requires sorting a copy of the series.

func Min

func Min(s Series) float64

Min returns the minimum value in the series, or +∞ if the series is empty.

func Skew

func Skew(s Series) float64

Skew returns the sample skew of the series.

NOTE: Not implemented yet.

func SkewP

func SkewP(s Series) float64

SkewP returns the population skew of the series.

NOTE: Not implemented yet.

func Std

func Std(s Series) float64

Std returns the sample standard deviation of the series.

If s is empty or has only one element, one cannot speak of variance, and NaN is returned.

func StdP

func StdP(s Series) float64

StdP returns the population standard deviation of the series.

If s is empty or has only one element, one cannot speak of variance, and NaN is returned.

func Var

func Var(s Series) float64

Var returns the sample variance of the series.

If s is empty or has only one element, one cannot speak of variance, and NaN is returned.

func VarP

func VarP(s Series) float64

VarP returns the population variance of the series.

If s is empty or has only one element, one cannot speak of variance, and NaN is returned.

Types

type Run

type Run struct {
	// contains filtered or unexported fields
}

Run calculates the running mean, variance, and standard deviation.

Note: Run contains only plain old datatypes, so a shallow copy is a complete copy.

func (*Run) Add

func (r *Run) Add(x float64)

Add a new value to the run.

func (*Run) AddN

func (r *Run) AddN(n int64, x float64)

func (*Run) Max

func (r *Run) Max() float64

Max returns the max.

func (*Run) Mean

func (r *Run) Mean() float64

Mean returns the mean.

func (*Run) Min

func (r *Run) Min() float64

Min returns the min.

func (*Run) N

func (r *Run) N() int64

func (*Run) Reset

func (r *Run) Reset()

Reset the values to zero.

func (*Run) Std

func (r *Run) Std() float64

Std returns the sample standard deviation.

func (*Run) StdP

func (r *Run) StdP() float64

StdP returns the population standard deviation.

func (*Run) Var

func (r *Run) Var() float64

Var returns the sample variance.

func (*Run) VarP

func (r *Run) VarP() float64

VarP returns the population variance.

type Running

type Running struct {
	// contains filtered or unexported fields
}

Running calculates the running means, variances, and standard deviation over time.

func (*Running) Add

func (r *Running) Add(t Time, x float64)

func (*Running) Means

func (r *Running) Means() Series

func (*Running) Stds

func (r *Running) Stds() Series

func (*Running) StdsP

func (r *Running) StdsP() Series

func (*Running) Times

func (r *Running) Times() []Time

func (*Running) Vars

func (r *Running) Vars() Series

func (*Running) VarsP

func (r *Running) VarsP() Series

type Series

type Series []float64

The Series type is a slice of float64 values.

func Add

func Add(s, t Series) Series

Add returns the components of s and t added to each other.

func Add1

func Add1(s Series, f float64) Series

Add1 adds f to each value in s and returns a new series.

func Div

func Div(s, t Series) Series

Div returns the components of s divided by those of t.

func Div1

func Div1(s Series, f float64) Series

Div1 divides f from each value in s and returns a new series.

func Head(s Series, n int) Series

Head returns the first n values from s.

If n > len(s), an out-of-bounds panic will occur. The returned slice is a slice from s, not a new series.

func Map

func Map(s Series, f func(float64) float64) Series

Map creates a new series by applying f to each value in s.

func Map2

func Map2(s, t Series, f func(a, b float64) float64) Series

Map creates a new series by applying f to each value in s and t.

If the series lengths are not the same, the function panics.

func Mul

func Mul(s, t Series) Series

Mul returns the components of s and t multiplied to each other.

func Mul1

func Mul1(s Series, f float64) Series

Mul1 multiplies f to each value in s and returns a new series.

func Resize

func Resize(s Series, n int) Series

Resize returns s resized to have length n.

If s is empty, the function panics. If n is less than the size of s, the first n elements of s is returned. If n is greater than the size of s, s is appended to s as often as necessary:

Example:

Resize([1 2 3], 5) -> [1 2 3 1 2]
Resize([1 2 3 4 5], 3) -> [1 2 3]

func Sub

func Sub(s, t Series) Series

Sub returns the components of s subtracted by those of t.

func Sub1

func Sub1(s Series, f float64) Series

Sub1 subtracts f from each value in s and returns a new series.

func Tail

func Tail(s Series, n int) Series

Tail returns the last n values from s.

If n > len(s), an out-of-bounds panic will occur. The returned slice is a slice from s, not a new series.

func (Series) Add

func (s Series) Add(t Series) Series

func (Series) Add1

func (s Series) Add1(f float64) Series

func (*Series) Append

func (s *Series) Append(f ...float64)

func (*Series) Append1

func (s *Series) Append1(f float64)

func (Series) Autocor

func (s Series) Autocor(lag int) float64

func (Series) Autocov

func (s Series) Autocov(lag int) float64

func (Series) Copy

func (s Series) Copy() Series

Copy returns a copy of the series s.

func (Series) Cor

func (s Series) Cor(t Series) float64

func (Series) Cov

func (s Series) Cov(t Series) float64

func (Series) CovP

func (s Series) CovP(t Series) float64

func (Series) Div

func (s Series) Div(t Series) Series

func (Series) Div1

func (s Series) Div1(f float64) Series

func (Series) Head

func (s Series) Head(n int) Series

func (Series) Len

func (s Series) Len() int

func (Series) Map

func (s Series) Map(f func(float64) float64) Series

func (Series) Max

func (s Series) Max() float64

func (Series) Mean

func (s Series) Mean() float64

func (Series) Median

func (s Series) Median() float64

func (Series) Min

func (s Series) Min() float64

func (Series) Mul

func (s Series) Mul(t Series) Series

func (Series) Mul1

func (s Series) Mul1(f float64) Series

func (*Series) Reset

func (s *Series) Reset()

func (Series) Skew

func (s Series) Skew() float64

func (Series) SkewP

func (s Series) SkewP() float64

func (Series) Std

func (s Series) Std() float64

func (Series) StdP

func (s Series) StdP() float64

func (Series) String

func (s Series) String() string

String returns the string representation of a series.

Example:

// Prints: [1 2 3 4 5]
fmt.Println(Series{1, 2, 3, 4, 5})

func (Series) Sub

func (s Series) Sub(t Series) Series

func (Series) Sub1

func (s Series) Sub1(f float64) Series

func (Series) Tail

func (s Series) Tail(n int) Series

func (Series) Var

func (s Series) Var() float64

func (Series) VarP

func (s Series) VarP() float64

func (Series) WriteFile

func (s Series) WriteFile(path string) error

WriteFile writes the series to a file, where each number is on its own line.

type Time

type Time uint64

I don't want to take along the baggage of a time.Time.

Directories

Path Synopsis
Package dist provides statistical probability distributions for random variables.
Package dist provides statistical probability distributions for random variables.
Package test provides statistical tests, such as the ChiSquaredTest.
Package test provides statistical tests, such as the ChiSquaredTest.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL