Class: Vanity::Experiment::Alternative

Inherits:
Object
• Object
show all
Defined in:
lib/vanity/experiment/alternative.rb

Overview

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

Instance Attribute Summary (collapse)

• Difference from least performing alternative.

Experiment this alternative belongs to.

Alternative id, only unique for this experiment.

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

• Probability alternative is best.

Alternative value.

• Z-score for this alternative, related to 2nd-best performing alternative.

Instance Method Summary (collapse)

• Conversion rate calculated as converted/participants.

• Number of conversions for this alternative (same participant may be counted more than once).

• Number of participants who converted on this alternative (a participant is counted only once).

• constructor

, participants, converted, conversions).

• The measure we use to order (sort) alternatives and decide which one is better (by calculating z-score).

• Number of participants who viewed this alternative.

Constructor Details

- (Alternative) initialize(experiment, id, value)

, participants, converted, conversions)

 ``` 7 8 9 10 11 12``` ```# File 'lib/vanity/experiment/alternative.rb', line 7 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.

 ``` 55 56 57``` ```# File 'lib/vanity/experiment/alternative.rb', line 55 def difference @difference end```

Experiment this alternative belongs to.

 ``` 24 25 26``` ```# File 'lib/vanity/experiment/alternative.rb', line 24 def experiment @experiment end```

Alternative id, only unique for this experiment.

 ``` 15 16 17``` ```# File 'lib/vanity/experiment/alternative.rb', line 15 def id @id end```

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

 ``` 18 19 20``` ```# File 'lib/vanity/experiment/alternative.rb', line 18 def name @name end```

- (Object) probability

Probability alternative is best. Populated by AbTest#score.

 ``` 51 52 53``` ```# File 'lib/vanity/experiment/alternative.rb', line 51 def probability @probability end```

Alternative value.

 ``` 21 22 23``` ```# File 'lib/vanity/experiment/alternative.rb', line 21 def value @value end```

- (Object) z_score

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

 ``` 48 49 50``` ```# File 'lib/vanity/experiment/alternative.rb', line 48 def z_score @z_score end```

Instance Method Details

- (Object) <=>(other)

 ``` 68 69 70``` ```# File 'lib/vanity/experiment/alternative.rb', line 68 def <=>(other) measure <=> other.measure end```

- (Object) ==(other)

 ``` 72 73 74``` ```# File 'lib/vanity/experiment/alternative.rb', line 72 def ==(other) other && id == other.id && experiment == other.experiment end```

- (Object) conversion_rate

Conversion rate calculated as converted/participants

 ``` 58 59 60``` ```# File 'lib/vanity/experiment/alternative.rb', line 58 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/alternative.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).

 ``` 34 35 36 37``` ```# File 'lib/vanity/experiment/alternative.rb', line 34 def converted load_counts unless @converted @converted end```

- (Object) inspect

 ``` 80 81 82``` ```# File 'lib/vanity/experiment/alternative.rb', line 80 def inspect "#{name}: #{value} #{converted}/#{participants}" end```

 ``` 84 85 86 87 88 89 90``` ```# 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```

- (Object) measure

The measure we use to order (sort) alternatives and decide which one is better (by calculating z-score). Defaults to conversion rate.

 ``` 64 65 66``` ```# File 'lib/vanity/experiment/alternative.rb', line 64 def measure conversion_rate end```

- (Object) participants

Number of participants who viewed this alternative.

 ``` 27 28 29 30``` ```# File 'lib/vanity/experiment/alternative.rb', line 27 def participants load_counts unless @participants @participants end```

- (Object) to_s

 ``` 76 77 78``` ```# File 'lib/vanity/experiment/alternative.rb', line 76 def to_s name end```