# livingsocial/vanity forked from assaf/vanity

`… determine statistical difference in categorial data according to abanalyzer`
1 parent 8ac8455 commit 312b78bd30e8581e47f658c0df2c2bb94f3ab7dd Andy Atkinson committed Aug 24, 2011
Showing with 19 additions and 2 deletions.
1. +17 −0 lib/vanity/experiment/ab_test.rb
2. +1 −2 lib/vanity/templates/_ab_test.erb
3. +1 −0 vanity.gemspec
 @@ -325,6 +325,23 @@ def score(probability = 90) choice = outcome ? alts[outcome.id] : (best && best.probability >= probability ? best : nil) Struct.new(:alts, :best, :base, :least, :choice).new(alts, best, base, least, choice) end + + def different?(score) + require 'abanalyzer' + + values = score.alts.inject({}) do |values, alternative| + alternative_data = {:participations => alternative.participants, :conversions => alternative.converted} + values.merge!({alternative.name.to_sym => alternative_data}) + values + end + + begin + ABAnalyzer::ABTest.new(values).different? + rescue ABAnalyzer::InsufficientDataError + ::Rails.logger.error "vanity: caught ABAnalyzer::InsufficientDataError exception from ABAnalyzer" + false + end + end # Use the result of #score to derive a conclusion. Returns an # array of claims.
 @@ -1,7 +1,6 @@ <% score = experiment.score %> - - <%= experiment.conclusion(score).join(" ") %> + Different? <%= experiment.different?(score) %> <% score.alts.each do |alt| %>
<%= alt.name.gsub(/^o/, "O") %>:
">
 @@ -21,4 +21,5 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 1.8.7' spec.add_dependency "redis", "~>2.0" spec.add_dependency "redis-namespace", "~>1.0.0" + spec.add_dependency "abanalyzer", "0.0.4" end