enumerable-stats 1.2.2 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67bc0d2458936c421a69879c70fa9eb553e48c7447012e87810ce3c4ab028d66
4
- data.tar.gz: 819fcf5e9446b4f7e4a1d7e75aeb914d4ab6ca6a76e65065877d5c3d3bab3634
3
+ metadata.gz: e012306442bdf4598aeff1c134063a3a0c98e6765a949c492626ba7acdf90c1d
4
+ data.tar.gz: dc2565331c7aa7f07ab55c7b876d78e8c9759f7a0e083d9a39f82c2deb1c5458
5
5
  SHA512:
6
- metadata.gz: c5dfe0571aa591684f9ae8cf8e26a472695b6a26c424185878a6e7a9bfd2786ee20c205c2eca0be234a88fb25c895fc0d2cb25a599aabbc569375657b5ee1705
7
- data.tar.gz: cd39ddb06cc2cbc1f204deaece6cce9fcf1835583510559a8dd7d24615df95aac16c9a2ff6bd0ba1678c1dce80c0e7636eae6c121e4b7fd31d418b619fed8604
6
+ metadata.gz: 1ef3e67bbf9977081003fb009b08afe891b0177a26d58fa5cd206f216890c1ec3c8b4904e92f2731bc3a6ce134848813033d555c7baa16c8fdde87637913f894
7
+ data.tar.gz: 4aa56d0cba5bd41c2b2e91224814801f8c97429a9cf2516d1acae865c0a2a6b7b786e5eeaba4c81e4777a7b0735b8008fdaf263e9fb26d7c0165fce70f7a24ff
@@ -93,6 +93,9 @@ module EnumerableStats
93
93
  # treatment = [15, 17, 16, 18, 14]
94
94
  # t_stat = control.t_value(treatment) # => ~-4.2 (negative means treatment > control)
95
95
  def t_value(other)
96
+ raise ArgumentError, "Cannot compare with an empty collection" if empty? || other.empty?
97
+ raise ArgumentError, "Parameter must be an Enumerable" unless other.respond_to?(:mean)
98
+
96
99
  signal = (mean - other.mean)
97
100
  noise = Math.sqrt(
98
101
  ((standard_deviation**2) / count) +
@@ -164,6 +167,58 @@ module EnumerableStats
164
167
  t_stat < -critical_value
165
168
  end
166
169
 
170
+ # Operator alias for greater_than? - tests if this collection's mean is significantly greater
171
+ #
172
+ # @param other [Enumerable] Another collection to compare against
173
+ # @param alpha [Float] The significance level (default: 0.05 for 95% confidence)
174
+ # @return [Boolean] true if this collection's mean is significantly greater
175
+ # @example
176
+ # baseline = [100, 110, 105, 115, 95]
177
+ # optimized = [85, 95, 90, 100, 80]
178
+ # baseline > optimized # => true (baseline is significantly greater)
179
+ def >(other, alpha: 0.05)
180
+ greater_than?(other, alpha: alpha)
181
+ end
182
+
183
+ # Operator alias for less_than? - tests if this collection's mean is significantly less
184
+ #
185
+ # @param other [Enumerable] Another collection to compare against
186
+ # @param alpha [Float] The significance level (default: 0.05 for 95% confidence)
187
+ # @return [Boolean] true if this collection's mean is significantly less
188
+ # @example
189
+ # optimized = [85, 95, 90, 100, 80]
190
+ # baseline = [100, 110, 105, 115, 95]
191
+ # optimized < baseline # => true (optimized is significantly less)
192
+ def <(other, alpha: 0.05)
193
+ less_than?(other, alpha: alpha)
194
+ end
195
+
196
+ # Tests if this collection's mean is significantly different from another collection's mean
197
+ # using a two-tailed Student's t-test. Returns 1 if the test indicates statistical
198
+ # significance at the specified alpha level, -1 if the test indicates statistical
199
+ # significance at the specified alpha level, and 0 if the test indicates no statistical
200
+ # significance at the specified alpha level.
201
+ #
202
+ # @param other [Enumerable] Another collection to compare against
203
+ # @param alpha [Float] Significance level (default: 0.05 for 95% confidence)
204
+ # @return [Integer] 1 if this collection's mean is significantly greater, -1 if this collection's mean is
205
+ # significantly less, 0 if this collection's mean is not significantly different
206
+ # @example
207
+ # control = [10, 12, 11, 13, 12] # mean ≈ 11.6
208
+ # treatment = [15, 17, 16, 18, 14] # mean = 16.0
209
+ # control <=> treatment # => 1 (control is significantly different from treatment)
210
+ # treatment <=> control # => -1 (treatment is significantly different from control)
211
+ # control <=> control # => 0 (control is not significantly different from itself)
212
+ def <=>(other, alpha: 0.05)
213
+ if greater_than?(other, alpha: alpha)
214
+ 1
215
+ elsif less_than?(other, alpha: alpha)
216
+ -1
217
+ else
218
+ 0
219
+ end
220
+ end
221
+
167
222
  # Calculates the arithmetic mean (average) of the collection
168
223
  #
169
224
  # @return [Float] The arithmetic mean of all numeric values
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EnumerableStats
4
+ VERSION = "1.4.0"
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerable-stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Daniel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-02 00:00:00.000000000 Z
11
+ date: 2025-08-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  A Ruby gem that extends all Enumerable objects (Arrays, Ranges, Sets, etc.) with essential statistical methods.
@@ -22,6 +22,7 @@ extra_rdoc_files: []
22
22
  files:
23
23
  - lib/enumerable-stats.rb
24
24
  - lib/enumerable_stats/enumerable_ext.rb
25
+ - lib/enumerable_stats/version.rb
25
26
  homepage: https://github.com/binarycleric/enumerable-stats
26
27
  licenses:
27
28
  - MIT