stats: github.com/montanaflynn/stats Index | Examples | Files | Directories

package stats

import "github.com/montanaflynn/stats"

Package stats is a well tested and comprehensive statistics library package with no dependencies.

Example Usage:

// start with some source data to use
data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8}

// you could also use different types like this
// data := stats.LoadRawData([]int{1, 2, 3, 4, 5})
// data := stats.LoadRawData([]interface{}{1.1, "2", 3})
// etc...

median, _ := stats.Median(data)
fmt.Println(median) // 3.65

roundedMedian, _ := stats.Round(median, 0)
fmt.Println(roundedMedian) // 4

MIT License Copyright (c) 2014-2020 Montana Flynn (https://montanaflynn.com)

Index

Examples

Package Files

correlation.go cumulative_sum.go data.go deviation.go distances.go doc.go entropy.go errors.go legacy.go load.go max.go mean.go median.go min.go mode.go norm.go outlier.go percentile.go quartile.go ranksum.go regression.go round.go sample.go sigmoid.go softmax.go sum.go util.go variance.go

Variables

var (
    // ErrEmptyInput Input must not be empty
    ErrEmptyInput = statsError{"Input must not be empty."}
    // ErrNaN Not a number
    ErrNaN = statsError{"Not a number."}
    // ErrNegative Must not contain negative values
    ErrNegative = statsError{"Must not contain negative values."}
    // ErrZero Must not contain zero values
    ErrZero = statsError{"Must not contain zero values."}
    // ErrBounds Input is outside of range
    ErrBounds = statsError{"Input is outside of range."}
    // ErrSize Must be the same length
    ErrSize = statsError{"Must be the same length."}
    // ErrInfValue Value is infinite
    ErrInfValue = statsError{"Value is infinite."}
    // ErrYCoord Y Value must be greater than zero
    ErrYCoord = statsError{"Y Value must be greater than zero."}
)

These are the package-wide error values. All error identification should use these values. https://github.com/golang/go/wiki/Errors#naming

var (
    EmptyInputErr = ErrEmptyInput
    NaNErr        = ErrNaN
    NegativeErr   = ErrNegative
    ZeroErr       = ErrZero
    BoundsErr     = ErrBounds
    SizeErr       = ErrSize
    InfValue      = ErrInfValue
    YCoordErr     = ErrYCoord
    EmptyInput    = ErrEmptyInput
)

Legacy error names that didn't start with Err

func AutoCorrelation Uses

func AutoCorrelation(data Float64Data, lags int) (float64, error)

AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay

Code:

s1 := []float64{1, 2, 3, 4, 5}
a, _ := stats.AutoCorrelation(s1, 1)
fmt.Println(a)

Output:

0.4

func ChebyshevDistance Uses

func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)

ChebyshevDistance computes the Chebyshev distance between two data sets

Code:

package main

import (
    "fmt"
    "testing"

    "github.com/montanaflynn/stats"
)

type distanceFunctionType func(stats.Float64Data, stats.Float64Data) (float64, error)

var minkowskiDistanceTestMatrix = []struct {
    dataPointX []float64
    dataPointY []float64
    lambda     float64
    distance   float64
}{
    {[]float64{2, 3, 4, 5, 6, 7, 8}, []float64{8, 7, 6, 5, 4, 3, 2}, 1, 24},
    {[]float64{2, 3, 4, 5, 6, 7, 8}, []float64{8, 7, 6, 5, 4, 3, 2}, 2, 10.583005244258363},
    {[]float64{2, 3, 4, 5, 6, 7, 8}, []float64{8, 7, 6, 5, 4, 3, 2}, 99, 6},
}

var distanceTestMatrix = []struct {
    dataPointX       []float64
    dataPointY       []float64
    distance         float64
    distanceFunction distanceFunctionType
}{
    {[]float64{2, 3, 4, 5, 6, 7, 8}, []float64{8, 7, 6, 5, 4, 3, 2}, 6, stats.ChebyshevDistance},
    {[]float64{2, 3, 4, 5, 6, 7, 8}, []float64{8, 7, 6, 5, 4, 3, 2}, 24, stats.ManhattanDistance},
    {[]float64{2, 3, 4, 5, 6, 7, 8}, []float64{8, 7, 6, 5, 4, 3, 2}, 10.583005244258363, stats.EuclideanDistance},
}

