Class: ABAnalyzer::ABTest
- Inherits:
-
Object
- Object
- ABAnalyzer::ABTest
- Defined in:
- lib/abanalyzer/abtest.rb
Instance Method Summary collapse
- #chisquare_p ⇒ Object
- #chisquare_score ⇒ Object
- #different?(sig = 0.05) ⇒ Boolean
- #gtest_p ⇒ Object
- #gtest_score ⇒ Object
-
#initialize(values) ⇒ ABTest
constructor
values should be hash of hashes, with top level hash the group names: { :groupa => { :yes => 20, :no => 10 }, :groupb => { :yes => 18, :no => 8 } }.
Constructor Details
Instance Method Details
#chisquare_p ⇒ Object
35 36 37 |
# File 'lib/abanalyzer/abtest.rb', line 35 def chisquare_p 1 - Statistics2.chi2dist(df, chisquare_score) end |
#chisquare_score ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/abanalyzer/abtest.rb', line 15 def chisquare_score sum = 0 @values.each_cell do |colname, rowname, value| ex = expected(colname, rowname) test_sufficient_data(colname, rowname, ex, value) sum += ((value - ex)**2) / ex end sum end |
#different?(sig = 0.05) ⇒ Boolean
11 12 13 |
# File 'lib/abanalyzer/abtest.rb', line 11 def different?(sig = 0.05) gtest_p < sig end |
#gtest_p ⇒ Object
39 40 41 |
# File 'lib/abanalyzer/abtest.rb', line 39 def gtest_p 1 - Statistics2.chi2dist(df, 2 * gtest_score) end |
#gtest_score ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/abanalyzer/abtest.rb', line 25 def gtest_score sum = 0 @values.each_cell do |colname, rowname, value| ex = expected(colname, rowname) test_sufficient_data(colname, rowname, ex, value) sum += value * Math.log(value / ex) end sum end |