descriptive-statistics 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -44,6 +44,12 @@ stats.variance #=> 14.299999999999999
44
44
  stats.standard_deviation #=> 3.7815340802378072
45
45
  ```
46
46
 
47
+ ### Other Measures:
48
+ ```ruby
49
+ stats = DescriptiveStatistics.new([1,1,2,3,10]).skewness #=> 1.188328915820243
50
+ stats = DescriptiveStatistics.new([1,1,2,3,10]).kurtosis #=> 2.405613966453127
51
+ ```
52
+
47
53
  ## Contributing
48
54
 
49
55
  1. Fork it
@@ -2,16 +2,18 @@ require "descriptive-statistics/version"
2
2
  require 'descriptive-statistics/central-tendency'
3
3
  require 'descriptive-statistics/dispersion'
4
4
  require 'descriptive-statistics/spread'
5
+ require 'descriptive-statistics/shape'
5
6
 
6
7
  class DescriptiveStatistics
7
8
  extend Forwardable
8
9
  include CentralTendency
9
10
  include Dispersion
10
11
  include Spread
12
+ include Shape
11
13
 
12
14
  def initialize(data)
13
15
  @data = data
14
16
  end
15
17
 
16
- def_delegators :@data, :length, :inject, :sort, :each_with_object
18
+ def_delegators :@data, :length, :inject, :sort, :each, :each_with_object
17
19
  end
@@ -0,0 +1,17 @@
1
+ class DescriptiveStatistics
2
+ module Shape
3
+ def skewness
4
+ return if length < 1
5
+ sum_cubed_deviation = inject(0) {|sum, value| sum + (value - mean) ** 3}
6
+ cubed_standard_deviation = standard_deviation ** 3
7
+ sum_cubed_deviation / ((length - 1) * cubed_standard_deviation.to_f)
8
+ end
9
+
10
+ def kurtosis
11
+ return if length < 1
12
+ sum_quarted_deviation = inject(0) {|sum, value| sum + (value - mean) ** 4}
13
+ quarted_standard_deviation = standard_deviation ** 4
14
+ sum_quarted_deviation / ((length - 1) * quarted_standard_deviation.to_f)
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  module Descriptive
2
2
  module Statistics
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe DescriptiveStatistics::Shape do
4
+ describe '#skewness' do
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
7
+ end
8
+
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
11
+ end
12
+
13
+ it 'returns nil if empty' do
14
+ DescriptiveStatistics.new([]).skewness.should be_nil
15
+ end
16
+ end
17
+
18
+ describe '#kurtosis' do
19
+ it 'returns the measure of kurtosis of the data as close to 0 when not skewed' do
20
+ DescriptiveStatistics.new([1,3,5,3,1]).kurtosis.should == 1.477551020408163
21
+ end
22
+
23
+ it 'returns the measure of skewness of the data as high when skewed' do
24
+ DescriptiveStatistics.new([50,10,1,1,1]).kurtosis.should == 2.45740139974872
25
+ end
26
+
27
+ it 'returns nil if empty' do
28
+ DescriptiveStatistics.new([]).kurtosis.should be_nil
29
+ end
30
+ end
31
+ 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.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -60,10 +60,12 @@ files:
60
60
  - lib/descriptive-statistics.rb
61
61
  - lib/descriptive-statistics/central-tendency.rb
62
62
  - lib/descriptive-statistics/dispersion.rb
63
+ - lib/descriptive-statistics/shape.rb
63
64
  - lib/descriptive-statistics/spread.rb
64
65
  - lib/descriptive-statistics/version.rb
65
66
  - spec/lib/descriptive-statistics/central_tendency_spec.rb
66
67
  - spec/lib/descriptive-statistics/dispersion_spec.rb
68
+ - spec/lib/descriptive-statistics/shape_spec.rb
67
69
  - spec/lib/descriptive-statistics/spread_spec.rb
68
70
  - spec/spec_helper.rb
69
71
  homepage: https://github.com/jtescher/descriptive-statistics
@@ -80,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
82
  version: '0'
81
83
  segments:
82
84
  - 0
83
- hash: -2781553124124914132
85
+ hash: -3386825229431147433
84
86
  required_rubygems_version: !ruby/object:Gem::Requirement
85
87
  none: false
86
88
  requirements:
@@ -89,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
91
  version: '0'
90
92
  segments:
91
93
  - 0
92
- hash: -2781553124124914132
94
+ hash: -3386825229431147433
93
95
  requirements: []
94
96
  rubyforge_project:
95
97
  rubygems_version: 1.8.24
@@ -100,5 +102,6 @@ summary: Simply calculate measures of central tendency (e.g. mean, median mode),
100
102
  test_files:
101
103
  - spec/lib/descriptive-statistics/central_tendency_spec.rb
102
104
  - spec/lib/descriptive-statistics/dispersion_spec.rb
105
+ - spec/lib/descriptive-statistics/shape_spec.rb
103
106
  - spec/lib/descriptive-statistics/spread_spec.rb
104
107
  - spec/spec_helper.rb