Class: Wilson::Interval

Inherits:
Object
  • Object
show all
Defined in:
lib/wilson_interval.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Interval

Returns a new instance of Interval.



5
6
7
8
9
10
11
12
13
14
# File 'lib/wilson_interval.rb', line 5

def initialize(options)
  @o = options
  @o[:confidence] ||= 0.95

  raise "Need to specify :n" unless @o[:total]
  unless @o[:p_hat]
    raise "Need to specify :p_hat or :successes" unless @o[:successes]
    @o[:p_hat] = @o[:successes].to_f / @o[:total] unless @o[:total] == 0
  end
end

Instance Method Details

#lower_boundObject



16
17
18
19
# File 'lib/wilson_interval.rb', line 16

def lower_bound
  return nil if @o[:total] == 0
  (center - plus_minus) / denominator
end

#upper_boundObject



21
22
23
24
# File 'lib/wilson_interval.rb', line 21

def upper_bound
  return nil if @o[:total] == 0
  (center + plus_minus) / denominator
end