statistiks 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 00ae3aa625a9d581629314658202bf417bb01cee
4
+ data.tar.gz: 85978de912fcdbe7120071b48c4b9159fbed5212
5
+ SHA512:
6
+ metadata.gz: 01e58f0aeb5b66d3546f9f2b391be3f46d60430f4872cd2c86511282efcd7ff11d0397645b07ce8eb9b39577971957de327cd668c5e950db49afdd5309bbb01d
7
+ data.tar.gz: f3ee09dc1657048bbca5ee2555612d0c1e724f08ca9e0edf5de3fbb651f779cc4dbd13776b83afb16b9b350439b934c508e567eb7f0f297031e95f9d563c4445
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in statistiks.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 João Daniel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Statistiks
2
+
3
+ Statistiks is a suite of statistical tools for Ruby language
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'statistiks'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install statistiks
20
+
21
+ ## Usage
22
+
23
+ ### Array methods
24
+
25
+ Sum
26
+
27
+ ```ruby
28
+ [1,2,3,4,5].sum
29
+ => 15.0
30
+ ```
31
+
32
+ Mean
33
+
34
+ ```ruby
35
+ [1,2,3,4,5].mean
36
+ => 3.0
37
+ ```
38
+
39
+ Variance
40
+
41
+ ```ruby
42
+ [1,2,3,4,5].variance
43
+ => 2.5
44
+ ```
45
+
46
+ Standard deviation
47
+
48
+ ```ruby
49
+ [1,2,3,4,5].sd
50
+ => 1.58114
51
+ ```
52
+
53
+ Median
54
+
55
+ ```ruby
56
+ [1,2,3,4,5,6,7,8,9,10].median
57
+ => 3.0
58
+ ```
59
+
60
+ Quartiles
61
+
62
+ ```ruby
63
+ [1,2,3,4,5,6,7,8,9,10].quartiles
64
+ => [3.0, 5.0, 8.0]
65
+ ```
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it ( https://github.com/jdanielnd/statistiks/fork )
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
4
+
data/lib/statistiks.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "statistiks/version"
2
+ require "statistiks/array"
3
+
4
+ module Statistiks
5
+ end
@@ -0,0 +1,5 @@
1
+ require "statistiks/array/sum"
2
+ require "statistiks/array/mean"
3
+ require "statistiks/array/variance"
4
+ require "statistiks/array/sd"
5
+ require "statistiks/array/percentile"
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def mean(round = 5)
3
+ (self.sum.to_f/self.length).round(round)
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ class Array
2
+ def percentile(p)
3
+ if p < 0 || p > 100
4
+ nil
5
+ else
6
+ self.sort[((p.to_f / 100.0) * self.length.to_f) - 0.5]
7
+ end
8
+ end
9
+
10
+ def median
11
+ self.percentile(50)
12
+ end
13
+
14
+ def quartiles
15
+ [self.percentile(25), self.percentile(50), self.percentile(75)]
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def sd(round = 5)
3
+ Math.sqrt(self.variance).round(round)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def sum(round = 5)
3
+ self.inject(:+).round(round)
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class Array
2
+ def variance(round = 5)
3
+ mean = self.mean
4
+ ((1.0/(self.length - 1))*self.map{ |x| (x - mean)**2 }.sum).round(round)
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Statistiks
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'statistiks'
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Statistiks do
4
+
5
+ describe 'Array#sum' do
6
+ it "should return correct sum" do
7
+ expect([1, 2, 3, 4, 5].sum).to eq 15.0
8
+ end
9
+ end
10
+
11
+ describe 'Array#mean' do
12
+ it "should return correct mean" do
13
+ expect([1, 2, 3, 4, 5].mean).to eq 3.0
14
+ end
15
+ end
16
+
17
+ describe 'Array#variance' do
18
+ it "should return correct variance" do
19
+ expect([1, 2, 3, 4, 5].variance).to eq 2.5
20
+ end
21
+ end
22
+
23
+ describe 'Array#sd' do
24
+ it "should return correct sd" do
25
+ expect([1, 2, 3, 4, 5].sd).to eq 1.58114
26
+ end
27
+ end
28
+
29
+ describe 'Array#percentile' do
30
+ it "should return correct percentile" do
31
+ expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10].percentile(25)).to eq 3.0
32
+ end
33
+
34
+ it "should return correct median" do
35
+ expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10].median).to eq 5.0
36
+ end
37
+
38
+ it "should return correct quartiles" do
39
+ expect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10].quartiles).to eq [3.0, 5.0, 8.0]
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statistiks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "statistiks"
8
+ spec.version = Statistiks::VERSION
9
+ spec.authors = ["João Daniel"]
10
+ spec.email = ["jdanielnd@gmail.com"]
11
+ spec.summary = "Statistical tools for Ruby"
12
+ spec.description = "A suite of statistical tools for Ruby language"
13
+ spec.homepage = "https://github.com/jdanielnd/statistiks"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency 'rspec', "~> 3.1.0"
24
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,3 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statistiks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - João Daniel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ description: A suite of statistical tools for Ruby language
56
+ email:
57
+ - jdanielnd@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/statistiks.rb
68
+ - lib/statistiks/array.rb
69
+ - lib/statistiks/array/mean.rb
70
+ - lib/statistiks/array/percentile.rb
71
+ - lib/statistiks/array/sd.rb
72
+ - lib/statistiks/array/sum.rb
73
+ - lib/statistiks/array/variance.rb
74
+ - lib/statistiks/version.rb
75
+ - spec/spec_helper.rb
76
+ - spec/statistiks_spec.rb
77
+ - statistiks.gemspec
78
+ - tasks/rspec.rake
79
+ homepage: https://github.com/jdanielnd/statistiks
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.2.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Statistical tools for Ruby
103
+ test_files:
104
+ - spec/spec_helper.rb
105
+ - spec/statistiks_spec.rb