descriptive-statistics 1.3.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -28,7 +28,7 @@ Or install it yourself as:
28
28
 
29
29
  ### Central Tendency:
30
30
  ```ruby
31
- stats = DescriptiveStatistics.new([1,1,2,3,10])
31
+ stats = DescriptiveStatistics::Stats.new([1,1,2,3,10])
32
32
  stats.mean #=> 3.4
33
33
  stats.median #=> 2
34
34
  stats.mode #=> 1
@@ -36,7 +36,7 @@ stats.mode #=> 1
36
36
 
37
37
  ### Dispersion:
38
38
  ```ruby
39
- stats = DescriptiveStatistics.new([1,1,2,3,10])
39
+ stats = DescriptiveStatistics::Stats.new([1,1,2,3,10])
40
40
  stats.range #=> 9
41
41
  stats.min #=> 1
42
42
  stats.max #=> 10
@@ -46,14 +46,14 @@ stats.value_from_percentile(60) #=> 3
46
46
 
47
47
  ### Spread:
48
48
  ```ruby
49
- stats = DescriptiveStatistics.new([1,1,2,3,10])
49
+ stats = DescriptiveStatistics::Stats.new([1,1,2,3,10])
50
50
  stats.variance #=> 14.299999999999999
51
51
  stats.standard_deviation #=> 3.7815340802378072
52
52
  ```
53
53
 
54
54
  ### Other Measures:
55
55
  ```ruby
56
- stats = DescriptiveStatistics.new([1,1,2,3,10])
56
+ stats = DescriptiveStatistics::Stats.new([1,1,2,3,10])
57
57
  stats.skewness #=> 1.188328915820243
58
58
  stats.kurtosis #=> 2.405613966453127
59
59
  ```
@@ -70,7 +70,7 @@ module Enumerable
70
70
 
71
71
  # Warning: hacky evil meta programming. Required because classes that have already included
72
72
  # Enumerable will not otherwise inherit the statistics methods.
73
- DescriptiveStatistics::AllMethods.instance_methods.each do |m|
73
+ DescriptiveStatistics.instance_methods.each do |m|
74
74
  define_method(m, DescriptiveStatistics::AllMethods.instance_method(m))
75
75
  end
76
76
  end
@@ -5,7 +5,7 @@ require 'descriptive-statistics/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "descriptive-statistics"
8
- gem.version = Descriptive::Statistics::VERSION
8
+ gem.version = DescriptiveStatistics::VERSION
9
9
  gem.authors = ["Julian Tescher"]
10
10
  gem.email = ["virulent@gmail.com"]
11
11
  gem.description = %q{Descriptive Statistics Calculator}
@@ -18,6 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_development_dependency "rspec"
22
- gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "rspec", "~> 2.13.0"
22
+ gem.add_development_dependency "rake", "~> 10.0.3"
23
23
  end
@@ -1,14 +1,7 @@
1
- require 'forwardable'
2
1
  require "descriptive-statistics/version"
3
- require 'descriptive-statistics/all-methods'
2
+ require "descriptive-statistics/all-methods"
3
+ require "descriptive-statistics/stats"
4
4
 
5
- class DescriptiveStatistics
6
- extend Forwardable
7
- include DescriptiveStatistics::AllMethods
8
-
9
- def initialize(data)
10
- @data = data
11
- end
12
-
13
- def_delegators :@data, *(Array.instance_methods - [:object_id, :__id__, :__send__, 'object_id', '__id__', '__send__'])
14
- end
5
+ module DescriptiveStatistics
6
+ include AllMethods
7
+ end
@@ -3,7 +3,7 @@ require 'descriptive-statistics/dispersion'
3
3
  require 'descriptive-statistics/spread'
4
4
  require 'descriptive-statistics/shape'
5
5
 
6
- class DescriptiveStatistics
6
+ module DescriptiveStatistics
7
7
  module AllMethods
8
8
  include CentralTendency
9
9
  include Dispersion
@@ -1,4 +1,4 @@
1
- class DescriptiveStatistics
1
+ module DescriptiveStatistics
2
2
  module CentralTendency
3
3
  def sum(identity = 0, &block)
4
4
  if block_given?
