lite-statistics 1.0.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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.fasterer.yml +19 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +4 -0
  5. data/.rubocop.yml +24 -0
  6. data/.travis.yml +24 -0
  7. data/CHANGELOG.md +11 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +6 -0
  10. data/Gemfile.lock +119 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +165 -0
  13. data/Rakefile +8 -0
  14. data/_config.yml +1 -0
  15. data/benchmarks/descriptive_statistics.rb +60 -0
  16. data/bin/console +15 -0
  17. data/bin/setup +8 -0
  18. data/docs/.DS_Store +0 -0
  19. data/docs/descriptive/COEFFICIENT_OF_VARIATION.md +19 -0
  20. data/docs/descriptive/FREQUENCIES.md +22 -0
  21. data/docs/descriptive/KURTOSIS.md +19 -0
  22. data/docs/descriptive/MAX.md +17 -0
  23. data/docs/descriptive/MEAN.md +19 -0
  24. data/docs/descriptive/MEDIAN.md +17 -0
  25. data/docs/descriptive/MIDRANGE.md +19 -0
  26. data/docs/descriptive/MIN.md +17 -0
  27. data/docs/descriptive/MODE.md +17 -0
  28. data/docs/descriptive/PERCENTILE_FROM_VALUE.md +19 -0
  29. data/docs/descriptive/PROPORTIONS.md +22 -0
  30. data/docs/descriptive/RANGE.md +17 -0
  31. data/docs/descriptive/SIZE.md +19 -0
  32. data/docs/descriptive/SKEWNESS.md +19 -0
  33. data/docs/descriptive/STANDARD_DEVIATION.md +19 -0
  34. data/docs/descriptive/STANDARD_ERROR.md +19 -0
  35. data/docs/descriptive/SUM.md +17 -0
  36. data/docs/descriptive/SUMMARY.md +25 -0
  37. data/docs/descriptive/VALUE_FROM_PERCENTILE.md +19 -0
  38. data/docs/descriptive/VARIANCE.md +19 -0
  39. data/docs/descriptive/ZSCORE.md +24 -0
  40. data/lib/generators/lite/statistics/install_generator.rb +17 -0
  41. data/lib/generators/lite/statistics/templates/install.rb +5 -0
  42. data/lib/lite/statistics.rb +9 -0
  43. data/lib/lite/statistics/base.rb +19 -0
  44. data/lib/lite/statistics/configuration.rb +29 -0
  45. data/lib/lite/statistics/descriptive.rb +361 -0
  46. data/lib/lite/statistics/enumerable.rb +24 -0
  47. data/lib/lite/statistics/version.rb +9 -0
  48. data/lite-statistics.gemspec +48 -0
  49. metadata +202 -0
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-leap-day
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[lib benchmarks].each { |name| $LOAD_PATH.unshift(name) }
4
+
5
+ require 'benchmark/ips'
6
+ require 'lite/statistics'
7
+ require 'descriptive_statistics/safe'
8
+
9
+ collection = []
10
+ 1_000_000.times { collection << rand(1..99) }
11
+
12
+ puts '~~~ Default Summary Size Calculations ~~~'
13
+ Benchmark.ips do |x|
14
+ x.report('lite-statistics') do
15
+ data = Lite::Statistics::Descriptive.new(collection)
16
+ data.sample_summary
17
+ end
18
+
19
+ x.report('descriptive_statistics') do
20
+ data = DescriptiveStatistics::Stats.new(collection)
21
+ data.descriptive_statistics
22
+ end
23
+
24
+ x.compare!
25
+ end
26
+
27
+ # rubocop:disable Metrics/MethodLength
28
+ def equal_summary(data)
29
+ {
30
+ max: data.max,
31
+ mean: data.mean,
32
+ median: data.median,
33
+ min: data.min,
34
+ mode: data.mode,
35
+ quartile_1: data.value_from_percentile(25),
36
+ quartile_2: data.value_from_percentile(50),
37
+ quartile_3: data.value_from_percentile(75),
38
+ range: data.range,
39
+ size: data.size,
40
+ sum: data.sum,
41
+ sample_standard_deviation: data.sample_standard_deviation,
42
+ sample_variance: data.sample_variance
43
+ }
44
+ end
45
+ # rubocop:enable Metrics/MethodLength
46
+
47
+ puts '~~~ Equal Summary Size Calculations ~~~'
48
+ Benchmark.ips do |x|
49
+ x.report('lite-statistics') do
50
+ data = Lite::Statistics::Descriptive.new(collection)
51
+ equal_summary(data)
52
+ end
53
+
54
+ x.report('descriptive_statistics') do
55
+ data = DescriptiveStatistics::Stats.new(collection)
56
+ data.descriptive_statistics
57
+ end
58
+
59
+ x.compare!
60
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'lite/statistics'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/docs/.DS_Store ADDED
Binary file
@@ -0,0 +1,19 @@
1
+ # Sample|Population Coefficient of Variation
2
+
3
+ Alias: `coefficient_of_variation`
4
+
5
+ ```ruby
6
+ collection = [1, 1, 2, 3, 10]
7
+ results = 0.994796148546339
8
+
9
+ klass = Lite::Statistics::Descriptive.new(collection)
10
+ klass.sample_coefficient_of_variation
11
+
12
+ # - or -
13
+
14
+ Lite::Statistics::Descriptive.population_coefficient_of_variation(collection)
15
+
16
+ # - or -
17
+
18
+ collection.sample_coefficient_of_variation
19
+ ```
@@ -0,0 +1,22 @@
1
+ # Frequencies
2
+
3
+ ```ruby
4
+ collection = [1, 1, 2, 3, 10]
5
+ results = {
6
+ 1 => 2,
7
+ 2 => 1,
8
+ 3 => 1,
9
+ 10 => 1
10
+ }
11
+
12
+ klass = Lite::Statistics::Descriptive.new(collection)
13
+ klass.frequencies
14
+
15
+ # - or -
16
+
17
+ Lite::Statistics::Descriptive.frequencies(collection)
18
+
19
+ # - or -
20
+
21
+ collection.frequencies
22
+ ```
@@ -0,0 +1,19 @@
1
+ # Sample|Population Kurtosis
2
+
3
+ Alias: `kurtosis`
4
+
5
+ ```ruby
6
+ collection = [1, 1, 2, 3, 10]
7
+ results = 3.007017458066408
8
+
9
+ klass = Lite::Statistics::Descriptive.new(collection)
10
+ klass.sample_kurtosis
11
+
12
+ # - or -
13
+
14
+ Lite::Statistics::Descriptive.population_kurtosis(collection)
15
+
16
+ # - or -
17
+
18
+ collection.sample_kurtosis
19
+ ```
@@ -0,0 +1,17 @@
1
+ # Max
2
+
3
+ ```ruby
4
+ collection = [1, 1, 2, 3, 10]
5
+ results = 10
6
+
7
+ klass = Lite::Statistics::Descriptive.new(collection)
8
+ klass.max
9
+
10
+ # - or -
11
+
12
+ Lite::Statistics::Descriptive.max(collection)
13
+
14
+ # - or -
15
+
16
+ # No monkey patch available as its part of Enumerable
17
+ ```
@@ -0,0 +1,19 @@
1
+ # Mean
2
+
3
+ Alias: `average`
4
+
5
+ ```ruby
6
+ collection = [1, 1, 2, 3, 10]
7
+ results = 3.4
8
+
9
+ klass = Lite::Statistics::Descriptive.new(collection)
10
+ klass.mean
11
+
12
+ # - or -
13
+
14
+ Lite::Statistics::Descriptive.mean(collection)
15
+
16
+ # - or -
17
+
18
+ collection.mean
19
+ ```
@@ -0,0 +1,17 @@
1
+ # Median
2
+
3
+ ```ruby
4
+ collection = [1, 1, 2, 3, 10]
5
+ results = 2
6
+
7
+ klass = Lite::Statistics::Descriptive.new(collection)
8
+ klass.median
9
+
10
+ # - or -
11
+
12
+ Lite::Statistics::Descriptive.median(collection)
13
+
14
+ # - or -
15
+
16
+ collection.median
17
+ ```
@@ -0,0 +1,19 @@
1
+ # Midrange
2
+
3
+ Alias: `midextreme`
4
+
5
+ ```ruby
6
+ collection = [1, 1, 2, 3, 10]
7
+ results = 5.5
8
+
9
+ klass = Lite::Statistics::Descriptive.new(collection)
10
+ klass.midrange
11
+
12
+ # - or -
13
+
14
+ Lite::Statistics::Descriptive.midrange(collection)
15
+
16
+ # - or -
17
+
18
+ collection.midrange
19
+ ```
@@ -0,0 +1,17 @@
1
+ # Min
2
+
3
+ ```ruby
4
+ collection = [1, 1, 2, 3, 10]
5
+ results = 1
6
+
7
+ klass = Lite::Statistics::Descriptive.new(collection)
8
+ klass.min
9
+
10
+ # - or -
11
+
12
+ Lite::Statistics::Descriptive.min(collection)
13
+
14
+ # - or -
15
+
16
+ # No monkey patch available as its part of Enumerable
17
+ ```
@@ -0,0 +1,17 @@
1
+ # Mode
2
+
3
+ ```ruby
4
+ collection = [1, 1, 2, 3, 10]
5
+ results = 1
6
+
7
+ klass = Lite::Statistics::Descriptive.new(collection)
8
+ klass.mode
9
+
10
+ # - or -
11
+
12
+ Lite::Statistics::Descriptive.mode(collection)
13
+
14
+ # - or -
15
+
16
+ collection.mode
17
+ ```
@@ -0,0 +1,19 @@
1
+ # Percentile from Value
2
+
3
+ Alias: `percentile`
4
+
5
+ ```ruby
6
+ collection = [1, 1, 2, 3, 10]
7
+ results = 80
8
+
9
+ klass = Lite::Statistics::Descriptive.new(collection)
10
+ klass.percentile_from_value(10)
11
+
12
+ # - or -
13
+
14
+ Lite::Statistics::Descriptive.percentile_from_value(collection, 10)
15
+
16
+ # - or -
17
+
18
+ collection.percentile_from_value(10)
19
+ ```
@@ -0,0 +1,22 @@
1
+ # Proportions
2
+
3
+ ```ruby
4
+ collection = [1, 1, 2, 3, 10]
5
+ results = {
6
+ 1 => 0.4,
7
+ 2 => 0.2,
8
+ 3 => 0.2,
9
+ 10 => 0.2
10
+ }
11
+
12
+ klass = Lite::Statistics::Descriptive.new(collection)
13
+ klass.proportions
14
+
15
+ # - or -
16
+
17
+ Lite::Statistics::Descriptive.proportions(collection)
18
+
19
+ # - or -
20
+
21
+ collection.proportions
22
+ ```
@@ -0,0 +1,17 @@
1
+ # Range
2
+
3
+ ```ruby
4
+ collection = [1, 1, 2, 3, 10]
5
+ results = 9
6
+
7
+ klass = Lite::Statistics::Descriptive.new(collection)
8
+ klass.range
9
+
10
+ # - or -
11
+
12
+ Lite::Statistics::Descriptive.range(collection)
13
+
14
+ # - or -
15
+
16
+ collection.range
17
+ ```
@@ -0,0 +1,19 @@
1
+ # Sample|Population Size
2
+
3
+ Alias: `size`
4
+
5
+ ```ruby
6
+ collection = [1, 1, 2, 3, 10]
7
+ results = 5
8
+
9
+ klass = Lite::Statistics::Descriptive.new(collection)
10
+ klass.sample_size
11
+
12
+ # - or -
13
+
14
+ Lite::Statistics::Descriptive.population_size(collection)
15
+
16
+ # - or -
17
+
18
+ collection.sample_size
19
+ ```
@@ -0,0 +1,19 @@
1
+ # Sample|Population Skewness
2
+
3
+ Alias: `skewness`
4
+
5
+ ```ruby
6
+ collection = [1, 1, 2, 3, 10]
7
+ results = 1.328592117701344
8
+
9
+ klass = Lite::Statistics::Descriptive.new(collection)
10
+ klass.sample_skewness
11
+
12
+ # - or -
13
+
14
+ Lite::Statistics::Descriptive.population_skewness(collection)
15
+
16
+ # - or -
17
+
18
+ collection.sample_skewness
19
+ ```
@@ -0,0 +1,19 @@
1
+ # Sample|Population Standard Deviation
2
+
3
+ Alias: `standard_deviation`
4
+
5
+ ```ruby
6
+ collection = [1, 1, 2, 3, 10]
7
+ results = 3.3823069050575527
8
+
9
+ klass = Lite::Statistics::Descriptive.new(collection)
10
+ klass.sample_standard_deviation
11
+
12
+ # - or -
13
+
14
+ Lite::Statistics::Descriptive.population_standard_deviation(collection)
15
+
16
+ # - or -
17
+
18
+ collection.sample_standard_deviation
19
+ ```
@@ -0,0 +1,19 @@
1
+ # Sample|Population Standard Error
2
+
3
+ Alias: `standard_error`
4
+
5
+ ```ruby
6
+ collection = [1, 1, 2, 3, 10]
7
+ results = 1.512613632095123
8
+
9
+ klass = Lite::Statistics::Descriptive.new(collection)
10
+ klass.sample_standard_error
11
+
12
+ # - or -
13
+
14
+ Lite::Statistics::Descriptive.population_standard_error(collection)
15
+
16
+ # - or -
17
+
18
+ collection.sample_standard_error
19
+ ```
@@ -0,0 +1,17 @@
1
+ # Sum
2
+
3
+ ```ruby
4
+ collection = [1, 1, 2, 3, 10]
5
+ results = 17
6
+
7
+ klass = Lite::Statistics::Descriptive.new(collection)
8
+ klass.sum
9
+
10
+ # - or -
11
+
12
+ Lite::Statistics::Descriptive.sum(collection)
13
+
14
+ # - or -
15
+
16
+ # No monkey patch available as its part of Enumerable
17
+ ```