rstat 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.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.0.2
2
+
3
+ * Added standard deviation.
4
+
1
5
  ## v0.0.1
2
6
 
3
7
  * Initial release.
data/README.md CHANGED
@@ -3,3 +3,10 @@
3
3
  A very simple gem that adds some statistics methods to the core Array class.
4
4
 
5
5
  Maybe in the future it will be something more.
6
+
7
+ Currently adds:
8
+
9
+ * Mean
10
+ * Median
11
+ * Mode
12
+ * Variance / Standard Deviation
@@ -1,3 +1,4 @@
1
1
  require "rstat/core_ext/array/mean"
2
2
  require "rstat/core_ext/array/median"
3
3
  require "rstat/core_ext/array/mode"
4
+ require "rstat/core_ext/array/standard_deviation"
@@ -0,0 +1,15 @@
1
+ class Array
2
+ def variance
3
+ mean = self.mean
4
+
5
+ (1.0 / self.length) * self.map{|x| (x - mean) ** 2}.inject(:+)
6
+ end
7
+
8
+ def standard_deviation
9
+ Math.sqrt(self.variance)
10
+ end
11
+
12
+ def std_dev
13
+ self.standard_deviation
14
+ end
15
+ end
data/lib/rstat/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rstat
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -74,4 +74,14 @@ describe Rstat do
74
74
  [44, 45, 46, 44, 46, 50].mode.should eql([44, 46])
75
75
  end
76
76
  end
77
+
78
+ describe ".standard_deviation" do
79
+ it "calculates the variance of an array" do
80
+ [1, 2, 3, 4, 5, 6].variance.should be_within(0.00001).of(2.91667)
81
+ end
82
+
83
+ it "calculates the standard deviation of an array" do
84
+ [1, 2, 3, 4, 5, 6].standard_deviation.should be_within(0.00001).of(1.70783)
85
+ end
86
+ end
77
87
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rstat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Eshbaugh
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-24 00:00:00 -05:00
18
+ date: 2012-03-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -53,6 +53,7 @@ files:
53
53
  - lib/rstat/core_ext/array/mean.rb
54
54
  - lib/rstat/core_ext/array/median.rb
55
55
  - lib/rstat/core_ext/array/mode.rb
56
+ - lib/rstat/core_ext/array/standard_deviation.rb
56
57
  - lib/rstat/version.rb
57
58
  - rstat.gemspec
58
59
  - spec/rstat/array_spec.rb