statistics

package module
v0.0.0-...-5af75da Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2013 License: GPL-2.0 Imports: 1 Imported by: 5

README

Statistics

Pure Go implementation of the GSL Statistics library.

For the API overview see Godoc.

Note:

An updated version of this package is https://github.com/grd/stat.

API Interfaces:
  • It uses interfaces for the data access. So different data types can be used.
  • Two datatypes are pre-defined: Float64 and Int64.
  • For sampling purposes there is a Strider type provided.

Testing 100% pass. Testing covers the complete functionality.
Tested on Debian6 32-bit and Windows 7 64-bit.

Stable API. I have absolutely no plans in changing the API.

Offtopic:
  • GSL 1.9 Statistics C library: 181 kb, 54 files
  • Go Statistics library : 83 kb, 26 files :-)

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Absdev

func Absdev(data Interface) float64

func AbsdevMean

func AbsdevMean(data Interface, mean float64) float64

AbsdevMean finds the absolute deviation of the data interface

func Covariance

func Covariance(data1, data2 Interface) float64

func CovarianceMean

func CovarianceMean(data1, data2 Interface, mean1, mean2 float64) float64

func Kurtosis

func Kurtosis(data Interface) float64

func KurtosisMainSd

func KurtosisMainSd(data Interface, mean, sd float64) float64

func Lag1Autocorrelation

func Lag1Autocorrelation(data Interface) float64

func Lag1AutocorrelationMean

func Lag1AutocorrelationMean(data Interface, mean float64) float64

func Max

func Max(data Interface) (max float64, max_index int)

Max finds the first largest member and the members position within the data

Example
package main

import (
	"fmt"
	"github.com/grd/statistics"
)

func main() {
	data := statistics.Float64{17.2, 18.1, 16.5, 18.3, 12.6}
	largest, index := statistics.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

func Mean(data Interface) (mean float64)

Mean calculates the arithmetic mean with the recurrence relation

Example
package main

import (
	"fmt"
	"github.com/grd/statistics"
)

func main() {
	data := statistics.Float64{17.2, 18.1, 16.5, 18.3, 12.6}
	mean := statistics.Mean(&data)
	fmt.Printf("The sample mean is %g", mean)
}
Output:

The sample mean is 16.54

func MedianFromSortedData

func MedianFromSortedData(sortedData Interface) (median float64)

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/statistics"
	"sort"
)