@@ -1,4 +1,4 @@
1
- class DescriptiveStatistics
1
+ module DescriptiveStatistics
2
2
  module Dispersion
3
3
  def range
4
4
  return if length < 1
@@ -1,4 +1,4 @@
1
- class DescriptiveStatistics
1
+ module DescriptiveStatistics
2
2
  module Shape
3
3
 
4
4
  def skewness
@@ -1,4 +1,4 @@
1
- class DescriptiveStatistics
1
+ module DescriptiveStatistics
2
2
  module Spread
3
3
  def variance
4
4
  return if length < 1
@@ -0,0 +1,8 @@
1
+ require 'delegate'
2
+ require "descriptive-statistics/all-methods"
3
+
4
+ module DescriptiveStatistics
5
+ class Stats < SimpleDelegator
6
+ include AllMethods
7
+ end
8
+ end
@@ -1,5 +1,3 @@
1
- module Descriptive
2
- module Statistics
3
- VERSION = "1.3.6"
4
- end
1
+ module DescriptiveStatistics
2
+ VERSION = "2.0.0"
5
3
  end
@@ -2,9 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe DescriptiveStatistics::AllMethods do
4
4
  it 'should include all stats modules' do
5
- [DescriptiveStatistics::Spread, DescriptiveStatistics::Shape, DescriptiveStatistics::Dispersion,
6
- DescriptiveStatistics::CentralTendency].each do |ancestor_module|
7
- DescriptiveStatistics::AllMethods.ancestors.should include(ancestor_module)
8
- end
5
+ DescriptiveStatistics::AllMethods.ancestors.should == [
6
+ DescriptiveStatistics::AllMethods,
7
+ DescriptiveStatistics::Spread,
8
+ DescriptiveStatistics::Shape,
9
+ DescriptiveStatistics::Dispersion,
10
+ DescriptiveStatistics::CentralTendency
11
+ ]
9
12
  end
10
13
  end
@@ -3,49 +3,49 @@ require 'spec_helper'
3
3
  describe DescriptiveStatistics::CentralTendency do
4
4
  describe '#sum' do
5
5
  it 'returns the amount attained by adding all numbers in the array' do
6
- DescriptiveStatistics.new([1,2,6]).sum.should == 9
6
+ DescriptiveStatistics::Stats.new([1,2,6]).sum.should == 9
7
7
  end
8
8
 
9
9
  it 'returns 0 if empty' do
10
- DescriptiveStatistics.new([]).sum.should == 0
10
+ DescriptiveStatistics::Stats.new([]).sum.should == 0
11
11
  end
12
12
  end
13
13
 
14
14
  describe '#mean' do
15
15
  it 'returns the sum of the values over the count of the values' do
16
- DescriptiveStatistics.new([1,2,6]).mean.should == 3
16
+ DescriptiveStatistics::Stats.new([1,2,6]).mean.should == 3
17
17
  end
18
18
 
19
19
  it 'returns nil if empty' do
20
- DescriptiveStatistics.new([]).mean.should be_nil
20
+ DescriptiveStatistics::Stats.new([]).mean.should be_nil
21
21
  end
22
22
  end
23
23
 
24
24
  describe '#median' do
25
25
  it 'returns the value lying at the midpoint of the array' do
26
- DescriptiveStatistics.new([1,2,6]).median.should == 2
26
+ DescriptiveStatistics::Stats.new([1,2,6]).median.should == 2
27
27
  end
28
28
 
29
29
  it 'returns the mean of the two midpoint values if the array length is even' do
30
- DescriptiveStatistics.new([1,2,3,6]).median.should == 2.5
30
+ DescriptiveStatistics::Stats.new([1,2,3,6]).median.should == 2.5
31
31
  end
32
32
 
33
33
  it 'returns nil if empty' do
34
- DescriptiveStatistics.new([]).median.should be_nil
34
+ DescriptiveStatistics::Stats.new([]).median.should be_nil
35
35
  end
36
36
  end
37
37
 
38
38
  describe '#mode' do
39
39
  it 'returns the most frequent value' do
40
- DescriptiveStatistics.new([1,1,2,46]).mode.should == 1
40
+ DescriptiveStatistics::Stats.new([1,1,2,46]).mode.should == 1
41
41
  end
