class Vanity::Experiment::Alternative

One of several alternatives in an A/B test (see AbTest#alternatives).

Attributes

difference[RW]

Difference from least performing alternative. Populated by AbTest#score.

experiment[R]

Experiment this alternative belongs to.

id[R]

Alternative id, only unique for this experiment.

name[R]

Alternative name (option A, option B, etc).

probability[RW]

Probability alternative is best. Populated by AbTest#score.

value[R]

Alternative value.

z_score[RW]

Z-score for this alternative, related to 2nd-best performing alternative. Populated by AbTest#score if score_method is :z_score.

Public Class Methods

new(experiment, id, value) click to toggle source
# 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

<=>(other) click to toggle source
# File lib/vanity/experiment/alternative.rb, line 68
def <=>(other)
  measure <=> other.measure
end
==(other) click to toggle source
# File lib/vanity/experiment/alternative.rb, line 72
def ==(other)
  other && id == other.id && experiment == other.experiment
end
conversion_rate() click to toggle source

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
conversions() click to toggle source

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
converted() click to toggle source

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
default?() click to toggle source
# File lib/vanity/experiment/alternative.rb, line 92
def default?
  @experiment.default == self
end
inspect() click to toggle source
# File lib/vanity/experiment/alternative.rb, line 80
def inspect
  "#{name}: #{value} #{converted}/#{participants}"
end
load_counts() click to toggle source
# 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
measure() click to toggle source

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
participants() click to toggle source

Number of participants who viewed this alternative.

# File lib/vanity/experiment/alternative.rb, line 27
def participants
  load_counts unless defined?(@participants)
  @participants
end
to_s() click to toggle source
# File lib/vanity/experiment/alternative.rb, line 76
def to_s
  name
end