func TestDataSetDistances(t *testing.T) {

    // Test Minkowski Distance with different lambda values.
    for _, testData := range minkowskiDistanceTestMatrix {
        distance, err := stats.MinkowskiDistance(testData.dataPointX, testData.dataPointY, testData.lambda)
        if err != nil && distance != testData.distance {
            t.Errorf("Failed to compute Minkowski distance.")
        }

        _, err = stats.MinkowskiDistance([]float64{}, []float64{}, 3)
        if err == nil {
            t.Errorf("Empty slices should have resulted in an error")
        }

        _, err = stats.MinkowskiDistance([]float64{1, 2, 3}, []float64{1, 4}, 3)
        if err == nil {
            t.Errorf("Different length slices should have resulted in an error")
        }

        _, err = stats.MinkowskiDistance([]float64{999, 999, 999}, []float64{1, 1, 1}, 1000)
        if err == nil {
            t.Errorf("Infinite distance should have resulted in an error")
        }
    }

    // Compute distance with the help of all algorithms.
    for _, testSet := range distanceTestMatrix {
        distance, err := testSet.distanceFunction(testSet.dataPointX, testSet.dataPointY)
        if err != nil && testSet.distance != distance {
            t.Errorf("Failed to compute distance.")
        }

        _, err = testSet.distanceFunction([]float64{}, []float64{})
        if err == nil {
            t.Errorf("Empty slices should have resulted in an error")
        }
    }
}

func main() {
    d1 := []float64{2, 3, 4, 5, 6, 7, 8}
    d2 := []float64{8, 7, 6, 5, 4, 3, 2}
    cd, _ := stats.ChebyshevDistance(d1, d2)
    fmt.Println(cd)
}

func Correlation Uses

func Correlation(data1, data2 Float64Data) (float64, error)

Correlation describes the degree of relationship between two sets of data

Code:

s1 := []float64{1, 2, 3, 4, 5}
s2 := []float64{1, 2, 3, 5, 6}
a, _ := stats.Correlation(s1, s2)
fmt.Println(a)

Output:

0.9912407071619302

func Covariance Uses

func Covariance(data1, data2 Float64Data) (float64, error)

Covariance is a measure of how much two sets of data change

func CovariancePopulation Uses

func CovariancePopulation(data1, data2 Float64Data) (float64, error)

CovariancePopulation computes covariance for entire population between two variables.

func CumulativeSum Uses

func CumulativeSum(input Float64Data) ([]float64, error)

CumulativeSum calculates the cumulative sum of the input slice

Code:

data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8}
csum, _ := stats.CumulativeSum(data)
fmt.Println(csum)

Output:

[1 3.1 6.300000000000001 11.123000000000001 15.223 21.023]

func Entropy Uses

func Entropy(input Float64Data) (float64, error)

Entropy provides calculation of the entropy

Code:

d := []float64{1.1, 2.2, 3.3}
e, _ := stats.Entropy(d)
fmt.Println(e)

Output:

1.0114042647073518

func EuclideanDistance Uses

func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)

EuclideanDistance computes the Euclidean distance between two data sets

func GeometricMean Uses

func GeometricMean(input Float64Data) (float64, error)

GeometricMean gets the geometric mean for a slice of numbers

func HarmonicMean Uses

func HarmonicMean(input Float64Data) (float64, error)

HarmonicMean gets the harmonic mean for a slice of numbers

func InterQuartileRange Uses

func InterQuartileRange(input Float64Data) (float64, error)

InterQuartileRange finds the range between Q1 and Q3

func ManhattanDistance Uses

func ManhattanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error)

ManhattanDistance computes the Manhattan distance between two data sets

