descriptive_statistics 1.1.1 → 1.1.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.
@@ -0,0 +1,17 @@
|
|
1
|
+
module DescriptiveStatistics
|
2
|
+
def descriptive_statistics
|
3
|
+
return { :number => self.size.to_f,
|
4
|
+
:sum => self.sum,
|
5
|
+
:variance => self.variance,
|
6
|
+
:standard_deviation => self.standard_deviation,
|
7
|
+
:min => self.min,
|
8
|
+
:max => self.max,
|
9
|
+
:mean => self.mean,
|
10
|
+
:mode => self.mode,
|
11
|
+
:median => self.median,
|
12
|
+
:range => self.range,
|
13
|
+
:q1 => self.percentile(25),
|
14
|
+
:q2 => self.percentile(50),
|
15
|
+
:q3 => self.percentile(75) }
|
16
|
+
end
|
17
|
+
end
|
@@ -6,3 +6,6 @@ require 'descriptive_statistics/mode.rb'
|
|
6
6
|
require 'descriptive_statistics/variance.rb'
|
7
7
|
require 'descriptive_statistics/standard_deviation.rb'
|
8
8
|
require 'descriptive_statistics/percentile.rb'
|
9
|
+
require 'descriptive_statistics/range.rb'
|
10
|
+
require 'descriptive_statistics/descriptive_statistics.rb'
|
11
|
+
|
data/test/test.rb
CHANGED
@@ -56,5 +56,38 @@ class TestData < MiniTest::Unit::TestCase
|
|
56
56
|
assert_equal test_case[0,10].percentile(100).round(6), test_case[25].round(6)
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
60
|
-
|
59
|
+
|
60
|
+
def test_mode
|
61
|
+
assert_equal [1,3,6,9,4,5,2,3,4,1,6,7,8,3,2,3,5,7,8,5,6,5,6,5,4,5,5,5].mode, 5
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_range
|
65
|
+
assert_equal [17, 5, 3, 23, 33, 30, 45, 37].range, 42
|
66
|
+
assert_equal [].range, 0
|
67
|
+
assert_equal [1, 1.0].range, 0
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_descriptive_statistics
|
71
|
+
@data.each do |test_case|
|
72
|
+
stat = test_case[0, 10].descriptive_statistics
|
73
|
+
assert_equal test_case[0, 10].sum, stat[:sum]
|
74
|
+
assert_equal test_case[0, 10].mean, stat[:mean]
|
75
|
+
assert_equal test_case[0, 10].median, stat[:median]
|
76
|
+
assert_equal test_case[0, 10].variance, stat[:variance]
|
77
|
+
assert_equal test_case[0, 10].standard_deviation, stat[:standard_deviation]
|
78
|
+
assert_equal test_case[0, 10].mode, stat[:mode]
|
79
|
+
assert_equal test_case[0, 10].range, stat[:range]
|
80
|
+
assert_equal test_case[0, 10].min, stat[:min]
|
81
|
+
assert_equal test_case[0, 10].max, stat[:max]
|
82
|
+
assert_equal test_case[0, 10].percentile(25), stat[:q1]
|
83
|
+
assert_equal test_case[0, 10].percentile(50), stat[:q2]
|
84
|
+
assert_equal test_case[0, 10].percentile(75), stat[:q3]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_median_is_percentile50
|
89
|
+
@data.each do |test_case|
|
90
|
+
assert_equal test_case[0, 10].median, test_case[0, 10].percentile(50)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: descriptive_statistics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Derrick Parkhurst
|
9
9
|
- Gregory Brown
|
10
10
|
- Daniel Farrell
|
11
|
+
- Graham Malmgren
|
11
12
|
autorequire:
|
12
13
|
bindir: bin
|
13
14
|
cert_chain: []
|
14
|
-
date:
|
15
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
15
16
|
dependencies: []
|
16
17
|
description: Adds descriptive statistics methods to Enumerable for use on collections
|
17
18
|
email: derrick.parkhurst@gmail.com
|
@@ -19,12 +20,14 @@ executables: []
|
|
19
20
|
extensions: []
|
20
21
|
extra_rdoc_files: []
|
21
22
|
files:
|
23
|
+
- lib/descriptive_statistics/descriptive_statistics.rb
|
22
24
|
- lib/descriptive_statistics/enumerable_extension.rb
|
23
25
|
- lib/descriptive_statistics/mean.rb
|
24
26
|
- lib/descriptive_statistics/median.rb
|
25
27
|
- lib/descriptive_statistics/mode.rb
|
26
28
|
- lib/descriptive_statistics/number.rb
|
27
29
|
- lib/descriptive_statistics/percentile.rb
|
30
|
+
- lib/descriptive_statistics/range.rb
|
28
31
|
- lib/descriptive_statistics/safe.rb
|
29
32
|
- lib/descriptive_statistics/standard_deviation.rb
|
30
33
|
- lib/descriptive_statistics/sum.rb
|