Class: ABAnalyzer::ABTest

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

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ ABTest

values should be hash of hashes, with top level hash the group names: { :groupa => { :yes => 20, :no => 10 }, :groupb => { :yes => 18, :no => 8 } }



7
8
9
# File 'lib/abanalyzer/abtest.rb', line 7

def initialize(values)
  @values = Matrix.new values
end

Instance Method Details

#chisquare_pObject



35
36
37
# File 'lib/abanalyzer/abtest.rb', line 35

def chisquare_p
  1 - Statistics2.chi2dist(df, chisquare_score)
end

#chisquare_scoreObject



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

Returns:

  • (Boolean)


11
12
13
# File 'lib/abanalyzer/abtest.rb', line 11

def different?(sig = 0.05)
  gtest_p < sig
end

#gtest_pObject



39
40
41
# File 'lib/abanalyzer/abtest.rb', line 39

def gtest_p
  1 - Statistics2.chi2dist(df, 2 * gtest_score)
end

#gtest_scoreObject



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