Class: ViralSeq::Math::BinomCI
- Inherits:
-
Object
- Object
- ViralSeq::Math::BinomCI
- Defined in:
- lib/viral_seq/math.rb
Overview
Use R to calculate binomial 95% confidence intervals. Require R function binom.test.
Instance Attribute Summary collapse
-
#lower ⇒ Float
readonly
Lower limit of 95% CI.
-
#mean ⇒ Float
readonly
Mean.
-
#n1 ⇒ Integer
Number of observations.
-
#n2 ⇒ Integer
Total numbers.
-
#upper ⇒ Float
readonly
Upper limit of 95% CI.
Instance Method Summary collapse
-
#initialize(n1, n2) ⇒ BinomCI
constructor
initialize with numerator @n1 and denominator @n2 as Integer.
Constructor Details
#initialize(n1, n2) ⇒ BinomCI
initialize with numerator @n1 and denominator @n2 as Integer
95 96 97 98 99 100 101 102 103 |
# File 'lib/viral_seq/math.rb', line 95 def initialize(n1, n2) @n1 = n1 @n2 = n2 @mean = n1/n2.to_f r_output = `Rscript -e 'binom.test(#{n1},#{n2})$conf.int[1];binom.test(#{n1},#{n2})$conf.int[2]'` lines = r_output.split "\n" @lower = lines[0].chomp[4..-1].to_f @upper = lines[1].chomp[4..-1].to_f end |
Instance Attribute Details
#lower ⇒ Float (readonly)
Returns lower limit of 95% CI.
112 113 114 |
# File 'lib/viral_seq/math.rb', line 112 def lower @lower end |
#mean ⇒ Float (readonly)
Returns mean.
110 111 112 |
# File 'lib/viral_seq/math.rb', line 110 def mean @mean end |
#n1 ⇒ Integer
Returns number of observations.
106 107 108 |
# File 'lib/viral_seq/math.rb', line 106 def n1 @n1 end |
#n2 ⇒ Integer
Returns total numbers.
108 109 110 |
# File 'lib/viral_seq/math.rb', line 108 def n2 @n2 end |
#upper ⇒ Float (readonly)
Returns upper limit of 95% CI.
114 115 116 |
# File 'lib/viral_seq/math.rb', line 114 def upper @upper end |