basic-stats 0.0.1 → 0.0.2
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 +4 -4
- data/.gitignore +1 -0
- data/README.md +8 -3
- data/Rakefile +7 -0
- data/basic-stats.gemspec +1 -0
- data/lib/basic/stats.rb +6 -0
- data/lib/basic/stats/version.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- data/spec/stats_spec.rb +13 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 954cf4ea4a93f8817eb667bbc3f62e26c6cb55e4
|
4
|
+
data.tar.gz: ea1e480076b70cb45b9308b61f20e5e6ee9e6f05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ef5bba7d45c8d599de018be6146d788e01e418721ddc4b77c618bbd239074a430e6e1e6b8cd2368a0ed1cc18f275e1dd46e4cbd4aad39cba6c43c76a159bbef
|
7
|
+
data.tar.gz: 51d0d236cd48d6b36983af55d9e54460842f1a23e441dc8dc80cee86f402ba1f7dace9368bbdcb233a63760ffb58820cd19d07da3ce5413d78123af86465af67
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# Basic::Stats
|
2
|
+
[](http://travis-ci.org/cpetersen/basic-stats)
|
3
|
+
[](https://codeclimate.com/github/cpetersen/basic-stats)
|
4
|
+
[](http://badge.fury.io/rb/basic-stats)
|
2
5
|
|
3
6
|
Basic statistical functions for Ruby collections, such as mean, standard_deviation, z, and outlier detection
|
4
7
|
|
@@ -53,6 +56,8 @@ The Grubb's test does not work well for detecting multiple outliers.
|
|
53
56
|
|
54
57
|
1. Fork it
|
55
58
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
-
3.
|
57
|
-
4.
|
58
|
-
5.
|
59
|
+
3. Make your changes
|
60
|
+
4. Make sure the specs run (`bundle exec rake spec`)
|
61
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
7. Create new Pull Request
|
data/Rakefile
CHANGED
data/basic-stats.gemspec
CHANGED
data/lib/basic/stats.rb
CHANGED
@@ -10,6 +10,12 @@ module Basic
|
|
10
10
|
self.sum/self.length.to_f
|
11
11
|
end
|
12
12
|
|
13
|
+
def median
|
14
|
+
sorted = self.sort
|
15
|
+
len = sorted.length
|
16
|
+
return (sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0
|
17
|
+
end
|
18
|
+
|
13
19
|
def sample_variance
|
14
20
|
m = self.mean
|
15
21
|
sum = self.inject(0){|accum, i| accum +(i-m)**2 }
|
data/lib/basic/stats/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "basic/stats"
|
2
|
+
require "coveralls"
|
2
3
|
|
3
4
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
5
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
@@ -17,3 +18,5 @@ RSpec.configure do |config|
|
|
17
18
|
# --seed 1234
|
18
19
|
config.order = 'random'
|
19
20
|
end
|
21
|
+
|
22
|
+
Coveralls.wear!
|
data/spec/stats_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Basic::Stats do
|
4
|
+
let(:short_array) { [1,2,3].extend Basic::Stats }
|
4
5
|
let(:array) { [1,2,3,4,5,6,7,8,9,10].extend Basic::Stats }
|
5
6
|
let(:array_with_outlier) { [1,2,3,4,5,6,7,8,9,30].extend Basic::Stats }
|
6
7
|
|
@@ -8,6 +9,18 @@ describe Basic::Stats do
|
|
8
9
|
array.mean.should == 5.5
|
9
10
|
end
|
10
11
|
|
12
|
+
it "should have a mean of 5.5" do
|
13
|
+
array.median.should == 5.5
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have a mean of 5.5" do
|
17
|
+
array_with_outlier.median.should == 5.5
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a mean of 2" do
|
21
|
+
short_array.median.should == 2
|
22
|
+
end
|
23
|
+
|
11
24
|
it "should have a standard deviation of 3.02765..." do
|
12
25
|
array.standard_deviation.should == 3.0276503540974917
|
13
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: basic-stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Petersen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|