func Max Uses

func Max(input Float64Data) (max float64, err error)

Max finds the highest number in a slice

Code:

d := []float64{1.1, 2.3, 3.2, 4.0, 4.01, 5.09}
a, _ := stats.Max(d)
fmt.Println(a)

Output:

5.09

func Mean Uses

func Mean(input Float64Data) (float64, error)

Mean gets the average of a slice of numbers

func Median Uses

func Median(input Float64Data) (median float64, err error)

Median gets the median number in a slice of numbers

Code:

data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8}
median, _ := stats.Median(data)
fmt.Println(median)

Output:

3.65

func MedianAbsoluteDeviation Uses

func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error)

MedianAbsoluteDeviation finds the median of the absolute deviations from the dataset median

func MedianAbsoluteDeviationPopulation Uses

func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error)

MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median

func Midhinge Uses

func Midhinge(input Float64Data) (float64, error)

Midhinge finds the average of the first and third quartiles

func Min Uses

func Min(input Float64Data) (min float64, err error)

Min finds the lowest number in a set of data

Code:

d := stats.LoadRawData([]interface{}{1.1, "2", 3.0, 4, "5"})
a, _ := stats.Min(d)
fmt.Println(a)

Output:

1.1

func MinkowskiDistance Uses

func MinkowskiDistance(dataPointX, dataPointY Float64Data, lambda float64) (distance float64, err error)

MinkowskiDistance computes the Minkowski distance between two data sets

Arguments:

dataPointX: First set of data points
dataPointY: Second set of data points. Length of both data
            sets must be equal.
lambda:     aka p or city blocks; With lambda = 1
            returned distance is manhattan distance and
            lambda = 2; it is euclidean distance. Lambda
            reaching to infinite - distance would be chebysev
            distance.

Return:

Distance or error

func Mode Uses

func Mode(input Float64Data) (mode []float64, err error)

Mode gets the mode [most frequent value(s)] of a slice of float64s

func Ncr Uses

func Ncr(n, r int) int

Ncr is an N choose R algorithm. Aaron Cannon's algorithm.

func NormBoxMullerRvs Uses

func NormBoxMullerRvs(loc float64, scale float64, size int) []float64

NormBoxMullerRvs generates random variates using the Box–Muller transform. For more information please visit: http://mathworld.wolfram.com/Box-MullerTransformation.html

func NormCdf Uses

func NormCdf(x float64, loc float64, scale float64) float64

NormCdf is the cumulative distribution function.

func NormEntropy Uses

func NormEntropy(loc float64, scale float64) float64

NormEntropy is the differential entropy of the RV.

func NormFit Uses

func NormFit(data []float64) [2]float64

NormFit returns the maximum likelihood estimators for the Normal Distribution. Takes array of float64 values. Returns array of Mean followed by Standard Deviation.

func NormInterval Uses

func NormInterval(alpha float64, loc float64, scale float64) [2]float64

NormInterval finds endpoints of the range that contains alpha percent of the distribution.

func NormIsf Uses

func NormIsf(p float64, loc float64, scale float64) (x float64)

NormIsf is the inverse survival function (inverse of sf).

func NormLogCdf Uses

func NormLogCdf(x float64, loc float64, scale float64) float64

NormLogCdf is the log of the cumulative distribution function.

func NormLogPdf Uses

func NormLogPdf(x float64, loc float64, scale float64) float64

NormLogPdf is the log of the probability density function.

func NormLogSf Uses

func NormLogSf(x float64, loc float64, scale float64) float64

NormLogSf is the log of the survival function.

func NormMean Uses

func NormMean(loc float64, scale float64) float64

NormMean is the mean/expected value of the distribution.

func NormMedian Uses

func NormMedian(loc float64, scale float64) float64

NormMedian is the median of the distribution.

func NormMoment Uses

func NormMoment(n int, loc float64, scale float64) float64

NormMoment approximates the non-central (raw) moment of order n. For more information please visit: https://math.stackexchange.com/questions/1945448/methods-for-finding-raw-moments-of-the-normal-distribution