42
42
 
43
43
  it 'returns nil if there is no most frequent value' do
44
- DescriptiveStatistics.new([1,2,3]).mode.should be_nil
44
+ DescriptiveStatistics::Stats.new([1,2,3]).mode.should be_nil
45
45
  end
46
46
 
47
47
  it 'returns nil if empty' do
48
- DescriptiveStatistics.new([]).mode.should be_nil
48
+ DescriptiveStatistics::Stats.new([]).mode.should be_nil
49
49
  end
50
50
  end
51
51
  end
@@ -3,31 +3,31 @@ require 'spec_helper'
3
3
  describe DescriptiveStatistics::Dispersion do
4
4
  describe '#range' do
5
5
  it 'returns the mean squared deviation of the sample (n - 1 denominator)' do
6
- DescriptiveStatistics.new([1,2,6]).range.should == 5
6
+ DescriptiveStatistics::Stats.new([1,2,6]).range.should == 5
7
7
  end
8
8
 
9
9
  it 'returns nil if empty' do
10
- DescriptiveStatistics.new([]).range.should be_nil
10
+ DescriptiveStatistics::Stats.new([]).range.should be_nil
11
11
  end
12
12
  end
13
13
 
14
14
  describe '#min' do
15
15
  it 'delegates to array' do
16
- DescriptiveStatistics.new([1,2,6]).min.should == 1
16
+ DescriptiveStatistics::Stats.new([1,2,6]).min.should == 1
17
17
  end
18
18
 
19
19
  it 'returns nil if empty' do
20
- DescriptiveStatistics.new([]).min.should be_nil
20
+ DescriptiveStatistics::Stats.new([]).min.should be_nil
21
21
  end
22
22
  end
23
23
 
24
24
  describe '#max' do
25
25
  it 'delegates to array' do
26
- DescriptiveStatistics.new([1,2,6]).max.should == 6
26
+ DescriptiveStatistics::Stats.new([1,2,6]).max.should == 6
27
27
  end
28
28
 
29
29
  it 'returns nil if empty' do
30
- DescriptiveStatistics.new([]).max.should be_nil
30
+ DescriptiveStatistics::Stats.new([]).max.should be_nil
31
31
  end
32
32
  end
33
33
 
@@ -35,14 +35,14 @@ describe DescriptiveStatistics::Dispersion do
35
35
  it 'returns the precise percentile of each value' do
36
36
  data = [95.1772, 95.1567, 95.1937, 95.1959, 95.1442, 95.061, 95.1591, 95.1195,95.1065, 95.0925, 95.199, 95.1682]
37
37
  percentiles = [0,9,17,25,34,42,50,59,67,75,84,92]
38
- stats = DescriptiveStatistics.new(data)
38
+ stats = DescriptiveStatistics::Stats.new(data)
39
39
  data.sort.each_with_index do |datum, i|
40
40
  stats.percentile_from_value(datum).should == percentiles[i]
41
41
  end
42
42
  end
43
43
 
44
44
  it 'returns nil if empty' do
45
- DescriptiveStatistics.new([]).percentile_from_value(1).should be_nil
45
+ DescriptiveStatistics::Stats.new([]).percentile_from_value(1).should be_nil
46
46
  end
47
47
  end
48
48
 
@@ -51,14 +51,14 @@ describe DescriptiveStatistics::Dispersion do
51
51
  data = [95.1772, 95.1567, 95.1937, 95.1959, 95.1442, 95.061, 95.1591, 95.1195,95.1065, 95.0925, 95.199, 95.1682]
52
52
  percentiles = [0,10,20,30,40,50,60,70,80,90]
53
53
  values = [95.061,95.1065,95.1195,95.1442,95.1567,95.1591,95.1772,95.1937,95.1959,95.199]
54
- stats = DescriptiveStatistics.new(data)
54
+ stats = DescriptiveStatistics::Stats.new(data)
55
55
  percentiles.sort.each_with_index do |percentile, i|
56
56
  stats.value_from_percentile(percentile).should == values[i]
57
57
  end
58
58
  end
59
59
 
60
60
  it 'returns nil if empty' do
