A statistics package with many functions missing from the Golang standard library.
Currently only float64
and []float64
data is supported due to the lack of generics. However, if the library becomes popular and there is demand I could also add support for the other number types. See the CHANGELOG.md for API changes and tagged releases you can vendor into your projects.
Statistics are used much like a drunk uses a lamppost: for support, not illumination. - Vin Scully
go get github.com/montanaflynn/stats
Protip: go get -u github.com/montanaflynn/stats
updates stats to the latest version.
All the functions can be seen in examples/main.go but here's a little taste:
// start with the some source data to use
var data = []float64{1, 2, 3, 4, 4, 5}
median, _ := stats.Median(data)
fmt.Println(median) // 3.5
roundedMedian, _ := stats.Round(median, 0)
fmt.Println(roundedMedian) // 4
You can call methods directly on the data (example) if using the Float64Data type.
var d stats.Float64Data = data
max, _ := d.Max()
fmt.Println(max) // 5
Protip: See all the available methods for Float64Data with godoc ./ Float64Data
The entire API documentation is available on GoDoc.org
Types: Float64Data
, Series
, Coordinate
, Quartiles
, Outliers
Functions: Min
, Max
, Sum
, Mean
, Median
, Mode
, Sample
, Round
, MedianAbsoluteDeviation
, MedianAbsoluteDeviationPopulation
, StandardDeviation
, StandardDeviationPopulation
, StandardDeviationSample
, Percentile
, PercentileNearestRank
, LinearRegression
, ExponentialRegression
, LogarithmicRegression
, Variance
, PopulationVariance
, SampleVariance
, Quartile
, InterQuartileRange
, Midhinge
, Trimean
, QuartileOutliers
, GeometricMean
, HarmonicMean
, Covariance
, CovariancePopulation
, Correlation
You can view docs offline with the following commands:
godoc ./
godoc ./ Median
godoc ./ Outliers
Protip: Generate HTML docs with godoc -http=:4444
If you have any suggestions, criticism or bug reports please create an issue and I'll do my best to accommodate you. In addition simply starring the repo would show your support for the project and be very much appreciated!
Pull request are always welcome no matter how big or small. Here's an easy way to do it:
- Fork it and clone your fork
- Create new branch (
git checkout -b some-thing
) - Make the desired changes
- Ensure tests pass (
go test -cover
ormake test
) - Commit changes (
git commit -am 'Did something'
) - Push branch (
git push origin some-thing
) - Submit pull request
To make things as seamless as possible please also consider the following steps:
- Update
README.md
to include new public types or functions in the documentation section. - Update
examples/main.go
with a simple example of the new feature. - Keep 100% code coverage (you can check with
make coverage
). - Run
gometalinter
and make your code pass. - Squash needless commits into single units of work with
git rebase -i new-feature
.
I've included a Makefile that has a lot of helper targets for common actions such as linting, testing, code coverage reporting and more.
Protip: watch -n 1 make check
will continuously format and test your code.
Copyright (c) 2014-2015 Montana Flynn http://anonfunction.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORpublicS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.