func NormPdf Uses

func NormPdf(x float64, loc float64, scale float64) float64

NormPdf is the probability density function.

func NormPpf Uses

func NormPpf(p float64, loc float64, scale float64) (x float64)

NormPpf is the point percentile function. This is based on Peter John Acklam's inverse normal CDF. algorithm: http://home.online.no/~pjacklam/notes/invnorm/ (no longer visible). For more information please visit: https://stackedboxes.org/2017/05/01/acklams-normal-quantile-function/

func NormPpfRvs Uses

func NormPpfRvs(loc float64, scale float64, size int) []float64

NormPpfRvs generates random variates using the Point Percentile Function. For more information please visit: https://demonstrations.wolfram.com/TheMethodOfInverseTransforms/

func NormSf Uses

func NormSf(x float64, loc float64, scale float64) float64

NormSf is the survival function (also defined as 1 - cdf, but sf is sometimes more accurate).

func NormStats Uses

func NormStats(loc float64, scale float64, moments string) []float64

NormStats returns the mean, variance, skew, and/or kurtosis. Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’). Takes string containing any of 'mvsk'. Returns array of m v s k in that order.

func NormStd Uses

func NormStd(loc float64, scale float64) float64

NormStd is the standard deviation of the distribution.

func NormVar Uses

func NormVar(loc float64, scale float64) float64

NormVar is the variance of the distribution.

func Pearson Uses

func Pearson(data1, data2 Float64Data) (float64, error)

Pearson calculates the Pearson product-moment correlation coefficient between two variables

func Percentile Uses

func Percentile(input Float64Data, percent float64) (percentile float64, err error)

Percentile finds the relative standing in a slice of floats

func PercentileNearestRank Uses

func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error)

PercentileNearestRank finds the relative standing in a slice of floats using the Nearest Rank method

func PopulationVariance Uses

func PopulationVariance(input Float64Data) (pvar float64, err error)

PopulationVariance finds the amount of variance within a population

func Round Uses

func Round(input float64, places int) (rounded float64, err error)

Round a float to a specific decimal place or precision

Code:

rounded, _ := stats.Round(1.534424, 1)
fmt.Println(rounded)

Output:

1.5

func Sample Uses

func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error)

Sample returns sample from input with replacement or without

func SampleVariance Uses

func SampleVariance(input Float64Data) (svar float64, err error)

SampleVariance finds the amount of variance within a sample

func Sigmoid Uses

func Sigmoid(input Float64Data) ([]float64, error)

Sigmoid returns the input values in the range of -1 to 1 along the sigmoid or s-shaped curve, commonly used in machine learning while training neural networks as an activation function.

Code:

s, _ := stats.Sigmoid([]float64{3.0, 1.0, 2.1})
fmt.Println(s)

Output:

[0.9525741268224334 0.7310585786300049 0.8909031788043871]

func SoftMax Uses

func SoftMax(input Float64Data) ([]float64, error)

SoftMax returns the input values in the range of 0 to 1 with sum of all the probabilities being equal to one. It is commonly used in machine learning neural networks.

Code:

sm, _ := stats.SoftMax([]float64{3.0, 1.0, 0.2})
fmt.Println(sm)

Output:

[0.8360188027814407 0.11314284146556013 0.05083835575299916]

func StableSample Uses

func StableSample(input Float64Data, takenum int) ([]float64, error)

StableSample like stable sort, it returns samples from input while keeps the order of original data.

func StandardDeviation Uses

func StandardDeviation(input Float64Data) (sdev float64, err error)

StandardDeviation the amount of variation in the dataset

func StandardDeviationPopulation Uses

func StandardDeviationPopulation(input Float64Data) (sdev float64, err error)

StandardDeviationPopulation finds the amount of variation from the population

func StandardDeviationSample Uses

func StandardDeviationSample(input Float64Data) (sdev float64, err error)

StandardDeviationSample finds the amount of variation from a sample