61
- DescriptiveStatistics.new([]).value_from_percentile(1).should be_nil
61
+ DescriptiveStatistics::Stats.new([]).value_from_percentile(1).should be_nil
62
62
  end
63
63
  end
64
64
  end
@@ -3,37 +3,37 @@ require 'spec_helper'
3
3
  describe DescriptiveStatistics::Shape do
4
4
  describe '#skewness' do
5
5
  it 'returns the measure of skewness of the data as close to 0 when not skewed' do
6
- DescriptiveStatistics.new([1,3,5,3,1]).skewness.should == 0.30734449954312965
6
+ DescriptiveStatistics::Stats.new([1,3,5,3,1]).skewness.should == 0.30734449954312965
7
7
  end
8
8
 
9
9
  it 'returns the measure of skewness of the data as high when skewed' do
10
- DescriptiveStatistics.new([50,10,1,1,1]).skewness.should == 1.2374536958450908
10
+ DescriptiveStatistics::Stats.new([50,10,1,1,1]).skewness.should == 1.2374536958450908
11
11
  end
12
12
 
13
13
  it 'returns 0 if only one element' do
14
- DescriptiveStatistics.new([1]).skewness.should == 0
14
+ DescriptiveStatistics::Stats.new([1]).skewness.should == 0
15
15
  end
16
16
 
17
17
  it 'returns nil if empty' do
18
- DescriptiveStatistics.new([]).skewness.should be_nil
18
+ DescriptiveStatistics::Stats.new([]).skewness.should be_nil
19
19
  end
20
20
  end
21
21
 
22
22
  describe '#kurtosis' do
23
23
  it 'returns the measure of kurtosis of the data as close to 0 when not skewed' do
24
- DescriptiveStatistics.new([1,3,5,3,1]).kurtosis.should == 1.477551020408163
24
+ DescriptiveStatistics::Stats.new([1,3,5,3,1]).kurtosis.should == 1.477551020408163
25
25
  end
26
26
 
27
27
  it 'returns the measure of skewness of the data as high when skewed' do
28
- DescriptiveStatistics.new([99,10,1,1,1]).kurtosis.should == 2.56586117539186
28
+ DescriptiveStatistics::Stats.new([99,10,1,1,1]).kurtosis.should == 2.56586117539186
29
29
  end
30
30
 
31
31
  it 'returns 0 if only one element' do
32
- DescriptiveStatistics.new([1]).kurtosis.should == 0
32
+ DescriptiveStatistics::Stats.new([1]).kurtosis.should == 0
33
33
  end
34
34
 
35
35
  it 'returns nil if empty' do
36
- DescriptiveStatistics.new([]).kurtosis.should be_nil
36
+ DescriptiveStatistics::Stats.new([]).kurtosis.should be_nil
37
37
  end
38
38
  end
39
39
  end
@@ -3,41 +3,41 @@ require 'spec_helper'
3
3
  describe DescriptiveStatistics::Spread do
4
4
  describe '#variance' do
5
5
  it 'returns the mean squared deviation of the sample (n - 1 denominator)' do
6
- DescriptiveStatistics.new([1,2,6]).variance.should == 7
6
+ DescriptiveStatistics::Stats.new([1,2,6]).variance.should == 7
7
7
  end
8
8
 
9
9
  it 'returns nil if empty' do
10
- DescriptiveStatistics.new([]).variance.should be_nil
10
+ DescriptiveStatistics::Stats.new([]).variance.should be_nil
11
11
  end
12
12
  end
13
13
 
14
14
  describe '#population_variance' do
15
15
  it 'returns the mean squared deviation of the sample' do
16
- DescriptiveStatistics.new([1,2,3,4]).population_variance.should == 1.25
16
+ DescriptiveStatistics::Stats.new([1,2,3,4]).population_variance.should == 1.25
17
17
  end
18
18
 
19
19
  it 'returns nil if empty' do
20
- DescriptiveStatistics.new([]).population_variance.should be_nil
20
+ DescriptiveStatistics::Stats.new([]).population_variance.should be_nil
21
21
  end
22
22
  end
23
23
 
24
24
  describe '#standard_deviation' do
25
25
  it 'returns the square root of the variance' do
