Documentation
¶
Overview ¶
GNU GSL Statistics library (v1.15, GPLv3) implemented in Go
Index ¶
- func Absdev(data Interface) float64
- func AbsdevMean(data Interface, mean float64) float64
- func Correlation(data1, data2 Interface) (res float64)
- func Covariance(data1, data2 Interface) float64
- func CovarianceMean(data1, data2 Interface, mean1, mean2 float64) float64
- func Kurtosis(data Interface) float64
- func KurtosisMainSd(data Interface, mean, sd float64) float64
- func Lag1Autocorrelation(data Interface) float64
- func Lag1AutocorrelationMean(data Interface, mean float64) float64
- func Max(data Interface) (max float64, max_index int)
- func Mean(data Interface) (mean float64)
- func MedianFromSortedData(sortedData Interface) (median float64)
- func Min(data Interface) (min float64, min_index int)
- func Minmax(data Interface) (min float64, min_index int, max float64, max_index int)
- func PVariance(data1, data2 Interface) float64
- func QuantileFromSortedData(sortedData Interface, f float64) (result float64)
- func Sd(data Interface) float64
- func SdMean(data Interface, mean float64) float64
- func SdWithFixedMean(data Interface, mean float64) float64
- func Skew(data Interface) float64
- func SkewMeanSd(data Interface, mean, sd float64) (skew float64)
- func TTest(data1, data2 Interface) float64
- func Tss(data Interface) float64
- func TssMean(data Interface, mean float64) (res float64)
- func Variance(data Interface) float64
- func VarianceMean(data Interface, mean float64) float64
- func VarianceWithFixedMean(data Interface, mean float64) float64
- func WAbsdev(w, data Interface) float64
- func WAbsdevMean(w, data Interface, wmean float64) (wabsdev float64)
- func WKurtosis(w, data Interface) float64
- func WKurtosisMeanSd(w, data Interface, wmean, wsd float64) float64
- func WMean(w, data Interface) (wmean float64)
- func WSd(w, data Interface) float64
- func WSdMean(w, data Interface, wmean float64) float64
- func WSkew(w, data Interface) float64
- func WSkewMeanSd(w, data Interface, wmean, wsd float64) (wskew float64)
- func WTss(w, data Interface) float64
- func WTssMean(w, data Interface, wmean float64) (res float64)
- func WVariance(w, data Interface) float64
- func WVarianceMean(w, data Interface, wmean float64) float64
- func WVarianceWithFixedMean(w, data Interface, wmean float64) float64
- func WsdWithFixedMean(w, data Interface, wmean float64) float64
- type Float64Slice
- type IntSlice
- type Interface
- type Sort
- type SortStrider
- type Strider
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsdevMean ¶
AbsdevMean finds the absolute deviation of the data interface
func Correlation ¶
Correlation()
Calculate Pearson correlation = cov(X, Y) / (sigma_X * sigma_Y)
This routine efficiently computes the correlation in one pass of the data and makes use of the algorithm described in:
B. P. Welford, "Note on a Method for Calculating Corrected Sums of Squares and Products", Technometrics, Vol 4, No 3, 1962.
This paper derives a numerically stable recurrence to compute a sum of products
S = sum_{i=1..N} [ (x_i - mu_x) * (y_i - mu_y) ]
with the relation
S_n = S_{n-1} + ((n-1)/n) * (x_n - mu_x_{n-1}) * (y_n - mu_y_{n-1})
func Covariance ¶
func CovarianceMean ¶
func KurtosisMainSd ¶
func Lag1Autocorrelation ¶
func Lag1AutocorrelationMean ¶
func Max ¶
Max finds the first largest member and the members position within the data
Example ¶
package main import ( "fmt" "github.com/grd/stat" ) func main() { data := stat.Float64Slice{17.2, 18.1, 16.5, 18.3, 12.6} largest, index := stat.Max(data) fmt.Printf("The largest value is %g and the index is %d", largest, index) }
Output: The largest value is 18.3 and the index is 3
func Mean ¶
Mean calculates the arithmetic mean with the recurrence relation
Example ¶
package main import ( "fmt" "github.com/grd/stat" ) func main() { data := stat.Float64Slice{17.2, 18.1, 16.5, 18.3, 12.6} mean := stat.Mean(data) fmt.Printf("The sample mean is %g", mean) }
Output: The sample mean is 16.54
func MedianFromSortedData ¶
MedianFromSortedData calculates the median of the sorted data. Note that the function doesn't check wheather the data is actually sorted.
Example ¶
package main import ( "fmt" "github.com/grd/stat" "sort" ) func main() { data := stat.Float64Slice{17.2, 18.1, 16.5, 18.3, 12.6} sort.Sort(data) median := stat.MedianFromSortedData(data) fmt.Printf("Sorted dataset: %v\n", data) fmt.Printf("The median is %g\n", median) }
Output: Sorted dataset: [12.6 16.5 17.2 18.1 18.3] The median is 17.2
func Min ¶
Min finds the first smallest member and the members position within the data
Example ¶
package main import ( "fmt" "github.com/grd/stat" ) func main() { data := stat.Float64Slice{17.2, 18.1, 16.5, 18.3, 12.6} smallest, index := stat.Min(data) fmt.Printf("The smallest value is %g and the index is %d", smallest, index) }
Output: The smallest value is 12.6 and the index is 4
func Minmax ¶
Minmax finds the first smallest and largest members and the members positions within the data
func QuantileFromSortedData ¶
QuantileFromSortedData performs the quantile function, also called percent point function or inverse cumulative distribution function, on the sorted data. Note that the function doesn't check wheather the data is actually sorted.
Example ¶
package main import ( "fmt" "github.com/grd/stat" "sort" ) func main() { data := stat.Float64Slice{17.2, 18.1, 16.5, 18.3, 12.6} sort.Sort(data) upperq := stat.QuantileFromSortedData(data, 0.75) lowerq := stat.QuantileFromSortedData(data, 0.25) fmt.Printf("Sorted dataset: %v\n", data) fmt.Printf("The upper quartile is %g\n", upperq) fmt.Printf("The lower quartile is %g\n", lowerq) }
Output: Sorted dataset: [12.6 16.5 17.2 18.1 18.3] The upper quartile is 18.1 The lower quartile is 16.5
func SdWithFixedMean ¶
func SkewMeanSd ¶
SkewMeanSd calculates the skewness of a dataset
func TTest ¶
runs a t-test between two datasets representing independent samples. Tests to see if the difference between means of the samples is different from zero.
func Variance ¶
Example ¶
package main import ( "fmt" "github.com/grd/stat" ) func main() { data := stat.Float64Slice{17.2, 18.1, 16.5, 18.3, 12.6} variance := stat.Variance(data) fmt.Printf("The estimated variance is %.4f", variance) }
Output: The estimated variance is 5.3730
func VarianceMean ¶
func VarianceWithFixedMean ¶
func WAbsdevMean ¶
WAbsdevMean calculates the weighted absolute deviation of a dataset
func WKurtosisMeanSd ¶
WKurtosisMean calculates the kurtosis of a dataset
func WSkewMeanSd ¶
Compute the weighted skewness of a dataset
func WVarianceMean ¶
func WVarianceWithFixedMean ¶
func WsdWithFixedMean ¶
Types ¶
type Float64Slice ¶
type Float64Slice []float64
Float64Slice is a predifined float64 slice type which implements the Interface and Sort interfaces.
func (Float64Slice) Get ¶
func (f Float64Slice) Get(i int) float64
func (Float64Slice) Len ¶
func (f Float64Slice) Len() int
func (Float64Slice) Less ¶
func (f Float64Slice) Less(i, j int) bool
func (Float64Slice) Swap ¶
func (f Float64Slice) Swap(i, j int)
type IntSlice ¶
type IntSlice []int64
IntSlice is a predifined int64 slice type which implements the Interface and Sort interfaces.
type SortStrider ¶
type SortStrider struct { Sort // contains filtered or unexported fields }
SortStrider strides over the data, for sampling purposes. It also has sorting functionality.
func NewSortStrider ¶
func NewSortStrider(data Sort, stride int) SortStrider
func (SortStrider) Get ¶
func (p SortStrider) Get(i int) float64
func (SortStrider) Len ¶
func (p SortStrider) Len() int
func (SortStrider) Less ¶
func (p SortStrider) Less(i, j int) bool
func (SortStrider) Swap ¶
func (p SortStrider) Swap(i, j int)
type Strider ¶
type Strider struct { Interface // contains filtered or unexported fields }
Strider strides over the data, for sampling purposes.
Example ¶
package main import ( "fmt" "github.com/grd/stat" ) func main() { data := stat.Float64Slice{ .0421, .0941, .1064, .0242, .1331, .0773, .0243, .0815, .1186, .0356, .0728, .0999, .0614, .0479} strider := stat.NewStrider(data, 4) for i := 0; i < strider.Len(); i++ { fmt.Println(strider.Get(i)) } }
Output: 0.0421 0.1331 0.1186
func NewStrider ¶
Example ¶
package main import ( "fmt" "github.com/grd/stat" ) func main() { data := stat.Float64Slice{ .0421, .0941, .1064, .0242, .1331, .0773, .0243, .0815, .1186, .0356, .0728, .0999, .0614, .0479} strider := stat.NewStrider(data, 4) fmt.Printf("mean data is %.4f\n", stat.Mean(data)) fmt.Printf("mean strider is %.4f\n", stat.Mean(strider)) }
Output: mean data is 0.0728 mean strider is 0.0979