func StdDevP Uses

func StdDevP(input Float64Data) (sdev float64, err error)

StdDevP is a shortcut to StandardDeviationPopulation

func StdDevS Uses

func StdDevS(input Float64Data) (sdev float64, err error)

StdDevS is a shortcut to StandardDeviationSample

func Sum Uses

func Sum(input Float64Data) (sum float64, err error)

Sum adds all the numbers of a slice together

Code:

d := []float64{1.1, 2.2, 3.3}
a, _ := stats.Sum(d)
fmt.Println(a)

Output:

6.6

func Trimean Uses

func Trimean(input Float64Data) (float64, error)

Trimean finds the average of the median and the midhinge

func VarP Uses

func VarP(input Float64Data) (sdev float64, err error)

VarP is a shortcut to PopulationVariance

func VarS Uses

func VarS(input Float64Data) (sdev float64, err error)

VarS is a shortcut to SampleVariance

func Variance Uses

func Variance(input Float64Data) (sdev float64, err error)

Variance the amount of variation in the dataset

type Coordinate Uses

type Coordinate struct {
    X, Y float64
}

Coordinate holds the data in a series

func ExpReg Uses

func ExpReg(s []Coordinate) (regressions []Coordinate, err error)

ExpReg is a shortcut to ExponentialRegression

func LinReg Uses

func LinReg(s []Coordinate) (regressions []Coordinate, err error)

LinReg is a shortcut to LinearRegression

func LogReg Uses

func LogReg(s []Coordinate) (regressions []Coordinate, err error)

LogReg is a shortcut to LogarithmicRegression

type Float64Data Uses

type Float64Data []float64

Float64Data is a named type for []float64 with helper methods

func LoadRawData Uses

func LoadRawData(raw interface{}) (f Float64Data)

LoadRawData parses and converts a slice of mixed data types to floats

Code:

package main

import (
    "fmt"
    "testing"
    "time"

    "github.com/montanaflynn/stats"
)

func main() {
    data := stats.LoadRawData([]interface{}{1.1, "2", 3})
    fmt.Println(data)
}

