Module: FDR
- Defined in:
- lib/rbbt/statistics/fdr.rb
Class Method Summary collapse
-
.adjust_hash!(data, field = nil) ⇒ Object
This will change the values of the floats in-situ.
-
.adjust_native(values) ⇒ Object
values should be sorted.
-
.step_up_native(values, rate) ⇒ Object
values should be sorted.
Class Method Details
.adjust_hash!(data, field = nil) ⇒ Object
This will change the values of the floats in-situ
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/rbbt/statistics/fdr.rb', line 139 def self.adjust_hash!(data, field = nil) keys = [] values = [] if data.respond_to? :unnamed unnamed = data.unnamed data.unnamed = true end data.collect{|key, value| [key, Array === ( v = field.nil? ? value : value[field] ) ? v.first : v] }.sort{|a,b| a[1] <=> b[1] }.each{|p| keys << p[0] values << p[1] } if data.respond_to? :unnamed data.unnamed = unnamed end if RUBY_VERSION[0] == "2" # I don't know why the RFLOAT_VALUE_SET for Ruby 2.1.0 does not work values = FDR.adjust(values) data = Hash[*keys.zip(values).flatten] else FDR.adjust!(values) end data end |
.adjust_native(values) ⇒ Object
values should be sorted
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rbbt/statistics/fdr.rb', line 20 def self.adjust_native(values) total = values.length.to_f adjusted = [] last = 1 values.reverse.each_with_index do |value, i| adj = [last, value * total / (total - i )].min last = adj adjusted << adj end adjusted.reverse end |
.step_up_native(values, rate) ⇒ Object
values should be sorted
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rbbt/statistics/fdr.rb', line 6 def self.step_up_native(values, rate) total = values.length last = 0 values.each_with_index do |value, i| if value > rate * (i + 1).to_f / total return last end last = value end return last end |