descriptive_statistics 1.1.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/descriptive_statistics/descriptive_statistics.rb +1 -1
- data/lib/descriptive_statistics/mean.rb +4 -1
- data/lib/descriptive_statistics/median.rb +4 -1
- data/lib/descriptive_statistics/mode.rb +8 -1
- data/lib/descriptive_statistics/number.rb +3 -1
- data/lib/descriptive_statistics/percentile.rb +8 -5
- data/lib/descriptive_statistics/percentile_rank.rb +4 -1
- data/lib/descriptive_statistics/range.rb +4 -2
- data/lib/descriptive_statistics/safe.rb +1 -0
- data/lib/descriptive_statistics/standard_deviation.rb +4 -1
- data/lib/descriptive_statistics/sum.rb +4 -1
- data/lib/descriptive_statistics/support/convert.rb +38 -0
- data/lib/descriptive_statistics/variance.rb +5 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3692ef50fac5b204943e2f89a12954beaf2b8f5e
|
4
|
+
data.tar.gz: 3ebba1de3d2119bc7bd4576e6b31ab12d5e21ce5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dc2caafb81f25a3e4432c2b0ef4c8f373416ed945e2faa153e743bc062210787249770182ec58795571f5935caab4c509a07d2ea435adfa6f61988fb59d5f5f
|
7
|
+
data.tar.gz: 11adc15ecd3ed6220a317d838e88d2b42d271fc8b13153e7de549a38286212ee26262e332fcdfe5884a4e96864bf1556a85bec8f743bac403e950929004f1e08
|
@@ -1,12 +1,15 @@
|
|
1
1
|
module DescriptiveStatistics
|
2
2
|
def percentile(p)
|
3
|
-
|
4
|
-
return
|
5
|
-
|
3
|
+
values = Support::convert(self)
|
4
|
+
return unless values.size > 0
|
5
|
+
|
6
|
+
sorted = values.sort
|
7
|
+
return sorted[-1] if p == 100
|
8
|
+
rank = p / 100.0 * (values.number - 1)
|
6
9
|
lrank = rank.floor
|
7
10
|
d = rank - lrank
|
8
|
-
lower = sorted[lrank]
|
9
|
-
upper = sorted[lrank+1]
|
11
|
+
lower = sorted[lrank]
|
12
|
+
upper = sorted[lrank+1]
|
10
13
|
lower + (upper - lower) * d
|
11
14
|
end
|
12
15
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module DescriptiveStatistics
|
2
2
|
# percent of cases that are at or below a score
|
3
3
|
def percentile_rank(p)
|
4
|
-
|
4
|
+
values = Support::convert(self)
|
5
|
+
return unless values.size > 0
|
6
|
+
|
7
|
+
return (((values.sort.rindex{ |x| x <= p } || -1.0) + 1.0)) / values.number * 100.0
|
5
8
|
end
|
6
9
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module DescriptiveStatistics
|
4
|
+
|
5
|
+
module Support
|
6
|
+
|
7
|
+
def self.convert(from_enumerable)
|
8
|
+
extend to_float to_array from_enumerable
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.extract(from_enumerable)
|
12
|
+
extend to_array from_enumerable
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.extend(enumerable)
|
18
|
+
enumerable.extend(DescriptiveStatistics)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.to_float(enumerable)
|
22
|
+
enumerable.map(&:to_f)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.to_array(enumerable)
|
26
|
+
case enumerable
|
27
|
+
when Hash
|
28
|
+
enumerable.values.each
|
29
|
+
when Set
|
30
|
+
enumerable.to_a.each
|
31
|
+
else
|
32
|
+
enumerable.each
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module DescriptiveStatistics
|
2
2
|
def variance
|
3
|
-
|
4
|
-
|
3
|
+
values = Support::convert(self)
|
4
|
+
return unless values.size > 0
|
5
|
+
|
6
|
+
mean = values.mean
|
7
|
+
values.map{ |sample| (mean - sample) ** 2 }.inject(:+) / values.number
|
5
8
|
end
|
6
9
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: descriptive_statistics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Parkhurst
|
@@ -12,9 +12,10 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-
|
15
|
+
date: 2014-08-30 00:00:00.000000000 Z
|
16
16
|
dependencies: []
|
17
|
-
description: Adds descriptive statistics methods to Enumerable for use on collections
|
17
|
+
description: Adds descriptive statistics methods to Enumerable module for use on collections
|
18
|
+
or Numeric data
|
18
19
|
email: derrick.parkhurst@gmail.com
|
19
20
|
executables: []
|
20
21
|
extensions: []
|
@@ -33,6 +34,7 @@ files:
|
|
33
34
|
- lib/descriptive_statistics/safe.rb
|
34
35
|
- lib/descriptive_statistics/standard_deviation.rb
|
35
36
|
- lib/descriptive_statistics/sum.rb
|
37
|
+
- lib/descriptive_statistics/support/convert.rb
|
36
38
|
- lib/descriptive_statistics/variance.rb
|
37
39
|
homepage: https://github.com/thirtysixthspan/descriptive_statistics
|
38
40
|
licenses:
|