rstat 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.0.4
2
+
3
+ * Added percentile.
4
+ * Added interquartile range.
5
+
1
6
  ## v0.0.3
2
7
 
3
8
  * Better mode algorithm.
@@ -0,0 +1,25 @@
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 interquartile_range
11
+ self.percentile(75) - self.percentile(25)
12
+ end
13
+
14
+ def iqr
15
+ self.interquartile_range
16
+ end
17
+
18
+ def midspread
19
+ self.interquartile_range
20
+ end
21
+
22
+ def middle_fifty
23
+ self.interquartile_range
24
+ end
25
+ end
data/lib/rstat/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rstat
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -106,4 +106,22 @@ describe Rstat do
106
106
  [1, 2, 3, 4, 5, 6].coefficient_of_variation.should be_within(0.00001).of(0.48795)
107
107
  end
108
108
  end
109
+
110
+ describe ".percentile" do
111
+ it "finds the 30th percentile of an array" do
112
+ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].percentile(30).should be(3)
113
+ end
114
+
115
+ it "finds the 50th percentile of an array" do
116
+ [1, 2, 3, 4, 5].percentile(50).should be(3)
117
+ end
118
+
119
+ it "finds the 10th percentile of an array" do
120
+ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17].percentile(10).should be(2)
121
+ end
122
+
123
+ it "finds the interquartile range of an array" do
124
+ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].interquartile_range.should be(5)
125
+ end
126
+ end
109
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rstat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -46,6 +46,7 @@ files:
46
46
  - lib/rstat/core_ext/array/mean.rb
47
47
  - lib/rstat/core_ext/array/median.rb
48
48
  - lib/rstat/core_ext/array/mode.rb
49
+ - lib/rstat/core_ext/array/percentile.rb
49
50
  - lib/rstat/core_ext/array/product.rb
50
51
  - lib/rstat/core_ext/array/range.rb
51
52
  - lib/rstat/core_ext/array/standard_deviation.rb