Class: Fathom::PlausibleRange

Inherits:
Node
  • Object
show all
Includes:
NumericMethods
Defined in:
lib/fathom/node/plausible_range.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#description, #distribution, #name, #values

Instance Method Summary collapse

Methods included from NumericMethods

#coefficient_of_variation, #interval_values, #inverse_cdf, #summary, #vector

Methods inherited from Node

#add_child, #add_parent, #children, #inspect, #name_sym, #parents, #register_child, #register_parent, #simple_inspect

Constructor Details

#initialize(opts = {}) ⇒ PlausibleRange

Returns a new instance of PlausibleRange.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fathom/node/plausible_range.rb', line 9

def initialize(opts={})
  super(opts)
  
  opts = OptionsHash.new(opts)
  
  @hard_upper_bound = opts[:hard_upper_bound]
  @upper_bound = opts[:upper_bound]
  @upper_bound ||= opts[:max]
  @upper_bound ||= @hard_upper_bound
  @upper_bound = @hard_upper_bound if @upper_bound and @hard_upper_bound and @hard_upper_bound < @upper_bound
  raise ArgumentError, "Must provide an upper bound." unless @upper_bound
  
  @hard_lower_bound = opts[:hard_lower_bound]
  @lower_bound = opts[:lower_bound]
  @lower_bound ||= opts[:min]
  @lower_bound ||= @hard_lower_bound
  @lower_bound = @hard_lower_bound if @lower_bound and @hard_lower_bound and @hard_lower_bound > @lower_bound
  raise ArgumentError, "Must provide a lower bound." unless @lower_bound
  
  @confidence_interval = opts[:confidence_interval]
  @confidence_interval ||= opts[:ci]
  @confidence_interval ||= 0.9
  
end

Instance Attribute Details

#confidence_intervalObject (readonly) Also known as: ci

Returns the value of attribute confidence_interval.



7
8
9
# File 'lib/fathom/node/plausible_range.rb', line 7

def confidence_interval
  @confidence_interval
end

#hard_lower_boundObject (readonly)

Returns the value of attribute hard_lower_bound.



7
8
9
# File 'lib/fathom/node/plausible_range.rb', line 7

def hard_lower_bound
  @hard_lower_bound
end

#hard_upper_boundObject (readonly)

Returns the value of attribute hard_upper_bound.



7
8
9
# File 'lib/fathom/node/plausible_range.rb', line 7

def hard_upper_bound
  @hard_upper_bound
end

#lower_boundObject (readonly) Also known as: min

Returns the value of attribute lower_bound.



7
8
9
# File 'lib/fathom/node/plausible_range.rb', line 7

def lower_bound
  @lower_bound
end

#upper_boundObject (readonly) Also known as: max

Returns the value of attribute upper_bound.



7
8
9
# File 'lib/fathom/node/plausible_range.rb', line 7

def upper_bound
  @upper_bound
end

Instance Method Details

#array_of_random_values(n = 10) ⇒ Object Also known as: to_a



61
62
63
# File 'lib/fathom/node/plausible_range.rb', line 61

def array_of_random_values(n=10)
  n.times.map {self.rand}
end

#midpointObject Also known as: mean



38
39
40
# File 'lib/fathom/node/plausible_range.rb', line 38

def midpoint
  @midpoint ||= lower_bound + (range / 2.0)
end

#randObject



53
54
55
56
57
58
59
# File 'lib/fathom/node/plausible_range.rb', line 53

def rand
  value = get_rand
  until is_bounded?(value) do
    value = get_rand
  end
  value
end

#rangeObject



43
44
45
# File 'lib/fathom/node/plausible_range.rb', line 43

def range
  @range ||= upper_bound - lower_bound
end

#standard_deviationObject Also known as: std, sd



47
48
49
# File 'lib/fathom/node/plausible_range.rb', line 47

def standard_deviation
  @standard_deviation ||= range / distribution.standard_deviations_under(confidence_interval)
end

#vector_of_random_values(n = 10) ⇒ Object Also known as: to_v



66
67
68
# File 'lib/fathom/node/plausible_range.rb', line 66

def vector_of_random_values(n=10)
  GSL::Vector.alloc(array_of_random_values(n))
end