DescriptiveStatistics
This gem calculates descriptive statistics including measures of central tendency (e.g. mean, median mode), dispersion
(e.g. range, and quartiles), and spread (e.g variance and standard deviation).
Tested against ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1.0, ruby-head, jruby-18mode, jruby-19mode, jruby-head, rbx-2.1.1,
rbx-2.2.0, rbx-2.2.1 and ree
Installation
Add this line to your application's Gemfile:
gem 'descriptive-statistics'
And then execute:
$ bundle
Or install it yourself as:
$ gem install descriptive-statistics
Usage
Central Tendency:
stats = DescriptiveStatistics::Stats.new([1,1,2,3,10])
stats.mean
stats.median
stats.mode
Dispersion:
stats = DescriptiveStatistics::Stats.new([1,1,2,3,10])
stats.range
stats.min
stats.max
stats.percentile_from_value(10)
stats.value_from_percentile(60)
Spread:
stats = DescriptiveStatistics::Stats.new([1,1,2,3,10])
stats.variance
stats.population_variance
stats.standard_deviation
stats.relative_standard_deviation
Other Measures:
stats = DescriptiveStatistics::Stats.new([1,1,2,3,10])
stats.skewness
stats.kurtosis
Alternative Usage (Not suggested)
If you want to monkey patch descriptive statistics methods into Enumerable, you can use the following:
(e.g. config/initializers/descriptive_statistics_monkey_patch.rb)
require 'descriptive-statistics'
module Enumerable
include DescriptiveStatistics
DescriptiveStatistics.instance_methods.each do |m|
define_method(m, DescriptiveStatistics.instance_method(m))
end
end
Then you can use these methods directly on Arrays:
[1,1,2,3,10].mean
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request