abanalyzer 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bandit.gemspec
4
+ gemspec
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ abanalyzer (0.0.5)
5
+ statistics2 (>= 0.54)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ statistics2 (0.54)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ abanalyzer!
data/Rakefile CHANGED
@@ -1,16 +1,12 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
1
  require 'rubygems'
3
- require 'rake'
2
+ require 'bundler'
4
3
  require 'rake/testtask'
5
- require 'rake/rdoctask'
6
- require 'rake/gempackagetask'
4
+ require 'rdoc/task'
7
5
 
8
- require 'date'
9
-
10
- require "abanalyzer/version"
6
+ Bundler::GemHelper.install_tasks
11
7
 
12
8
  desc "Create documentation"
13
- Rake::RDocTask.new("doc") { |rdoc|
9
+ RDoc::Task.new("doc") { |rdoc|
14
10
  rdoc.title = "ABAnalyzer - A/B test analysis library for Ruby"
15
11
  rdoc.rdoc_dir = 'docs'
16
12
  rdoc.rdoc_files.include('README.rdoc')
@@ -19,29 +15,7 @@ Rake::RDocTask.new("doc") { |rdoc|
19
15
 
20
16
  desc "Run all unit tests"
21
17
  Rake::TestTask.new("test") { |t|
22
- t.libs << "lib"
18
+ t.libs +=[ "lib", "." ]
23
19
  t.test_files = FileList['test/*_test.rb']
24
20
  t.verbose = true
25
21
  }
26
-
27
- spec = Gem::Specification.new do |s|
28
- s.name = "abanalyzer"
29
- s.version = ABAnalyzer::VERSION
30
- s.authors = ["Brian Muller"]
31
- s.date = Date.today.to_s
32
- s.description = "A/B test analysis library for Ruby - performs Chi-Square tests and G-tests on A/B results."
33
- s.summary = "Performs statistical tests for significant differences in categorical data."
34
- s.email = "brian.muller@livingsocial.com"
35
- s.files = FileList["lib/**/*", "[A-Z]*", "Rakefile", "docs/**/*"]
36
- s.homepage = "https://github.com/livingsocial/abanalyzer"
37
- s.require_paths = ["lib"]
38
- s.add_dependency('statistics2', '>= 0.54')
39
- end
40
-
41
- Rake::GemPackageTask.new(spec) do |pkg|
42
- pkg.need_zip = true
43
- pkg.need_tar = true
44
- end
45
-
46
- desc "Default task: builds gem and runs tests"
47
- task :default => [ :gem, :test ]
@@ -2,3 +2,4 @@ require 'abanalyzer/matrix'
2
2
  require 'abanalyzer/abtest'
3
3
  require 'abanalyzer/exceptions'
4
4
  require 'abanalyzer/version'
5
+ require 'abanalyzer/sample'
@@ -0,0 +1,42 @@
1
+ require 'statistics2'
2
+
3
+ module ABAnalyzer
4
+
5
+ # Calculate the minimum sample size (per group) based on the desire to detect
6
+ # a increase from proportion p1 to proportion p2. Significance is generally
7
+ # safe at 0.05 (why? just because) and a power of 0.8 (why? just because)
8
+ def self.calculate_size(p1, p2, significance, power)
9
+ [ p1, p2, significance, power ].each { |a|
10
+ raise "All arguments to calculate_size must be Floats" unless a.is_a?(Float)
11
+ }
12
+
13
+ pbar = (p1 + p2) / 2.0
14
+ sides = 2.0
15
+
16
+ zcrit = Statistics2.pnormaldist(1 - (significance / sides))
17
+ zpow = Statistics2.pnormaldist(power)
18
+
19
+ numerator = (zcrit * Math.sqrt(2 * pbar * (1 - pbar)) + zpow * Math.sqrt(p2 * (1 - p2) + p1 * (1 - p1))) ** 2
20
+ denominator = (p2 - p1) ** 2
21
+ (numerator / denominator).ceil
22
+ end
23
+
24
+ # Calculate the confidence interval given the number of successes and trials at
25
+ # the desired level of significance. Returns an Array of [lower, upper]
26
+ def self.confidence_interval(successes, trials, alpha)
27
+ sides = 2.0
28
+ zcrit = Statistics2.pnormaldist(1 - (alpha / sides))
29
+ p = successes.to_f / trials.to_f
30
+
31
+ interval = zcrit * Math.sqrt((p * (1 - p)) / trials.to_f)
32
+ [p - interval, p + interval]
33
+ end
34
+
35
+ # Like confidence_interval, but returns the relative interval compared to the baseline given
36
+ # in compared_proportion
37
+ def self.relative_confidence_interval(successes, trials, compared_proportion, alpha)
38
+ ci = confidence_interval(successes, trials, alpha)
39
+ [(ci.first - compared_proportion) / compared_proportion, (ci.last - compared_proportion) / compared_proportion]
40
+ end
41
+
42
+ end
@@ -1,3 +1,3 @@
1
1
  module ABAnalyzer
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,88 +1,66 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: abanalyzer
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 4
10
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Brian Muller
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-04-21 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: statistics2
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70291725609180 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 103
30
- segments:
31
- - 0
32
- - 54
33
- version: "0.54"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.54'
34
22
  type: :runtime
35
- version_requirements: *id001
36
- description: A/B test analysis library for Ruby - performs Chi-Square tests and G-tests on A/B results.
23
+ prerelease: false
24
+ version_requirements: *70291725609180
25
+ description: A/B test analysis library for Ruby
37
26
  email: brian.muller@livingsocial.com
38
27
  executables: []
39
-
40
28
  extensions: []
41
-
42
29
  extra_rdoc_files: []
43
-
44
- files:
30
+ files:
45
31
  - lib/abanalyzer/abtest.rb
46
32
  - lib/abanalyzer/exceptions.rb
47
33
  - lib/abanalyzer/matrix.rb
34
+ - lib/abanalyzer/sample.rb
48
35
  - lib/abanalyzer/version.rb
49
36
  - lib/abanalyzer.rb
37
+ - Gemfile
38
+ - Gemfile.lock
50
39
  - LICENSE
51
40
  - Rakefile
52
41
  - README.rdoc
53
- has_rdoc: true
54
42
  homepage: https://github.com/livingsocial/abanalyzer
55
43
  licenses: []
56
-
57
44
  post_install_message:
58
45
  rdoc_options: []
59
-
60
- require_paths:
46
+ require_paths:
61
47
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
48
+ required_ruby_version: !ruby/object:Gem::Requirement
63
49
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
- version: "0"
71
- required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
55
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 0
79
- version: "0"
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
80
60
  requirements: []
81
-
82
- rubyforge_project:
83
- rubygems_version: 1.3.7
61
+ rubyforge_project: abanalyzer
62
+ rubygems_version: 1.8.17
84
63
  signing_key:
85
64
  specification_version: 3
86
- summary: Performs statistical tests for significant differences in categorical data.
65
+ summary: A/B test analysis library for Ruby
87
66
  test_files: []
88
-