descriptive_statistics 2.2.1 → 2.3.0
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/lib/descriptive_statistics/class_methods.rb +23 -1
- data/lib/descriptive_statistics/mean.rb +1 -1
- data/lib/descriptive_statistics/median.rb +1 -1
- data/lib/descriptive_statistics/percentile.rb +1 -1
- data/lib/descriptive_statistics/percentile_rank.rb +1 -1
- data/lib/descriptive_statistics/range.rb +1 -1
- data/lib/descriptive_statistics/standard_deviation.rb +1 -1
- data/lib/descriptive_statistics/sum.rb +1 -1
- data/lib/descriptive_statistics/variance.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1879dad6f99acc6168dc63b2574ca72b3225d05
|
4
|
+
data.tar.gz: 1cc44d9e5259ba71a343556886a0ebc814800475
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af8be7209ff639f578b7ddd01eebcd4149dfe75d94607d99964aafa353823a141737c34852213e46fba62877e36ab22905f768d7b3b2b9d27214c6724e252a58
|
7
|
+
data.tar.gz: 5180ca2d716200159d3843faf882a12ef167020d65dcca31efdf010368318c323538f564ea81d6337e13bcb19069a529c250ec8e637443ed3c0fa8b8d5679b0e
|
@@ -2,12 +2,34 @@ module DescriptiveStatistics
|
|
2
2
|
|
3
3
|
class << self
|
4
4
|
|
5
|
-
|
5
|
+
def empty_collection_default_value
|
6
|
+
@empty_collection_default_value
|
7
|
+
end
|
8
|
+
|
9
|
+
def empty_collection_default_value=(value)
|
10
|
+
@empty_collection_default_value = value
|
11
|
+
DescriptiveStatistics.instance_methods.each { |m| default_values[m] = value }
|
12
|
+
end
|
13
|
+
|
14
|
+
DescriptiveStatistics.instance_methods.each do |m|
|
15
|
+
define_method("#{m}_empty_collection_default_value") do
|
16
|
+
default_values[m]
|
17
|
+
end
|
18
|
+
define_method("#{m}_empty_collection_default_value=") do |value|
|
19
|
+
default_values[m] = value
|
20
|
+
end
|
21
|
+
end
|
6
22
|
|
7
23
|
DescriptiveStatistics.instance_methods.each do |m|
|
8
24
|
define_method(m, DescriptiveStatistics.instance_method(m))
|
9
25
|
end
|
10
26
|
|
27
|
+
private
|
28
|
+
|
29
|
+
def default_values
|
30
|
+
@default_values ||= {}
|
31
|
+
end
|
32
|
+
|
11
33
|
end
|
12
34
|
|
13
35
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DescriptiveStatistics
|
2
2
|
def mean(collection = self)
|
3
3
|
values = Support::convert(collection)
|
4
|
-
return DescriptiveStatistics.
|
4
|
+
return DescriptiveStatistics.mean_empty_collection_default_value unless values.size > 0
|
5
5
|
|
6
6
|
values.sum / values.number
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DescriptiveStatistics
|
2
2
|
def median(collection = self)
|
3
3
|
values = Support::convert(collection)
|
4
|
-
return DescriptiveStatistics.
|
4
|
+
return DescriptiveStatistics.median_empty_collection_default_value unless values.size > 0
|
5
5
|
|
6
6
|
values.percentile(50)
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DescriptiveStatistics
|
2
2
|
def percentile(p, collection = self)
|
3
3
|
values = Support::convert(collection)
|
4
|
-
return DescriptiveStatistics.
|
4
|
+
return DescriptiveStatistics.percentile_empty_collection_default_value unless values.size > 0
|
5
5
|
|
6
6
|
return values.first unless values.size > 1
|
7
7
|
|
@@ -2,7 +2,7 @@ module DescriptiveStatistics
|
|
2
2
|
# percent of cases that are at or below a score
|
3
3
|
def percentile_rank(p, collection = self)
|
4
4
|
values = Support::convert(collection)
|
5
|
-
return DescriptiveStatistics.
|
5
|
+
return DescriptiveStatistics.percentile_rank_empty_collection_default_value unless values.size > 0
|
6
6
|
|
7
7
|
return (((values.sort.rindex{ |x| x <= p } || -1.0) + 1.0)) / values.number * 100.0
|
8
8
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DescriptiveStatistics
|
2
2
|
def range(collection = self)
|
3
3
|
values = Support::convert(collection)
|
4
|
-
return DescriptiveStatistics.
|
4
|
+
return DescriptiveStatistics.range_empty_collection_default_value unless values.size > 0
|
5
5
|
|
6
6
|
values.max - values.min
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DescriptiveStatistics
|
2
2
|
def standard_deviation(collection = self)
|
3
3
|
values = Support::convert(collection)
|
4
|
-
return DescriptiveStatistics.
|
4
|
+
return DescriptiveStatistics.standard_deviation_empty_collection_default_value unless values.size > 0
|
5
5
|
|
6
6
|
Math.sqrt(values.variance)
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DescriptiveStatistics
|
2
2
|
def sum(collection = self)
|
3
3
|
values = Support::convert(collection)
|
4
|
-
return DescriptiveStatistics.
|
4
|
+
return DescriptiveStatistics.sum_empty_collection_default_value unless values.size > 0
|
5
5
|
|
6
6
|
return values.inject(:+)
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DescriptiveStatistics
|
2
2
|
def variance(collection = self)
|
3
3
|
values = Support::convert(collection)
|
4
|
-
return DescriptiveStatistics.
|
4
|
+
return DescriptiveStatistics.variance_empty_collection_default_value unless values.size > 0
|
5
5
|
|
6
6
|
mean = values.mean
|
7
7
|
values.map{ |sample| (mean - sample) ** 2 }.inject(:+) / values.number
|
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: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Parkhurst
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-09-
|
15
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
16
16
|
dependencies: []
|
17
17
|
description: Adds descriptive statistics methods to Enumerable module for use on collections
|
18
18
|
or Numeric data
|