Giter Site home page Giter Site logo

leereilly / descriptive-statistics Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jtescher/descriptive-statistics

0.0 2.0 0.0 92 KB

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).

Home Page: http://rubygems.org/gems/descriptive-statistics

License: MIT License

descriptive-statistics's Introduction

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, ruby-head, jruby-18mode, jruby-19mode, jruby-head, rbx-18mode, rbx-19mode, and ree

[Build Status] (http://travis-ci.org/jtescher/descriptive-statistics) Dependency Status Code Climate

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.new([1,1,2,3,10])
stats.mean #=> 3.4
stats.median #=> 2
stats.mode #=> 1

Dispersion:

stats = DescriptiveStatistics.new([1,1,2,3,10])
stats.range #=> 9
stats.min #=> 1
stats.max #=> 10
stats.percentile_from_value(10) #=> 80
stats.value_from_percentile(60) #=> 3

Spread:

stats = DescriptiveStatistics.new([1,1,2,3,10])
stats.variance #=> 14.299999999999999
stats.standard_deviation #=> 3.7815340802378072

Other Measures:

stats = DescriptiveStatistics.new([1,1,2,3,10])
stats.skewness #=> 1.188328915820243
stats.kurtosis #=> 2.405613966453127

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::AllMethods

  # Warning: hacky evil meta programming. Required because classes that have already included
  # Enumerable will not otherwise inherit the statistics methods.
  DescriptiveStatistics::AllMethods.instance_methods.each do |m|
    define_method(m, DescriptiveStatistics::AllMethods.instance_method(m))
  end
end

Then you can use these methods directly on Arrays:

[1,1,2,3,10].mean #=> 3.4

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.