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
-
#conversions ⇒ Object
readonly
Number of conversions for this alternative (same participant may be counted more than once).
-
#converted ⇒ Object
readonly
Number of participants who converted on this alternative (a participant is counted only once).
-
#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.
-
#name ⇒ Object
readonly
Alternative name (option A, option B, etc).
-
#participants ⇒ Object
readonly
Number of participants who viewed this alternative.
-
#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, rounded to 3 places.
-
#initialize(experiment, id, value, participants, converted, conversions) ⇒ Alternative
constructor
A new instance of Alternative.
- #inspect ⇒ Object
-
#measure ⇒ Object
The measure we use to order (sort) alternatives and decide which one is better (by calculating z-score).
- #to_s ⇒ Object
Constructor Details
#initialize(experiment, id, value, participants, converted, conversions) ⇒ Alternative
Returns a new instance of Alternative.
9 10 11 12 13 14 15 |
# 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 @participants, @converted, @conversions = participants, converted, conversions end |
Instance Attribute Details
#conversions ⇒ Object (readonly)
Number of conversions for this alternative (same participant may be counted more than once).
36 37 38 |
# File 'lib/vanity/experiment/ab_test.rb', line 36 def conversions @conversions end |
#converted ⇒ Object (readonly)
Number of participants who converted on this alternative (a participant is counted only once).
33 34 35 |
# File 'lib/vanity/experiment/ab_test.rb', line 33 def converted @converted end |
#difference ⇒ Object
Difference from least performing alternative. Populated by AbTest#score.
45 46 47 |
# File 'lib/vanity/experiment/ab_test.rb', line 45 def difference @difference end |
#experiment ⇒ Object (readonly)
Experiment this alternative belongs to.
27 28 29 |
# File 'lib/vanity/experiment/ab_test.rb', line 27 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 |
#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 |
#participants ⇒ Object (readonly)
Number of participants who viewed this alternative.
30 31 32 |
# File 'lib/vanity/experiment/ab_test.rb', line 30 def participants @participants end |
#probability ⇒ Object
Probability derived from z-score. Populated by AbTest#score.
42 43 44 |
# File 'lib/vanity/experiment/ab_test.rb', line 42 def probability @probability end |
#value ⇒ Object (readonly)
Alternative value.
24 25 26 |
# File 'lib/vanity/experiment/ab_test.rb', line 24 def value @value end |
#z_score ⇒ Object
Z-score for this alternative, related to 2nd-best performing alternative. Populated by AbTest#score.
39 40 41 |
# File 'lib/vanity/experiment/ab_test.rb', line 39 def z_score @z_score end |
Instance Method Details
#<=>(other) ⇒ Object
58 59 60 |
# File 'lib/vanity/experiment/ab_test.rb', line 58 def <=>(other) measure <=> other.measure end |
#==(other) ⇒ Object
62 63 64 |
# File 'lib/vanity/experiment/ab_test.rb', line 62 def ==(other) other && id == other.id && experiment == other.experiment end |
#conversion_rate ⇒ Object
Conversion rate calculated as converted/participants, rounded to 3 places.
48 49 50 |
# File 'lib/vanity/experiment/ab_test.rb', line 48 def conversion_rate @conversion_rate ||= (participants > 0 ? (converted.to_f/participants.to_f * 1000).round / 1000.0 : 0.0) end |
#inspect ⇒ Object
70 71 72 |
# File 'lib/vanity/experiment/ab_test.rb', line 70 def inspect "#{name}: #{value} #{converted}/#{participants}" 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.
54 55 56 |
# File 'lib/vanity/experiment/ab_test.rb', line 54 def measure conversion_rate end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/vanity/experiment/ab_test.rb', line 66 def to_s name end |