func main() {
	data := statistics.Float64{17.2, 18.1, 16.5, 18.3, 12.6}
	sort.Sort(&data)
	median := statistics.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

func Min(data Interface) (min float64, min_index int)

Min finds the first smallest member and the members position within the data

Example
package main

import (
	"fmt"
	"github.com/grd/statistics"
)

func main() {
	data := statistics.Float64{17.2, 18.1, 16.5, 18.3, 12.6}
	smallest, index := statistics.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

func Minmax(data Interface) (min float64, min_index int, max float64, max_index int)

Minmax finds the first smallest and largest members and the members positions within the data

func PVariance

func PVariance(data1, data2 Interface) float64

PVariance finds the pooled variance of two datasets

func QuantileFromSortedData

func QuantileFromSortedData(sortedData Interface, f float64) (result float64)

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/statistics"
	"sort"
)

func main() {
	data := statistics.Float64{17.2, 18.1, 16.5, 18.3, 12.6}
	sort.Sort(&data)
	upperq := statistics.QuantileFromSortedData(&data, 0.75)
	lowerq := statistics.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 Sd

func Sd(data Interface) float64

func SdMean

func SdMean(data Interface, mean float64) float64

func SdWithFixedMean

func SdWithFixedMean(data Interface, mean float64) float64

func Skew

func Skew(data Interface) float64

func SkewMeanSd

func SkewMeanSd(data Interface, mean, sd float64) (skew float64)

SkewMeanSd calculates the skewness of a dataset

func TTest

func TTest(data1, data2 Interface) float64

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

func Variance(data Interface) float64
Example
package main

import (
	"fmt"
	"github.com/grd/statistics"
)

func main() {
	data := statistics.Float64{17.2, 18.1, 16.5, 18.3, 12.6}
	variance := statistics.Variance(&data)
	fmt.Printf("The estimated variance is %.4f", variance)
}
Output:

The estimated variance is 5.3730

func VarianceMean

func VarianceMean(data Interface, mean float64) float64

func VarianceWithFixedMean

func VarianceWithFixedMean(data Interface, mean float64) float64

func WAbsdev

func WAbsdev(w, data Interface) float64

func WAbsdevMean

func WAbsdevMean(w, data Interface, wmean float64) (wabsdev float64)

WAbsdevMean calculates the weighted absolute deviation of a dataset

func WKurtosis

func WKurtosis(w, data Interface) float64

func WKurtosisMeanSd

func WKurtosisMeanSd(w, data Interface, wmean, wsd float64) float64

WKurtosisMean calculates the kurtosis of a dataset

func WMean

func WMean(w, data Interface) (wmean float64)

WMean calculates the weighted arithmetic mean of a dataset

func WSd

func WSd(w, data Interface) float64

func WSdMean

func WSdMean(w, data Interface, wmean float64) float64

func WSkew

func WSkew(w, data Interface) float64

func WSkewMeanSd

func WSkewMeanSd(w, data Interface, wmean, wsd float64) (wskew float64)

Compute the weighted skewness of a dataset

func WVariance

func WVariance(w, data Interface) float64

func WVarianceMean

func WVarianceMean(w, data Interface, wmean float64) float64

func WVarianceWithFixedMean

func WVarianceWithFixedMean(w, data Interface, wmean float64) float64

func WsdWithFixedMean

func WsdWithFixedMean(w, data Interface, wmean float64) float64

Types

type Float64

type Float64 []float64

func (*Float64) Len

func (f *Float64) Len() int

func (*Float64) Less

func (f *Float64) Less(i, j int) bool

func (*Float64) SetValue

func (f *Float64) SetValue(i int, val float64)

func (*Float64) Swap

func (f *Float64) Swap(i, j int)

func (*Float64) Value

func (f *Float64) Value(i int) float64

type Int64

type Int64 []int64

func (*Int64) Len

func (f *Int64) Len() int

func (*Int64) Less

func (f *Int64) Less(i, j int) bool

func (*Int64) SetValue

func (f *Int64) SetValue(i int, value float64)

func (*Int64) Swap

func (f *Int64) Swap(i, j int)

func (*Int64) Value

func (f *Int64) Value(i int) float64

type Interface

type Interface interface {
	Value(int) float64
	SetValue(int, float64)
	Len() int
	Less(int, int) bool
	Swap(int, int)
}

Interface is used throughout the package.

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/statistics"
)

func main() {
	data := statistics.Float64{
		.0421, .0941, .1064, .0242,
		.1331, .0773, .0243, .0815,
		.1186, .0356, .0728, .0999,
		.0614, .0479}
	strider := statistics.NewStrider(&data, 4)
	for i := 0; i < strider.Len(); i++ {
		fmt.Println(strider.Value(i))
	}
}
Output:

0.0421
0.1331
0.1186

func NewStrider

func NewStrider(data Interface, stride int) *Strider
Example
package main

import (
	"fmt"
	"github.com/grd/statistics"
)

func main() {
	data := statistics.Float64{
		.0421, .0941, .1064, .0242,
		.1331, .0773, .0243, .0815,
		.1186, .0356, .0728, .0999,
		.0614, .0479}
	strider := statistics.NewStrider(&data, 4)
	fmt.Printf("mean data is %.4f\n", statistics.Mean(&data))
	fmt.Printf("mean strider is %.4f\n", statistics.Mean(strider))
}
Output:

mean data is 0.0728
mean strider is 0.0979

func (*Strider) Len

func (p *Strider) Len() int

func (*Strider) Less

func (p *Strider) Less(i, j int) bool

func (*Strider) SetValue

func (p *Strider) SetValue(i int, value float64)

func (*Strider) Swap

func (p *Strider) Swap(i, j int)

func (*Strider) Value

func (p *Strider) Value(i int) float64

Jump to

Keyboard shortcuts

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