A statistics package with common functions that are missing from the Golang standard library.
Clone or download
instance01 and montanaflynn Add CumulativeSum (#40)
* Add CumulativeSum
Latest commit db72e6c Sep 11, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Add CumulativeSum (#40) Sep 11, 2018
.gitignore Re-wrote mode functionality for better performance. Added tests, incl… Oct 21, 2015
.travis.yml Change travis tip alias to master Sep 11, 2018
CHANGELOG.md Release version 0.2.0 Oct 14, 2015
LICENSE Add a standard MIT license file Jul 9, 2015
Makefile Switch default and check targets Oct 15, 2015
README.md Remove deep links to types and functions Jan 4, 2016
correlation.go Consolidated all error values. Dec 4, 2015
correlation_test.go Add unit test for edge case that wasn't covered Jan 3, 2016
cumulative_sum.go Add CumulativeSum (#40) Sep 11, 2018
cumulative_sum_test.go Add CumulativeSum (#40) Sep 11, 2018
data.go Add CumulativeSum (#40) Sep 11, 2018
data_test.go Add CumulativeSum (#40) Sep 11, 2018
deviation.go Annotation spelling error Apr 9, 2016
deviation_test.go Consolidated all error values. Dec 4, 2015
distances.go Add more tests and rename distance files Sep 11, 2018
distances_test.go Add more tests and rename distance files Sep 11, 2018
errors.go Add Chebyshev, Manhattan, Euclidean and Minkowski distance functions (#… Oct 28, 2017
errors_test.go Add unit tests for edge cases that weren't covered Jan 3, 2016
legacy.go Add comments describing functions and structs Aug 22, 2015
legacy_test.go Add Float64Data and Series types Aug 21, 2015
load.go Fix a few lint warnings Sep 11, 2018
load_test.go Add more tests and rename distance files Sep 11, 2018
max.go Consolidated all error values. Dec 4, 2015
max_test.go Improve error log messaging Nov 18, 2015
mean.go Consolidated all error values. Dec 4, 2015
mean_test.go Fix a few lint warnings Sep 11, 2018
median.go Remove unnecessary type conversions Jul 22, 2018
median_test.go Improve error log messaging Nov 18, 2015
min.go Consolidated all error values. Dec 4, 2015
min_test.go Improve error log messaging Nov 18, 2015
mode.go Mode calculation fix and tests Dec 17, 2015
mode_test.go Mode calculation fix and tests Dec 17, 2015
outlier.go Consolidated all error values. Dec 4, 2015
outlier_test.go Split up stats.go into separate files Oct 15, 2015
percentile.go Add more tests and rename distance files Sep 11, 2018
percentile_test.go Add more tests and rename distance files Sep 11, 2018
quartile.go Consolidated all error values. Dec 4, 2015
quartile_test.go Split up stats.go into separate files Oct 15, 2015
regression.go Consolidated all error values. Dec 4, 2015
regression_test.go Split up stats.go into separate files Oct 15, 2015
round.go Consolidated all error values. Dec 4, 2015
round_test.go Refactor testing of Round() Oct 16, 2015
sample.go Consolidated all error values. Dec 4, 2015
sample_test.go Split up stats.go into separate files Oct 15, 2015
sum.go Consolidated all error values. Dec 4, 2015
sum_test.go Split up stats.go into separate files Oct 15, 2015
util.go Re-wrote mode functionality for better performance. Added tests, incl… Oct 21, 2015
util_test.go Re-wrote mode functionality for better performance. Added tests, incl… Oct 21, 2015
variance.go Remove unnecessary type conversions Jul 22, 2018
variance_test.go Consolidated all error values. Dec 4, 2015

README.md

Stats

A statistics package with many functions missing from the Golang standard library. 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

Installation

go get github.com/montanaflynn/stats

Protip: go get -u github.com/montanaflynn/stats updates stats to the latest version.

Usage

The entire API documentation is available on GoDoc.org

You can view docs offline with the following commands:

godoc ./
godoc ./ Median
godoc ./ Float64Data

Protip: Generate HTML docs with godoc -http=:4444

Example

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

Protip: You can call methods on the data if using the Float64Data type:

var d stats.Float64Data = data

max, _ := d.Max()
fmt.Println(max) // 5

Contributing

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 Requests

Pull request are always welcome no matter how big or small. Here's an easy way to do it:

  1. Fork it and clone your fork
  2. Create new branch (git checkout -b some-thing)
  3. Make the desired changes
  4. Ensure tests pass (go test -cover or make test)
  5. Commit changes (git commit -am 'Did something')
  6. Push branch (git push origin some-thing)
  7. 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.

Makefile

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.

MIT License

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.