26
- DescriptiveStatistics.new([1,2,6]).standard_deviation.should == 2.6457513110645907
26
+ DescriptiveStatistics::Stats.new([1,2,6]).standard_deviation.should == 2.6457513110645907
27
27
  end
28
28
 
29
29
  it 'returns nil if empty' do
30
- DescriptiveStatistics.new([]).standard_deviation.should be_nil
30
+ DescriptiveStatistics::Stats.new([]).standard_deviation.should be_nil
31
31
  end
32
32
  end
33
33
 
34
34
  describe '#population_standard_deviation' do
35
35
  it 'returns the square root of the population_variance' do
36
- DescriptiveStatistics.new([1,2,6]).population_standard_deviation.should == 2.160246899469287
36
+ DescriptiveStatistics::Stats.new([1,2,6]).population_standard_deviation.should == 2.160246899469287
37
37
  end
38
38
 
39
39
  it 'returns nil if empty' do
40
- DescriptiveStatistics.new([]).population_standard_deviation.should be_nil
40
+ DescriptiveStatistics::Stats.new([]).population_standard_deviation.should be_nil
41
41
  end
42
42
  end
43
43
  end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe DescriptiveStatistics do
4
+ it "should have a VERSION constant" do
5
+ subject.const_get('VERSION').should_not be_empty
6
+ end
7
+ end
@@ -7,7 +7,7 @@ describe DescriptiveStatistics do
7
7
  include DescriptiveStatistics::AllMethods
8
8
 
9
9
  # Warning: hacky evil meta programming. Required to have classes that include array get the methods too.
10
- DescriptiveStatistics::AllMethods.instance_methods.each do |m|
10
+ DescriptiveStatistics.instance_methods.each do |m|
11
11
  define_method(m, DescriptiveStatistics::AllMethods.instance_method(m))
12
12
  end
13
13
  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: 1.3.6
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,40 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-26 00:00:00.000000000 Z
12
+ date: 2013-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 2.13.0
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 2.13.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: 10.0.3
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: 10.0.3
46
46
  description: Descriptive Statistics Calculator
47
47
  email:
48
48
  - virulent@gmail.com
@@ -63,12 +63,14 @@ files:
63
63
  - lib/descriptive-statistics/dispersion.rb
64
64
  - lib/descriptive-statistics/shape.rb
65
65
  - lib/descriptive-statistics/spread.rb
66
+ - lib/descriptive-statistics/stats.rb
66
67
  - lib/descriptive-statistics/version.rb
67
68
  - spec/lib/descriptive-statistics/all_methods_spec.rb
68
69
  - spec/lib/descriptive-statistics/central_tendency_spec.rb
69
70
  - spec/lib/descriptive-statistics/dispersion_spec.rb
70
71
  - spec/lib/descriptive-statistics/shape_spec.rb
71
72
  - spec/lib/descriptive-statistics/spread_spec.rb
73
+ - spec/lib/descriptive-statistics/version_spec.rb
72
74
  - spec/lib/descriptive_statistics_spec.rb
73
75
  - spec/spec_helper.rb
74
76
  homepage: https://github.com/jtescher/descriptive-statistics
@@ -85,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
87
  version: '0'
86
88
  segments:
87
89
  - 0
88
- hash: 91225882488360211
90
+ hash: -3484178174301179474
89
91
  required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  none: false
91
93
  requirements:
@@ -94,10 +96,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  version: '0'
95
97
  segments:
96
98
  - 0
97
- hash: 91225882488360211
99
+ hash: -3484178174301179474
98
100
  requirements: []
99
101
  rubyforge_project:
100
- rubygems_version: 1.8.24
102
+ rubygems_version: 1.8.25
101
103
  signing_key:
102
104
  specification_version: 3
103
105
  summary: Simply calculate descriptive statistics such as measures of central tendency
@@ -109,5 +111,6 @@ test_files:
109
111
  - spec/lib/descriptive-statistics/dispersion_spec.rb
110
112
  - spec/lib/descriptive-statistics/shape_spec.rb
111
113
  - spec/lib/descriptive-statistics/spread_spec.rb
114
+ - spec/lib/descriptive-statistics/version_spec.rb
112
115
  - spec/lib/descriptive_statistics_spec.rb
113
116
  - spec/spec_helper.rb