class Vanity::Experiment::Alternative
One of several alternatives in an A/B test (see AbTest#alternatives
).
Attributes
Difference from least performing alternative. Populated by AbTest#score
.
Experiment
this alternative belongs to.
Alternative
id, only unique for this experiment.
Alternative
name (option A, option B, etc).
Probability alternative is best. Populated by AbTest#score
.
Alternative
value.
Z-score for this alternative, related to 2nd-best performing alternative. Populated by AbTest#score
if score_method is :z_score.
Public Class Methods
# File lib/vanity/experiment/alternative.rb, line 7 def initialize(experiment, id, value) #, participants, converted, conversions) @experiment = experiment @id = id @name = I18n.t('vanity.option_number', :char=>(@id + 65).chr.upcase) @value = value end
Public Instance Methods
# File lib/vanity/experiment/alternative.rb, line 68 def <=>(other) measure <=> other.measure end
# File lib/vanity/experiment/alternative.rb, line 72 def ==(other) other && id == other.id && experiment == other.experiment end
Conversion rate calculated as converted/participants
# File lib/vanity/experiment/alternative.rb, line 58 def conversion_rate @conversion_rate ||= (participants > 0 ? converted.to_f/participants.to_f : 0.0) end
Number of conversions for this alternative (same participant may be counted more than once).
# File lib/vanity/experiment/alternative.rb, line 41 def conversions load_counts unless defined?(@conversions) @conversions end
Number of participants who converted on this alternative (a participant is counted only once).
# File lib/vanity/experiment/alternative.rb, line 34 def converted load_counts unless defined?(@converted) @converted end
# File lib/vanity/experiment/alternative.rb, line 92 def default? @experiment.default == self end
# File lib/vanity/experiment/alternative.rb, line 80 def inspect "#{name}: #{value} #{converted}/#{participants}" end
# File lib/vanity/experiment/alternative.rb, line 84 def load_counts if @experiment.playground.collecting? @participants, @converted, @conversions = @experiment.playground.connection.ab_counts(@experiment.id, id).values_at(:participants, :converted, :conversions) else @participants = @converted = @conversions = 0 end end
The measure we use to order (sort) alternatives and decide which one is better (by calculating z-score). Defaults to conversion rate.
# File lib/vanity/experiment/alternative.rb, line 64 def measure conversion_rate end
Number of participants who viewed this alternative.
# File lib/vanity/experiment/alternative.rb, line 27 def participants load_counts unless defined?(@participants) @participants end
# File lib/vanity/experiment/alternative.rb, line 76 def to_s name end