var allTestData = []struct {
    actual   interface{}
    expected stats.Float64Data
}{
    {
        []interface{}{1.0, "2", 3.0, uint(4), "4.0", 5, time.Duration(6), time.Duration(-7)},
        stats.Float64Data{1.0, 2.0, 3.0, 4.0, 4.0, 5.0, 6.0, -7.0},
    },
    {
        []interface{}{"-345", "223", "-654.4", "194", "898.3"},
        stats.Float64Data{-345.0, 223.0, -654.4, 194.0, 898.3},
    },
    {
        []interface{}{7862, 4234, 9872.1, 8794},
        stats.Float64Data{7862.0, 4234.0, 9872.1, 8794.0},
    },
    {
        []interface{}{true, false, true, false, false},
        stats.Float64Data{1.0, 0.0, 1.0, 0.0, 0.0},
    },
    {
        []interface{}{14.3, 26, 17.7, "shoe"},
        stats.Float64Data{14.3, 26.0, 17.7},
    },
    {
        []bool{true, false, true, true, false},
        stats.Float64Data{1.0, 0.0, 1.0, 1.0, 0.0},
    },
    {
        []float64{10230.9823, 93432.9384, 23443.945, 12374.945},
        stats.Float64Data{10230.9823, 93432.9384, 23443.945, 12374.945},
    },
    {
        []time.Duration{-843, 923, -398, 1000},
        stats.Float64Data{-843.0, 923.0, -398.0, 1000.0},
    },
    {
        []string{"-843.2", "923", "hello", "-398", "1000.5"},
        stats.Float64Data{-843.2, 923.0, -398.0, 1000.5},
    },
    {
        []uint{34, 12, 65, 230, 30},
        stats.Float64Data{34.0, 12.0, 65.0, 230.0, 30.0},
    },
    {
        []uint8{34, 12, 65, 23, 255},
        stats.Float64Data{34.0, 12.0, 65.0, 23.0, 255.0},
    },
    {
        []uint16{34, 12, 65, 230, 65535},
        stats.Float64Data{34.0, 12.0, 65.0, 230.0, 65535.0},
    },
    {
        []uint32{34, 12, 65, 230, 4294967295},
        stats.Float64Data{34.0, 12.0, 65.0, 230.0, 4294967295.0},
    },
    {
        []uint64{34, 12, 65, 230, 18446744073709551615},
        stats.Float64Data{34.0, 12.0, 65.0, 230.0, 18446744073709552000.0},
    },
    {
        []int{-843, 923, -398, 1000},
        stats.Float64Data{-843.0, 923.0, -398.0, 1000.0},
    },
    {
        []int8{-43, 23, -128, 127},
        stats.Float64Data{-43.0, 23.0, -128.0, 127.0},
    },
    {
        []int16{-843, 923, -32768, 32767},
        stats.Float64Data{-843.0, 923.0, -32768.0, 32767.0},
    },
    {
        []int32{-843, 923, -2147483648, 2147483647},
        stats.Float64Data{-843.0, 923.0, -2147483648.0, 2147483647.0},
    },
    {
        []int64{-843, 923, -9223372036854775808, 9223372036854775807, 9223372036854775800},
        stats.Float64Data{-843.0, 923.0, -9223372036854776000.0, 9223372036854776000.0, 9223372036854776000.0},
    },
    {
        map[int]bool{0: true, 1: true, 2: false, 3: true, 4: false},
        stats.Float64Data{1.0, 1.0, 0.0, 1.0, 0.0},
    },
    {
        map[int]float64{0: 68.6, 1: 72.1, 2: -33.3, 3: -99.2},
        stats.Float64Data{68.6, 72.1, -33.3, -99.2},
    },
    {
        map[int]time.Duration{0: -843, 1: 923, 2: -398, 3: 1000},
        stats.Float64Data{-843.0, 923.0, -398.0, 1000.0},
    },
    {
        map[int]string{0: "456", 1: "758", 2: "-9874", 3: "-1981", 4: "68.6", 5: "72.1", 6: "-33.3", 7: "-99.2"},
        stats.Float64Data{456.0, 758.0, -9874.0, -1981.0, 68.6, 72.1, -33.3, -99.2},
    },
    {
        map[int]uint{0: 4567, 1: 7580, 2: 98742, 3: 19817},
        stats.Float64Data{4567.0, 7580.0, 98742.0, 19817.0},
    },
    {
        map[int]uint8{0: 34, 1: 12, 2: 65, 3: 23, 4: 255},
        stats.Float64Data{34.0, 12.0, 65.0, 23.0, 255.0},
    },
    {
        map[int]uint16{0: 34, 1: 12, 2: 65, 3: 230, 4: 65535},
        stats.Float64Data{34.0, 12.0, 65.0, 230.0, 65535.0},
    },
    {
        map[int]uint32{0: 34, 1: 12, 2: 65, 3: 230, 4: 4294967295},
        stats.Float64Data{34.0, 12.0, 65.0, 230.0, 4294967295.0},
    },
    {
        map[int]uint64{0: 34, 1: 12, 2: 65, 3: 230, 4: 18446744073709551615},
        stats.Float64Data{34.0, 12.0, 65.0, 230.0, 18446744073709552000.0},
    },
    {
        map[int]int{0: 456, 1: 758, 2: -9874, 3: -1981},
        stats.Float64Data{456.0, 758.0, -9874.0, -1981.0},
    },
    {
        map[int]int8{0: -43, 1: 23, 2: -128, 3: 127},
        stats.Float64Data{-43.0, 23.0, -128.0, 127.0},
    },
    {
        map[int]int16{0: -843, 1: 923, 2: -32768, 3: 32767},
        stats.Float64Data{-843.0, 923.0, -32768.0, 32767.0},
    },
    {
        map[int]int32{0: -843, 1: 923, 2: -2147483648, 3: 2147483647},
        stats.Float64Data{-843.0, 923.0, -2147483648.0, 2147483647.0},
    },
    {
        map[int]int64{0: -843, 1: 923, 2: -9223372036854775808, 3: 9223372036854775807, 4: 9223372036854775800},
        stats.Float64Data{-843.0, 923.0, -9223372036854776000.0, 9223372036854776000.0, 9223372036854776000.0},
    },
}

