Class: Byar
- Inherits:
-
Object
- Object
- Byar
- Defined in:
- lib/byar.rb,
lib/byar/version.rb
Overview
Byar is a Byar’s approximation confidence interval tool with SMR calculation.
Can be used with class-level methods or as instantiated object.
Class-level example with observed value 100 and expected value 90:
Byar.upper(100, 90) # => 1.3514260807978444, equals to SMR of 135.1
Object instance example with observed value 100 and expected value 90:
b = Byar.new(100)
b.upper_bound # => 121.628347271806
b.lower(90) # => 0.9040199067337297, equals to SMR of 90.4
Constant Summary collapse
- Z_VALUE =
Z_VALUE defaults to 1.96 for 95% confidence interval
1.96
- VERSION =
"1.0.0"
Class Method Summary collapse
-
.lower(obs, exp) ⇒ Object
Calculate SMR-like lower boundary (1 equals SMR of 100).
-
.lower_bound(obs, z_value = Z_VALUE) ⇒ Object
Calculate lower boundary for observed cases.
-
.upper(obs, exp) ⇒ Object
Calculate SMR-like upper boundary (1 equals SMR of 100).
-
.upper_bound(obs, z_value = Z_VALUE) ⇒ Object
Calculate upper boundary for observed cases.
- .z_value ⇒ Object
- .z_value=(value) ⇒ Object
Instance Method Summary collapse
-
#initialize(obs) ⇒ Byar
constructor
Create new Byar approximation calculator for
obs
observed cases. -
#lower(expected) ⇒ Object
Give lower SMR-like boundary for
expected
cases. -
#lower_bound ⇒ Object
Give lower boundary for observed value.
-
#upper(expected) ⇒ Object
Give upper SMR-like boundary for
expected
cases. -
#upper_bound ⇒ Object
Give upper boundary for observed value.
-
#z_value ⇒ Object
Give object’s Z value, with fallback to Class variable or Z_VALUE.
-
#z_value=(value) ⇒ Object
Set custom Z value for this Byar instance.
Constructor Details
#initialize(obs) ⇒ Byar
Create new Byar approximation calculator for obs
observed cases
26 27 28 |
# File 'lib/byar.rb', line 26 def initialize(obs) @obs = obs end |
Class Method Details
.lower(obs, exp) ⇒ Object
Calculate SMR-like lower boundary (1 equals SMR of 100)
Give obs
observed and exp
expected values to return a lower SMR-like boundary value (0 - Infinite)
35 36 37 38 |
# File 'lib/byar.rb', line 35 def self.lower(obs, exp) return nil if exp == 0 lower_bound(obs).quo(exp) end |
.lower_bound(obs, z_value = Z_VALUE) ⇒ Object
Calculate lower boundary for observed cases
52 53 54 55 |
# File 'lib/byar.rb', line 52 def self.lower_bound(obs, z_value = Z_VALUE) return 0 if obs == 0 obs * (1 - 1.quo(9 * obs) - z_value.quo(3 * Math.sqrt(obs))) ** 3 end |
.upper(obs, exp) ⇒ Object
Calculate SMR-like upper boundary (1 equals SMR of 100)
Give obs
observed and exp
expected values to return an upper SMR-like boundary value (0 - Infinite)
45 46 47 48 |
# File 'lib/byar.rb', line 45 def self.upper(obs, exp) return nil if exp == 0 upper_bound(obs).quo(exp) end |
.upper_bound(obs, z_value = Z_VALUE) ⇒ Object
Calculate upper boundary for observed cases
59 60 61 62 |
# File 'lib/byar.rb', line 59 def self.upper_bound(obs, z_value = Z_VALUE) obs = obs + 1 obs * (1 - 1.quo(9 * obs) + z_value.quo(3 * Math.sqrt(obs))) ** 3 end |
.z_value ⇒ Object
68 69 70 |
# File 'lib/byar.rb', line 68 def self.z_value @z_value ||= Z_VALUE end |
.z_value=(value) ⇒ Object
64 65 66 |
# File 'lib/byar.rb', line 64 def self.z_value=(value) @z_value = value end |
Instance Method Details
#lower(expected) ⇒ Object
Give lower SMR-like boundary for expected
cases
74 75 76 |
# File 'lib/byar.rb', line 74 def lower(expected) self.class.lower(@obs, expected) end |
#lower_bound ⇒ Object
Give lower boundary for observed value
86 87 88 |
# File 'lib/byar.rb', line 86 def lower_bound self.class.lower_bound(@obs, z_value) end |
#upper(expected) ⇒ Object
Give upper SMR-like boundary for expected
cases
80 81 82 |
# File 'lib/byar.rb', line 80 def upper(expected) self.class.upper(@obs, expected) end |
#upper_bound ⇒ Object
Give upper boundary for observed value
92 93 94 |
# File 'lib/byar.rb', line 92 def upper_bound self.class.upper_bound(@obs, z_value) end |
#z_value ⇒ Object
Give object’s Z value, with fallback to Class variable or Z_VALUE
98 99 100 |
# File 'lib/byar.rb', line 98 def z_value @z_value ||= self.class.z_value end |
#z_value=(value) ⇒ Object
Set custom Z value for this Byar instance
104 105 106 |
# File 'lib/byar.rb', line 104 def z_value=(value) @z_value = value end |