Module: FDR

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

Class Method Summary collapse

Class Method Details

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



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
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/rbbt/statistics/fdr.rb', line 139

def self.adjust_hash!(data, field = nil)
  begin
    if data.respond_to? :unnamed
      unnamed = data.unnamed 
      data.unnamed = true
    end

    values = []
    keys = []
    data.collect{|k,vs|
      v = field.nil? ? vs : vs[field]
      v = v.first if Array === v
      [k, v] 
    }.sort{|a,b| 
      a[1] <=> b[1]
    }.each{|p|
      keys << p[0]
      values << p[1]
    }

    if RUBY_VERSION[0] == "2"
      values = FDR.adjust(values)
      keys.zip(values).each do |k,v|
        vs = data[k] 
        if field
          vs[field] = v
        else
          if Array === vs
            vs[0] = v
          else
            data[k] = vs
          end
        end
      end
    else
      FDR.adjust!(values)
    end

    data
  ensure
    data.unnamed = unnamed if unnamed
  end
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