func equal(actual, expected stats.Float64Data) bool {
    if len(actual) != len(expected) {
        return false
    }

    for k, actualVal := range actual {
        if actualVal != expected[k] {
            return false
        }
    }

    return true
}

func TestLoadRawData(t *testing.T) {
    for _, data := range allTestData {
        actual := stats.LoadRawData(data.actual)
        if !equal(actual, data.expected) {
            t.Fatalf("Transform(%v). Expected [%v], Actual [%v]", data.actual, data.expected, actual)
        }
    }
}

func (Float64Data) AutoCorrelation Uses

func (f Float64Data) AutoCorrelation(lags int) (float64, error)

AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay

func (Float64Data) Correlation Uses

func (f Float64Data) Correlation(d Float64Data) (float64, error)

Correlation describes the degree of relationship between two sets of data

func (Float64Data) Covariance Uses

func (f Float64Data) Covariance(d Float64Data) (float64, error)

Covariance is a measure of how much two sets of data change

func (Float64Data) CovariancePopulation Uses

func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error)

CovariancePopulation computes covariance for entire population between two variables

func (Float64Data) CumulativeSum Uses

func (f Float64Data) CumulativeSum() ([]float64, error)

CumulativeSum returns the cumulative sum of the data

func (Float64Data) Entropy Uses

func (f Float64Data) Entropy() (float64, error)

Entropy provides calculation of the entropy

func (Float64Data) GeometricMean Uses

func (f Float64Data) GeometricMean() (float64, error)

GeometricMean returns the median of the data

func (Float64Data) Get Uses

func (f Float64Data) Get(i int) float64

Get item in slice

func (Float64Data) HarmonicMean Uses

func (f Float64Data) HarmonicMean() (float64, error)

HarmonicMean returns the mode of the data

func (Float64Data) InterQuartileRange Uses

func (f Float64Data) InterQuartileRange() (float64, error)

InterQuartileRange finds the range between Q1 and Q3

func (Float64Data) Len Uses

func (f Float64Data) Len() int

Len returns length of slice

func (Float64Data) Less Uses

func (f Float64Data) Less(i, j int) bool

Less returns if one number is less than another

func (Float64Data) Max Uses

func (f Float64Data) Max() (float64, error)

Max returns the maximum number in the data

func (Float64Data) Mean Uses

func (f Float64Data) Mean() (float64, error)

Mean returns the mean of the data

func (Float64Data) Median Uses

func (f Float64Data) Median() (float64, error)

Median returns the median of the data

func (Float64Data) MedianAbsoluteDeviation Uses

func (f Float64Data) MedianAbsoluteDeviation() (float64, error)

MedianAbsoluteDeviation the median of the absolute deviations from the dataset median

func (Float64Data) MedianAbsoluteDeviationPopulation Uses

func (f Float64Data) MedianAbsoluteDeviationPopulation() (float64, error)

MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median

func (Float64Data) Midhinge Uses

func (f Float64Data) Midhinge(d Float64Data) (float64, error)

Midhinge finds the average of the first and third quartiles

func (Float64Data) Min Uses

func (f Float64Data) Min() (float64, error)

Min returns the minimum number in the data

func (Float64Data) Mode Uses

func (f Float64Data) Mode() ([]float64, error)

Mode returns the mode of the data

func (Float64Data) Pearson Uses

func (f Float64Data) Pearson(d Float64Data) (float64, error)

Pearson calculates the Pearson product-moment correlation coefficient between two variables.

func (Float64Data) Percentile Uses

func (f Float64Data) Percentile(p float64) (float64, error)

Percentile finds the relative standing in a slice of floats

