Class: Statistics::Bin
- Inherits:
-
Object
- Object
- Statistics::Bin
- Defined in:
- lib/Statistics/Bin.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
class << self.
-
#interval ⇒ Object
readonly
class << self.
Class Method Summary collapse
- .bin_for_value(value, bins, bottom_boundary, bin_width) ⇒ Object
- .boundaries(values, bin_width: nil, bin_count: nil, method: :square_root) ⇒ Object
- .count(values, method: :square_root) ⇒ Object
- .data_range(values) ⇒ Object
- .width(values, bin_width: nil, bin_count: nil, method: :square_root) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#count ⇒ Object (readonly)
class << self
53 54 55 |
# File 'lib/Statistics/Bin.rb', line 53 def count @count end |
#interval ⇒ Object (readonly)
class << self
53 54 55 |
# File 'lib/Statistics/Bin.rb', line 53 def interval @interval end |
Class Method Details
.bin_for_value(value, bins, bottom_boundary, bin_width) ⇒ Object
32 33 34 35 |
# File 'lib/Statistics/Bin.rb', line 32 def bin_for_value(value, bins, bottom_boundary, bin_width) index = index_for_value(value, bins.count, bottom_boundary, bin_width) bins[index] end |
.boundaries(values, bin_width: nil, bin_count: nil, method: :square_root) ⇒ Object
27 28 29 30 |
# File 'lib/Statistics/Bin.rb', line 27 def boundaries(values, bin_width: nil, bin_count: nil, method: :square_root) w = bin_width || width(values, bin_count: bin_count, method: method) values.first.step(to: values.last + w, by: w).to_a end |
.count(values, method: :square_root) ⇒ Object
19 20 21 |
# File 'lib/Statistics/Bin.rb', line 19 def count(values, method: :square_root) send("#{method}_count", values) end |
.data_range(values) ⇒ Object
23 24 25 |
# File 'lib/Statistics/Bin.rb', line 23 def data_range(values) values.last - values.first end |
.width(values, bin_width: nil, bin_count: nil, method: :square_root) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/Statistics/Bin.rb', line 7 def width(values, bin_width: nil, bin_count: nil, method: :square_root) if bin_width bin_width elsif bin_count data_range(values) / bin_count.to_f elsif data_range(values) == 0 1.0 else send("#{method}_width", values) end end |
Instance Method Details
#empty? ⇒ Boolean
63 64 65 |
# File 'lib/Statistics/Bin.rb', line 63 def empty? @count == 0 end |
#increment ⇒ Object
55 56 57 |
# File 'lib/Statistics/Bin.rb', line 55 def increment @count += 1 end |
#width ⇒ Object
59 60 61 |
# File 'lib/Statistics/Bin.rb', line 59 def width @interval.end - @interval.begin end |