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