func (Float64Data) PercentileNearestRank Uses

func (f Float64Data) PercentileNearestRank(p float64) (float64, error)

PercentileNearestRank finds the relative standing using the Nearest Rank method

func (Float64Data) PopulationVariance Uses

func (f Float64Data) PopulationVariance() (float64, error)

PopulationVariance finds the amount of variance within a population

func (Float64Data) Quartile Uses

func (f Float64Data) Quartile(d Float64Data) (Quartiles, error)

Quartile returns the three quartile points from a slice of data

func (Float64Data) QuartileOutliers Uses

func (f Float64Data) QuartileOutliers() (Outliers, error)

QuartileOutliers finds the mild and extreme outliers

func (Float64Data) Sample Uses

func (f Float64Data) Sample(n int, r bool) ([]float64, error)

Sample returns sample from input with replacement or without

func (Float64Data) SampleVariance Uses

func (f Float64Data) SampleVariance() (float64, error)

SampleVariance finds the amount of variance within a sample

func (Float64Data) Sigmoid Uses

func (f Float64Data) Sigmoid() ([]float64, error)

Sigmoid returns the input values along the sigmoid or s-shaped curve

func (Float64Data) SoftMax Uses

func (f Float64Data) SoftMax() ([]float64, error)

SoftMax returns the input values in the range of 0 to 1 with sum of all the probabilities being equal to one.

func (Float64Data) StandardDeviation Uses

func (f Float64Data) StandardDeviation() (float64, error)

StandardDeviation the amount of variation in the dataset

func (Float64Data) StandardDeviationPopulation Uses

func (f Float64Data) StandardDeviationPopulation() (float64, error)

StandardDeviationPopulation finds the amount of variation from the population

func (Float64Data) StandardDeviationSample Uses

func (f Float64Data) StandardDeviationSample() (float64, error)

StandardDeviationSample finds the amount of variation from a sample

func (Float64Data) Sum Uses

func (f Float64Data) Sum() (float64, error)

Sum returns the total of all the numbers in the data

func (Float64Data) Swap Uses

func (f Float64Data) Swap(i, j int)

Swap switches out two numbers in slice

func (Float64Data) Trimean Uses

func (f Float64Data) Trimean(d Float64Data) (float64, error)

Trimean finds the average of the median and the midhinge

func (Float64Data) Variance Uses

func (f Float64Data) Variance() (float64, error)

Variance the amount of variation in the dataset

type Outliers Uses

type Outliers struct {
    Mild    Float64Data
    Extreme Float64Data
}

Outliers holds mild and extreme outliers found in data

func QuartileOutliers Uses

func QuartileOutliers(input Float64Data) (Outliers, error)

QuartileOutliers finds the mild and extreme outliers

type Quartiles Uses

type Quartiles struct {
    Q1  float64
    Q2  float64
    Q3  float64
}

Quartiles holds the three quartile points

func Quartile Uses

func Quartile(input Float64Data) (Quartiles, error)

Quartile returns the three quartile points from a slice of data

type Series Uses

type Series []Coordinate

Series is a container for a series of data

func ExponentialRegression Uses

func ExponentialRegression(s Series) (regressions Series, err error)

ExponentialRegression returns an exponential regression on data series

func LinearRegression Uses

func LinearRegression(s Series) (regressions Series, err error)

LinearRegression finds the least squares linear regression on data series

Code:

data := []stats.Coordinate{
    {1, 2.3},
    {2, 3.3},
    {3, 3.7},
}

r, _ := stats.LinearRegression(data)
fmt.Println(r)

Output:

[{1 2.400000000000001} {2 3.1} {3 3.7999999999999994}]

func LogarithmicRegression Uses

func LogarithmicRegression(s Series) (regressions Series, err error)

LogarithmicRegression returns an logarithmic regression on data series

Directories

PathSynopsis
examples

Package stats imports 6 packages (graph) and is imported by 265 packages. Updated 2020-09-21. Refresh now. Tools for package owners.