Module: FDR

Defined in:
lib/rbbt/statistics/fdr.rb

Class Method Summary collapse

Class Method Details

.adjust_hash!(data, field = nil) ⇒ Object

This will change the values of the floats in situ



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/rbbt/statistics/fdr.rb', line 134

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

  FDR.adjust!(values)

  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