package stats
import "github.com/montanaflynn/stats"
Index ¶
- Variables
- func AutoCorrelation(data Float64Data, lags int) (float64, error)
- func ChebyshevDistance(dataPointX, dataPointY []float64) (distance float64, err error)
- func Correlation(data1, data2 Float64Data) (float64, error)
- func Covariance(data1, data2 Float64Data) (float64, error)
- func CovariancePopulation(data1, data2 Float64Data) (float64, error)
- func CumulativeSum(input Float64Data) ([]float64, error)
- func EuclideanDistance(dataPointX, dataPointY []float64) (distance float64, err error)
- func GeometricMean(input Float64Data) (float64, error)
- func HarmonicMean(input Float64Data) (float64, error)
- func InterQuartileRange(input Float64Data) (float64, error)
- func ManhattanDistance(dataPointX, dataPointY []float64) (distance float64, err error)
- func Max(input Float64Data) (max float64, err error)
- func Mean(input Float64Data) (float64, error)
- func Median(input Float64Data) (median float64, err error)
- func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error)
- func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error)
- func Midhinge(input Float64Data) (float64, error)
- func Min(input Float64Data) (min float64, err error)
- func MinkowskiDistance(dataPointX, dataPointY []float64, lambda float64) (distance float64, err error)
- func Mode(input Float64Data) (mode []float64, err error)
- func Pearson(data1, data2 Float64Data) (float64, error)
- func Percentile(input Float64Data, percent float64) (percentile float64, err error)
- func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error)
- func PopulationVariance(input Float64Data) (pvar float64, err error)
- func Round(input float64, places int) (rounded float64, err error)
- func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error)
- func SampleVariance(input Float64Data) (svar float64, err error)
- func StandardDeviation(input Float64Data) (sdev float64, err error)
- func StandardDeviationPopulation(input Float64Data) (sdev float64, err error)
- func StandardDeviationSample(input Float64Data) (sdev float64, err error)
- func StdDevP(input Float64Data) (sdev float64, err error)
- func StdDevS(input Float64Data) (sdev float64, err error)
- func Sum(input Float64Data) (sum float64, err error)
- func Trimean(input Float64Data) (float64, error)
- func VarP(input Float64Data) (sdev float64, err error)
- func VarS(input Float64Data) (sdev float64, err error)
- func Variance(input Float64Data) (sdev float64, err error)
- type Coordinate
- func ExpReg(s []Coordinate) (regressions []Coordinate, err error)
- func LinReg(s []Coordinate) (regressions []Coordinate, err error)
- func LogReg(s []Coordinate) (regressions []Coordinate, err error)
- type Float64Data
- func LoadRawData(raw interface{}) (f Float64Data)
- func (f Float64Data) AutoCorrelation(lags int) (float64, error)
- func (f Float64Data) Correlation(d Float64Data) (float64, error)
- func (f Float64Data) Covariance(d Float64Data) (float64, error)
- func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error)
- func (f Float64Data) CumulativeSum() ([]float64, error)
- func (f Float64Data) GeometricMean() (float64, error)
- func (f Float64Data) Get(i int) float64
- func (f Float64Data) HarmonicMean() (float64, error)
- func (f Float64Data) InterQuartileRange() (float64, error)
- func (f Float64Data) Len() int
- func (f Float64Data) Less(i, j int) bool
- func (f Float64Data) Max() (float64, error)
- func (f Float64Data) Mean() (float64, error)
- func (f Float64Data) Median() (float64, error)
- func (f Float64Data) MedianAbsoluteDeviation() (float64, error)
- func (f Float64Data) MedianAbsoluteDeviationPopulation() (float64, error)
- func (f Float64Data) Midhinge(d Float64Data) (float64, error)
- func (f Float64Data) Min() (float64, error)
- func (f Float64Data) Mode() ([]float64, error)
- func (f Float64Data) Pearson(d Float64Data) (float64, error)
- func (f Float64Data) Percentile(p float64) (float64, error)
- func (f Float64Data) PercentileNearestRank(p float64) (float64, error)
- func (f Float64Data) PopulationVariance() (float64, error)
- func (f Float64Data) Quartile(d Float64Data) (Quartiles, error)
- func (f Float64Data) QuartileOutliers() (Outliers, error)
- func (f Float64Data) Sample(n int, r bool) ([]float64, error)
- func (f Float64Data) SampleVariance() (float64, error)
- func (f Float64Data) StandardDeviation() (float64, error)
- func (f Float64Data) StandardDeviationPopulation() (float64, error)
- func (f Float64Data) StandardDeviationSample() (float64, error)
- func (f Float64Data) Sum() (float64, error)
- func (f Float64Data) Swap(i, j int)
- func (f Float64Data) Trimean(d Float64Data) (float64, error)
- func (f Float64Data) Variance() (float64, error)
- type Outliers
- type Quartiles
- type Series
Examples ¶
Variables ¶
var ( EmptyInputErr = statsErr{"Input must not be empty."} NaNErr = statsErr{"Not a number."} NegativeErr = statsErr{"Must not contain negative values."} ZeroErr = statsErr{"Must not contain zero values."} BoundsErr = statsErr{"Input is outside of range."} SizeErr = statsErr{"Must be the same length."} InfValue = statsErr{"Value is infinite."} YCoordErr = statsErr{"Y Value must be greater than zero."} )
These are the package-wide error values. All error identification should use these values.
var EmptyInput = EmptyInputErr
EmptyInput legacy error name didn't end with Err
Functions ¶
func AutoCorrelation ¶
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:
Output:Example¶
{
s1 := []float64{1, 2, 3, 4, 5}
a, _ := AutoCorrelation(s1, 1)
fmt.Println(a)
// Output: 0.4
}
0.4
func ChebyshevDistance ¶
ChebyshevDistance computes the Chebyshev distance between two data sets
Code:
Output:Example¶
{
d1 := []float64{2, 3, 4, 5, 6, 7, 8}
d2 := []float64{8, 7, 6, 5, 4, 3, 2}
cd, _ := ChebyshevDistance(d1, d2)
fmt.Println(cd)
// Output: 6
}
6
func Correlation ¶
func Correlation(data1, data2 Float64Data) (float64, error)
Correlation describes the degree of relationship between two sets of data
Code:
Output:Example¶
{
s1 := []float64{1, 2, 3, 4, 5}
s2 := []float64{1, 2, 3, 5, 6}
a, _ := Correlation(s1, s2)
fmt.Println(a)
// Output: 0.9912407071619302
}
0.9912407071619302
func Covariance ¶
func Covariance(data1, data2 Float64Data) (float64, error)
Covariance is a measure of how much two sets of data change
func CovariancePopulation ¶
func CovariancePopulation(data1, data2 Float64Data) (float64, error)
CovariancePopulation computes covariance for entire population between two variables.
func CumulativeSum ¶
func CumulativeSum(input Float64Data) ([]float64, error)
CumulativeSum calculates the cumulative sum of the input slice
func EuclideanDistance ¶
EuclideanDistance computes the Euclidean distance between two data sets
func GeometricMean ¶
func GeometricMean(input Float64Data) (float64, error)
GeometricMean gets the geometric mean for a slice of numbers
func HarmonicMean ¶
func HarmonicMean(input Float64Data) (float64, error)
HarmonicMean gets the harmonic mean for a slice of numbers
func InterQuartileRange ¶
func InterQuartileRange(input Float64Data) (float64, error)
InterQuartileRange finds the range between Q1 and Q3
func ManhattanDistance ¶
ManhattanDistance computes the Manhattan distance between two data sets
func Max ¶
func Max(input Float64Data) (max float64, err error)
Max finds the highest number in a slice
Code:
Output:Example¶
{
d := []float64{1.1, 2.3, 3.2, 4.0, 4.01, 5.09}
a, _ := Max(d)
fmt.Println(a)
// Output: 5.09
}
5.09
func Mean ¶
func Mean(input Float64Data) (float64, error)
Mean gets the average of a slice of numbers
func Median ¶
func Median(input Float64Data) (median float64, err error)
Median gets the median number in a slice of numbers
func MedianAbsoluteDeviation ¶
func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error)
MedianAbsoluteDeviation finds the median of the absolute deviations from the dataset median
func MedianAbsoluteDeviationPopulation ¶
func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error)
MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median
func Midhinge ¶
func Midhinge(input Float64Data) (float64, error)
Midhinge finds the average of the first and third quartiles
func Min ¶
func Min(input Float64Data) (min float64, err error)
Min finds the lowest number in a set of data
Code:
Output:Example¶
{
d := LoadRawData([]interface{}{1.1, "2", 3.0, 4, "5"})
a, _ := Min(d)
fmt.Println(a)
// Output: 1.1
}
1.1
func MinkowskiDistance ¶
func MinkowskiDistance(dataPointX, dataPointY []float64, 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 ¶
func Mode(input Float64Data) (mode []float64, err error)
Mode gets the mode [most frequent value(s)] of a slice of float64s
func Pearson ¶
func Pearson(data1, data2 Float64Data) (float64, error)
Pearson calculates the Pearson product-moment correlation coefficient between two variables
func Percentile ¶
func Percentile(input Float64Data, percent float64) (percentile float64, err error)
Percentile finds the relative standing in a slice of floats
func PercentileNearestRank ¶
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 ¶
func PopulationVariance(input Float64Data) (pvar float64, err error)
PopulationVariance finds the amount of variance within a population
func Round ¶
Round a float to a specific decimal place or precision
func Sample ¶
func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error)
Sample returns sample from input with replacement or without
func SampleVariance ¶
func SampleVariance(input Float64Data) (svar float64, err error)
SampleVariance finds the amount of variance within a sample
func StandardDeviation ¶
func StandardDeviation(input Float64Data) (sdev float64, err error)
StandardDeviation the amount of variation in the dataset
func StandardDeviationPopulation ¶
func StandardDeviationPopulation(input Float64Data) (sdev float64, err error)
StandardDeviationPopulation finds the amount of variation from the population
func StandardDeviationSample ¶
func StandardDeviationSample(input Float64Data) (sdev float64, err error)
StandardDeviationSample finds the amount of variation from a sample
func StdDevP ¶
func StdDevP(input Float64Data) (sdev float64, err error)
StdDevP is a shortcut to StandardDeviationPopulation
func StdDevS ¶
func StdDevS(input Float64Data) (sdev float64, err error)
StdDevS is a shortcut to StandardDeviationSample
func Sum ¶
func Sum(input Float64Data) (sum float64, err error)
Sum adds all the numbers of a slice together
Code:
Output:Example¶
{
d := []float64{1.1, 2.2, 3.3}
a, _ := Sum(d)
fmt.Println(a)
// Output: 6.6
}
6.6
func Trimean ¶
func Trimean(input Float64Data) (float64, error)
Trimean finds the average of the median and the midhinge
func VarP ¶
func VarP(input Float64Data) (sdev float64, err error)
VarP is a shortcut to PopulationVariance
func VarS ¶
func VarS(input Float64Data) (sdev float64, err error)
VarS is a shortcut to SampleVariance
func Variance ¶
func Variance(input Float64Data) (sdev float64, err error)
Variance the amount of variation in the dataset
Types ¶
type Coordinate ¶
type Coordinate struct { X, Y float64 }
Coordinate holds the data in a series
func ExpReg ¶
func ExpReg(s []Coordinate) (regressions []Coordinate, err error)
ExpReg is a shortcut to ExponentialRegression
func LinReg ¶
func LinReg(s []Coordinate) (regressions []Coordinate, err error)
LinReg is a shortcut to LinearRegression
func LogReg ¶
func LogReg(s []Coordinate) (regressions []Coordinate, err error)
LogReg is a shortcut to LogarithmicRegression
type Float64Data ¶
type Float64Data []float64
Float64Data is a named type for []float64 with helper methods
func LoadRawData ¶
func LoadRawData(raw interface{}) (f Float64Data)
LoadRawData parses and converts a slice of mixed data types to floats
func (Float64Data) AutoCorrelation ¶
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 ¶
func (f Float64Data) Correlation(d Float64Data) (float64, error)
Correlation describes the degree of relationship between two sets of data
func (Float64Data) Covariance ¶
func (f Float64Data) Covariance(d Float64Data) (float64, error)
Covariance is a measure of how much two sets of data change
func (Float64Data) CovariancePopulation ¶
func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error)
CovariancePopulation computes covariance for entire population between two variables.
func (Float64Data) CumulativeSum ¶
func (f Float64Data) CumulativeSum() ([]float64, error)
CumulativeSum returns the cumulative sum of the data
func (Float64Data) GeometricMean ¶
func (f Float64Data) GeometricMean() (float64, error)
GeometricMean returns the median of the data
func (Float64Data) Get ¶
func (f Float64Data) Get(i int) float64
Get item in slice
func (Float64Data) HarmonicMean ¶
func (f Float64Data) HarmonicMean() (float64, error)
HarmonicMean returns the mode of the data
func (Float64Data) InterQuartileRange ¶
func (f Float64Data) InterQuartileRange() (float64, error)
InterQuartileRange finds the range between Q1 and Q3
func (Float64Data) Len ¶
func (f Float64Data) Len() int
Len returns length of slice
func (Float64Data) Less ¶
func (f Float64Data) Less(i, j int) bool
Less returns if one number is less than another
func (Float64Data) Max ¶
func (f Float64Data) Max() (float64, error)
Max returns the maximum number in the data
func (Float64Data) Mean ¶
func (f Float64Data) Mean() (float64, error)
Mean returns the mean of the data
func (Float64Data) Median ¶
func (f Float64Data) Median() (float64, error)
Median returns the median of the data
func (Float64Data) MedianAbsoluteDeviation ¶
func (f Float64Data) MedianAbsoluteDeviation() (float64, error)
MedianAbsoluteDeviation the median of the absolute deviations from the dataset median
func (Float64Data) MedianAbsoluteDeviationPopulation ¶
func (f Float64Data) MedianAbsoluteDeviationPopulation() (float64, error)
MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median
func (Float64Data) Midhinge ¶
func (f Float64Data) Midhinge(d Float64Data) (float64, error)
Midhinge finds the average of the first and third quartiles
func (Float64Data) Min ¶
func (f Float64Data) Min() (float64, error)
Min returns the minimum number in the data
func (Float64Data) Mode ¶
func (f Float64Data) Mode() ([]float64, error)
Mode returns the mode of the data
func (Float64Data) Pearson ¶
func (f Float64Data) Pearson(d Float64Data) (float64, error)
Pearson calculates the Pearson product-moment correlation coefficient between two variables.
func (Float64Data) Percentile ¶
func (f Float64Data) Percentile(p float64) (float64, error)
Percentile finds the relative standing in a slice of floats
func (Float64Data) PercentileNearestRank ¶
func (f Float64Data) PercentileNearestRank(p float64) (float64, error)
PercentileNearestRank finds the relative standing using the Nearest Rank method
func (Float64Data) PopulationVariance ¶
func (f Float64Data) PopulationVariance() (float64, error)
PopulationVariance finds the amount of variance within a population
func (Float64Data) Quartile ¶
func (f Float64Data) Quartile(d Float64Data) (Quartiles, error)
Quartile returns the three quartile points from a slice of data
func (Float64Data) QuartileOutliers ¶
func (f Float64Data) QuartileOutliers() (Outliers, error)
QuartileOutliers finds the mild and extreme outliers
func (Float64Data) Sample ¶
func (f Float64Data) Sample(n int, r bool) ([]float64, error)
Sample returns sample from input with replacement or without
func (Float64Data) SampleVariance ¶
func (f Float64Data) SampleVariance() (float64, error)
SampleVariance finds the amount of variance within a sample
func (Float64Data) StandardDeviation ¶
func (f Float64Data) StandardDeviation() (float64, error)
StandardDeviation the amount of variation in the dataset
func (Float64Data) StandardDeviationPopulation ¶
func (f Float64Data) StandardDeviationPopulation() (float64, error)
StandardDeviationPopulation finds the amount of variation from the population
func (Float64Data) StandardDeviationSample ¶
func (f Float64Data) StandardDeviationSample() (float64, error)
StandardDeviationSample finds the amount of variation from a sample
func (Float64Data) Sum ¶
func (f Float64Data) Sum() (float64, error)
Sum returns the total of all the numbers in the data
func (Float64Data) Swap ¶
func (f Float64Data) Swap(i, j int)
Swap switches out two numbers in slice
func (Float64Data) Trimean ¶
func (f Float64Data) Trimean(d Float64Data) (float64, error)
Trimean finds the average of the median and the midhinge
func (Float64Data) Variance ¶
func (f Float64Data) Variance() (float64, error)
Variance the amount of variation in the dataset
type Outliers ¶
type Outliers struct { Mild Float64Data Extreme Float64Data }
Outliers holds mild and extreme outliers found in data
func QuartileOutliers ¶
func QuartileOutliers(input Float64Data) (Outliers, error)
QuartileOutliers finds the mild and extreme outliers
type Quartiles ¶
Quartiles holds the three quartile points
func Quartile ¶
func Quartile(input Float64Data) (Quartiles, error)
Quartile returns the three quartile points from a slice of data
type Series ¶
type Series []Coordinate
Series is a container for a series of data
func ExponentialRegression ¶
ExponentialRegression returns an exponential regression on data series
func LinearRegression ¶
LinearRegression finds the least squares linear regression on data series
Code:
Output:Example¶
{
data := []Coordinate{
{1, 2.3},
{2, 3.3},
{3, 3.7},
}
r, _ := LinearRegression(data)
fmt.Println(r)
// Output: [{1 2.400000000000001} {2 3.1} {3 3.7999999999999994}]
}
[{1 2.400000000000001} {2 3.1} {3 3.7999999999999994}]
func LogarithmicRegression ¶
LogarithmicRegression returns an logarithmic regression on data series
Source Files ¶
correlation.go cumulative_sum.go data.go deviation.go distances.go errors.go legacy.go load.go max.go mean.go median.go min.go mode.go outlier.go percentile.go quartile.go regression.go round.go sample.go sum.go util.go variance.go
Directories ¶
Path | Synopsis |
---|---|
examples |
- Version
- v0.4.0
- Published
- Jan 14, 2019
- Platform
- js/wasm
- Imports
- 5 packages
- Last checked
- now –
Tools for package owners.