Class: Vanity::Experiment::Alternative
- Inherits:
-
Object
- Object
- Vanity::Experiment::Alternative
- Defined in:
- lib/vanity/experiment/ab_test.rb
Overview
One of several alternatives in an A/B test (see AbTest#alternatives).
Instance Attribute Summary (collapse)
-
- (Object) difference
Difference from least performing alternative.
-
- (Object) experiment
readonly
Experiment this alternative belongs to.
-
- (Object) id
readonly
Alternative id, only unique for this experiment.
-
- (Object) name
readonly
Alternative name (option A, option B, etc).
-
- (Object) probability
Probability derived from z-score.
-
- (Object) value
readonly
Alternative value.
-
- (Object) z_score
Z-score for this alternative, related to 2nd-best performing alternative.
Instance Method Summary (collapse)
- - (Object) <=>(other)
- - (Object) ==(other)
-
- (Object) conversion_rate
Conversion rate calculated as converted/participants.
-
- (Object) conversions
Number of conversions for this alternative (same participant may be counted more than once).
-
- (Object) converted
Number of participants who converted on this alternative (a participant is counted only once).
-
- (Alternative) initialize(experiment, id, value)
constructor
, participants, converted, conversions).
- - (Object) inspect
- - (Object) load_counts
-
- (Object) measure
The measure we use to order (sort) alternatives and decide which one is better (by calculating z-score).
-
- (Object) participants
Number of participants who viewed this alternative.
- - (Object) to_s
Constructor Details
- (Alternative) initialize(experiment, id, value)
, participants, converted, conversions)
9 10 11 12 13 14 |
# File 'lib/vanity/experiment/ab_test.rb', line 9 def initialize(experiment, id, value) #, participants, converted, conversions) @experiment = experiment @id = id @name = "option #{(@id + 65).chr}" @value = value end |
Instance Attribute Details
- (Object) difference
Difference from least performing alternative. Populated by AbTest#score.
53 54 55 |
# File 'lib/vanity/experiment/ab_test.rb', line 53 def difference @difference end |
- (Object) experiment (readonly)
Experiment this alternative belongs to.
26 27 28 |
# File 'lib/vanity/experiment/ab_test.rb', line 26 def experiment @experiment end |
- (Object) id (readonly)
Alternative id, only unique for this experiment.
17 18 19 |
# File 'lib/vanity/experiment/ab_test.rb', line 17 def id @id end |
- (Object) name (readonly)
Alternative name (option A, option B, etc).
20 21 22 |
# File 'lib/vanity/experiment/ab_test.rb', line 20 def name @name end |
- (Object) probability
Probability derived from z-score. Populated by AbTest#score.
50 51 52 |
# File 'lib/vanity/experiment/ab_test.rb', line 50 def probability @probability end |
- (Object) value (readonly)
Alternative value.
23 24 25 |
# File 'lib/vanity/experiment/ab_test.rb', line 23 def value @value end |
- (Object) z_score
Z-score for this alternative, related to 2nd-best performing alternative. Populated by AbTest#score.
47 48 49 |
# File 'lib/vanity/experiment/ab_test.rb', line 47 def z_score @z_score end |
Instance Method Details
- (Object) <=>(other)
66 67 68 |
# File 'lib/vanity/experiment/ab_test.rb', line 66 def <=>(other) measure <=> other.measure end |
- (Object) ==(other)
70 71 72 |
# File 'lib/vanity/experiment/ab_test.rb', line 70 def ==(other) other && id == other.id && experiment == other.experiment end |
- (Object) conversion_rate
Conversion rate calculated as converted/participants
56 57 58 |
# File 'lib/vanity/experiment/ab_test.rb', line 56 def conversion_rate @conversion_rate ||= (participants > 0 ? converted.to_f/participants.to_f : 0.0) end |
- (Object) conversions
Number of conversions for this alternative (same participant may be counted more than once).
41 42 43 44 |
# File 'lib/vanity/experiment/ab_test.rb', line 41 def conversions load_counts unless @conversions @conversions end |
- (Object) converted
Number of participants who converted on this alternative (a participant is counted only once).
35 36 37 38 |
# File 'lib/vanity/experiment/ab_test.rb', line 35 def converted load_counts unless @converted @converted end |
- (Object) inspect
78 79 80 |
# File 'lib/vanity/experiment/ab_test.rb', line 78 def inspect "#{name}: #{value} #{converted}/#{participants}" end |
- (Object) load_counts
82 83 84 85 86 87 88 |
# File 'lib/vanity/experiment/ab_test.rb', line 82 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 |
- (Object) measure
The measure we use to order (sort) alternatives and decide which one is better (by calculating z-score). Defaults to conversion rate.
62 63 64 |
# File 'lib/vanity/experiment/ab_test.rb', line 62 def measure conversion_rate end |
- (Object) participants
Number of participants who viewed this alternative.
29 30 31 32 |
# File 'lib/vanity/experiment/ab_test.rb', line 29 def participants load_counts unless @participants @participants end |
- (Object) to_s
74 75 76 |
# File 'lib/vanity/experiment/ab_test.rb', line 74 def to_s name end |