abanalyzer 0.0.5 → 0.0.6

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abanalyzer (0.0.5)
4
+ abanalyzer (0.0.6)
5
5
  statistics2 (>= 0.54)
6
6
 
7
7
  GEM
@@ -56,6 +56,34 @@ You can additionally get the actual score for either a Chi-Square test for indep
56
56
  puts tester.gtest_score
57
57
 
58
58
 
59
+ == Sample Size Calculations
60
+ Let's say you want to determine how large your sample size needs to be for an A/B test. Let's say your baseline is 10%, and you want to be able to determine if there's at least a 10% relative lift (1% absolute) to 11%. Let's assume you want a power[http://en.wikipedia.org/wiki/Statistical_power] of 0.8 and a {significance level}[http://en.wikipedia.org/wiki/Statistical_significance] of 0.05 (that is, an 80% chance of that you'll fail to recognize a difference when there is one, and a 5% chance of a false negative).
61
+
62
+ ...
63
+ ABAnalyzer.calculate_size(0.1, 0.11, 0.05, 0.8)
64
+ => 14751
65
+
66
+ This means that you will need at least 14,751 people in each group sample. You can see this same example with R at {on the 37 signals blog}[http://37signals.com/svn/posts/3004-ab-testing-tech-note-determining-sample-size].
67
+
68
+
69
+ == Confidence Intervals
70
+ You can also get a {confidence interval}[http://en.wikipedia.org/wiki/Confidence_interval]. Let's say you have the results of a test where there were 711 successes out of 4000 trials. To get a 95% confidence interval of the "true" value of the conversion rate, use:
71
+
72
+ ...
73
+ ABAnalyzer.confidence_interval(711, 4000, 0.95)
74
+ => [0.1659025512617185, 0.1895974487382815]
75
+
76
+ This means (roughly) that if you ran this experiment over and over, 95% of the time the resulting proportion would be between 17% and 19%.
77
+
78
+ You can also determine what the relative confidence intervals would be. Let's say that your old conversion rate was 13%, and you wanted to know what sort of relative lift you could get.
79
+
80
+ ...
81
+ ABAnalyzer.relative_confidence_interval(711, 4000, 0.13, 0.95)
82
+ => [0.27617347124398833, 0.45844191337139606]
83
+
84
+ This means (roughly) that if you ran this experiment over and over, 95% of the time the resulting proportion would be a relative lift of between 28% and 46%. Go buy yourself a beer!
85
+
86
+
59
87
  == Running Tests
60
88
  Testing can be run by using:
61
89
  rake test
@@ -0,0 +1,336 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
+
8
+ <title>Module: ABAnalyzer</title>
9
+
10
+ <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="./js/jquery.js" type="text/javascript"
13
+ charset="utf-8"></script>
14
+ <script src="./js/thickbox-compressed.js" type="text/javascript"
15
+ charset="utf-8"></script>
16
+ <script src="./js/quicksearch.js" type="text/javascript"
17
+ charset="utf-8"></script>
18
+ <script src="./js/darkfish.js" type="text/javascript"
19
+ charset="utf-8"></script>
20
+
21
+ </head>
22
+ <body class="module">
23
+
24
+ <div id="metadata">
25
+ <div id="home-metadata">
26
+ <div id="home-section" class="section">
27
+ <h3 class="section-header">
28
+ <a href="./index.html">Home</a>
29
+ <a href="./index.html#classes">Classes</a>
30
+ <a href="./index.html#methods">Methods</a>
31
+ </h3>
32
+ </div>
33
+ </div>
34
+
35
+ <div id="file-metadata">
36
+ <div id="file-list-section" class="section">
37
+ <h3 class="section-header">In Files</h3>
38
+ <div class="section-body">
39
+ <ul>
40
+
41
+ <li><a href="./lib/abanalyzer/abtest_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
42
+ class="thickbox" title="lib/abanalyzer/abtest.rb">lib/abanalyzer/abtest.rb</a></li>
43
+
44
+ <li><a href="./lib/abanalyzer/exceptions_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
45
+ class="thickbox" title="lib/abanalyzer/exceptions.rb">lib/abanalyzer/exceptions.rb</a></li>
46
+
47
+ <li><a href="./lib/abanalyzer/matrix_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
48
+ class="thickbox" title="lib/abanalyzer/matrix.rb">lib/abanalyzer/matrix.rb</a></li>
49
+
50
+ <li><a href="./lib/abanalyzer/sample_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
51
+ class="thickbox" title="lib/abanalyzer/sample.rb">lib/abanalyzer/sample.rb</a></li>
52
+
53
+ <li><a href="./lib/abanalyzer/version_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
54
+ class="thickbox" title="lib/abanalyzer/version.rb">lib/abanalyzer/version.rb</a></li>
55
+
56
+ </ul>
57
+ </div>
58
+ </div>
59
+
60
+
61
+ </div>
62
+
63
+ <div id="class-metadata">
64
+
65
+ <!-- Parent Class -->
66
+
67
+
68
+ <!-- Namespace Contents -->
69
+
70
+ <div id="namespace-list-section" class="section">
71
+ <h3 class="section-header">Namespace</h3>
72
+ <ul class="link-list">
73
+
74
+ <li><span class="type">CLASS</span> <a href="ABAnalyzer/ABTest.html">ABAnalyzer::ABTest</a></li>
75
+
76
+ <li><span class="type">CLASS</span> <a href="ABAnalyzer/InsufficientDataError.html">ABAnalyzer::InsufficientDataError</a></li>
77
+
78
+ <li><span class="type">CLASS</span> <a href="ABAnalyzer/Matrix.html">ABAnalyzer::Matrix</a></li>
79
+
80
+ <li><span class="type">CLASS</span> <a href="ABAnalyzer/MatrixFormatError.html">ABAnalyzer::MatrixFormatError</a></li>
81
+
82
+ </ul>
83
+ </div>
84
+
85
+
86
+ <!-- Method Quickref -->
87
+
88
+ <div id="method-list-section" class="section">
89
+ <h3 class="section-header">Methods</h3>
90
+ <ul class="link-list">
91
+
92
+ <li><a href="#method-c-calculate_size">::calculate_size</a></li>
93
+
94
+ <li><a href="#method-c-confidence_interval">::confidence_interval</a></li>
95
+
96
+ <li><a href="#method-c-relative_confidence_interval">::relative_confidence_interval</a></li>
97
+
98
+ </ul>
99
+ </div>
100
+
101
+
102
+ <!-- Included Modules -->
103
+
104
+ </div>
105
+
106
+ <div id="project-metadata">
107
+
108
+
109
+ <div id="fileindex-section" class="section project-section">
110
+ <h3 class="section-header">Files</h3>
111
+ <ul>
112
+
113
+ <li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
114
+
115
+ </ul>
116
+ </div>
117
+
118
+
119
+ <div id="classindex-section" class="section project-section">
120
+ <h3 class="section-header">Class Index
121
+ <span class="search-toggle"><img src="./images/find.png"
122
+ height="16" width="16" alt="[+]"
123
+ title="show/hide quicksearch" /></span></h3>
124
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
125
+ <fieldset>
126
+ <legend>Quicksearch</legend>
127
+ <input type="text" name="quicksearch" value=""
128
+ class="quicksearch-field" />
129
+ </fieldset>
130
+ </form>
131
+
132
+ <ul class="link-list">
133
+
134
+ <li><a href="./ABAnalyzer.html">ABAnalyzer</a></li>
135
+
136
+ <li><a href="./ABAnalyzer/ABTest.html">ABAnalyzer::ABTest</a></li>
137
+
138
+ <li><a href="./ABAnalyzer/InsufficientDataError.html">ABAnalyzer::InsufficientDataError</a></li>
139
+
140
+ <li><a href="./ABAnalyzer/Matrix.html">ABAnalyzer::Matrix</a></li>
141
+
142
+ <li><a href="./ABAnalyzer/MatrixFormatError.html">ABAnalyzer::MatrixFormatError</a></li>
143
+
144
+ </ul>
145
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
146
+ </div>
147
+
148
+
149
+ </div>
150
+ </div>
151
+
152
+ <div id="documentation">
153
+ <h1 class="module">ABAnalyzer</h1>
154
+
155
+ <div id="description">
156
+
157
+ </div>
158
+
159
+ <!-- Constants -->
160
+
161
+ <div id="constants-list" class="section">
162
+ <h3 class="section-header">Constants</h3>
163
+ <dl>
164
+
165
+ <dt><a name="VERSION">VERSION</a></dt>
166
+
167
+ <dd class="description"></dd>
168
+
169
+
170
+ </dl>
171
+ </div>
172
+
173
+
174
+ <!-- Attributes -->
175
+
176
+
177
+ <!-- Methods -->
178
+
179
+ <div id="public-class-method-details" class="method-section section">
180
+ <h3 class="section-header">Public Class Methods</h3>
181
+
182
+
183
+ <div id="calculate-size-method" class="method-detail ">
184
+ <a name="method-c-calculate_size"></a>
185
+
186
+ <div class="method-heading">
187
+
188
+ <span class="method-name">calculate_size</span><span
189
+ class="method-args">(p1, p2, significance, power)</span>
190
+ <span class="method-click-advice">click to toggle source</span>
191
+
192
+ </div>
193
+
194
+ <div class="method-description">
195
+
196
+ <p>
197
+ Calculate the minimum sample size (per group) based on the desire to detect
198
+ a increase from proportion p1 to proportion p2. Significance is generally
199
+ safe at 0.05 (why? just because) and a power of 0.8 (why? just because)
200
+ </p>
201
+
202
+
203
+
204
+ <div class="method-source-code"
205
+ id="calculate-size-source">
206
+ <pre>
207
+ <span class="ruby-comment cmt"># File lib/abanalyzer/sample.rb, line 8</span>
208
+ 8: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">calculate_size</span>(<span class="ruby-identifier">p1</span>, <span class="ruby-identifier">p2</span>, <span class="ruby-identifier">significance</span>, <span class="ruby-identifier">power</span>)
209
+ 9: [ <span class="ruby-identifier">p1</span>, <span class="ruby-identifier">p2</span>, <span class="ruby-identifier">significance</span>, <span class="ruby-identifier">power</span> ].<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>
210
+ 10: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;All arguments to calculate_size must be Floats&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Float</span>)
211
+ 11: }
212
+ 12:
213
+ 13: <span class="ruby-identifier">pbar</span> = (<span class="ruby-identifier">p1</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">p2</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>
214
+ 14: <span class="ruby-identifier">sides</span> = <span class="ruby-value">2.0</span>
215
+ 15:
216
+ 16: <span class="ruby-identifier">zcrit</span> = <span class="ruby-constant">Statistics2</span>.<span class="ruby-identifier">pnormaldist</span>(<span class="ruby-value">1</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">significance</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">sides</span>))
217
+ 17: <span class="ruby-identifier">zpow</span> = <span class="ruby-constant">Statistics2</span>.<span class="ruby-identifier">pnormaldist</span>(<span class="ruby-identifier">power</span>)
218
+ 18:
219
+ 19: <span class="ruby-identifier">numerator</span> = (<span class="ruby-identifier">zcrit</span> * <span class="ruby-constant">Math</span>.<span class="ruby-identifier">sqrt</span>(<span class="ruby-value">2</span> * <span class="ruby-identifier">pbar</span> * (<span class="ruby-value">1</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">pbar</span>)) <span class="ruby-operator">+</span> <span class="ruby-identifier">zpow</span> * <span class="ruby-constant">Math</span>.<span class="ruby-identifier">sqrt</span>(<span class="ruby-identifier">p2</span> * (<span class="ruby-value">1</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p2</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">p1</span> * (<span class="ruby-value">1</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p1</span>))) <span class="ruby-operator">**</span> <span class="ruby-value">2</span>
220
+ 20: <span class="ruby-identifier">denominator</span> = (<span class="ruby-identifier">p2</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p1</span>) <span class="ruby-operator">**</span> <span class="ruby-value">2</span>
221
+ 21: (<span class="ruby-identifier">numerator</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">denominator</span>).<span class="ruby-identifier">ceil</span>
222
+ 22: <span class="ruby-keyword kw">end</span></pre>
223
+ </div>
224
+
225
+ </div>
226
+
227
+
228
+
229
+
230
+ </div>
231
+
232
+
233
+ <div id="confidence-interval-method" class="method-detail ">
234
+ <a name="method-c-confidence_interval"></a>
235
+
236
+ <div class="method-heading">
237
+
238
+ <span class="method-name">confidence_interval</span><span
239
+ class="method-args">(successes, trials, confidence)</span>
240
+ <span class="method-click-advice">click to toggle source</span>
241
+
242
+ </div>
243
+
244
+ <div class="method-description">
245
+
246
+ <p>
247
+ Calculate the confidence interval given the number of successes and trials
248
+ at the desired confidence level. Returns an Array of [lower, upper]
249
+ </p>
250
+
251
+
252
+
253
+ <div class="method-source-code"
254
+ id="confidence-interval-source">
255
+ <pre>
256
+ <span class="ruby-comment cmt"># File lib/abanalyzer/sample.rb, line 26</span>
257
+ 26: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">confidence_interval</span>(<span class="ruby-identifier">successes</span>, <span class="ruby-identifier">trials</span>, <span class="ruby-identifier">confidence</span>)
258
+ 27: <span class="ruby-identifier">sides</span> = <span class="ruby-value">2.0</span>
259
+ 28: <span class="ruby-identifier">alpha</span> = <span class="ruby-value">1</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">confidence</span>
260
+ 29: <span class="ruby-identifier">zcrit</span> = <span class="ruby-constant">Statistics2</span>.<span class="ruby-identifier">pnormaldist</span>(<span class="ruby-value">1</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">alpha</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">sides</span>))
261
+ 30: <span class="ruby-identifier">p</span> = <span class="ruby-identifier">successes</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">trials</span>.<span class="ruby-identifier">to_f</span>
262
+ 31:
263
+ 32: <span class="ruby-identifier">interval</span> = <span class="ruby-identifier">zcrit</span> * <span class="ruby-constant">Math</span>.<span class="ruby-identifier">sqrt</span>((<span class="ruby-identifier">p</span> * (<span class="ruby-value">1</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">p</span>)) <span class="ruby-operator">/</span> <span class="ruby-identifier">trials</span>.<span class="ruby-identifier">to_f</span>)
264
+ 33: [<span class="ruby-identifier">p</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">interval</span>, <span class="ruby-identifier">p</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">interval</span>]
265
+ 34: <span class="ruby-keyword kw">end</span></pre>
266
+ </div>
267
+
268
+ </div>
269
+
270
+
271
+
272
+
273
+ </div>
274
+
275
+
276
+ <div id="relative-confidence-interval-method" class="method-detail ">
277
+ <a name="method-c-relative_confidence_interval"></a>
278
+
279
+ <div class="method-heading">
280
+
281
+ <span class="method-name">relative_confidence_interval</span><span
282
+ class="method-args">(successes, trials, compared_proportion, confidence)</span>
283
+ <span class="method-click-advice">click to toggle source</span>
284
+
285
+ </div>
286
+
287
+ <div class="method-description">
288
+
289
+ <p>
290
+ Like <a
291
+ href="ABAnalyzer.html#method-c-confidence_interval">confidence_interval</a>,
292
+ but returns the relative interval compared to the baseline given in
293
+ compared_proportion
294
+ </p>
295
+
296
+
297
+
298
+ <div class="method-source-code"
299
+ id="relative-confidence-interval-source">
300
+ <pre>
301
+ <span class="ruby-comment cmt"># File lib/abanalyzer/sample.rb, line 38</span>
302
+ 38: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">relative_confidence_interval</span>(<span class="ruby-identifier">successes</span>, <span class="ruby-identifier">trials</span>, <span class="ruby-identifier">compared_proportion</span>, <span class="ruby-identifier">confidence</span>)
303
+ 39: <span class="ruby-identifier">ci</span> = <span class="ruby-identifier">confidence_interval</span>(<span class="ruby-identifier">successes</span>, <span class="ruby-identifier">trials</span>, <span class="ruby-identifier">confidence</span>)
304
+ 40: [(<span class="ruby-identifier">ci</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">compared_proportion</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">compared_proportion</span>, (<span class="ruby-identifier">ci</span>.<span class="ruby-identifier">last</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">compared_proportion</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">compared_proportion</span>]
305
+ 41: <span class="ruby-keyword kw">end</span></pre>
306
+ </div>
307
+
308
+ </div>
309
+
310
+
311
+
312
+
313
+ </div>
314
+
315
+
316
+ </div>
317
+
318
+
319
+ </div>
320
+
321
+
322
+ <div id="rdoc-debugging-section-dump" class="debugging-section">
323
+
324
+ <p>Disabled; run with --debug to generate this.</p>
325
+
326
+ </div>
327
+
328
+ <div id="validator-badges">
329
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
330
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
331
+ Rdoc Generator</a> 1.1.6</small>.</p>
332
+ </div>
333
+
334
+ </body>
335
+ </html>
336
+
@@ -0,0 +1,559 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
+
8
+ <title>Class: ABAnalyzer::ABTest</title>
9
+
10
+ <link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="../js/jquery.js" type="text/javascript"
13
+ charset="utf-8"></script>
14
+ <script src="../js/thickbox-compressed.js" type="text/javascript"
15
+ charset="utf-8"></script>
16
+ <script src="../js/quicksearch.js" type="text/javascript"
17
+ charset="utf-8"></script>
18
+ <script src="../js/darkfish.js" type="text/javascript"
19
+ charset="utf-8"></script>
20
+
21
+ </head>
22
+ <body class="class">
23
+
24
+ <div id="metadata">
25
+ <div id="home-metadata">
26
+ <div id="home-section" class="section">
27
+ <h3 class="section-header">
28
+ <a href="../index.html">Home</a>
29
+ <a href="../index.html#classes">Classes</a>
30
+ <a href="../index.html#methods">Methods</a>
31
+ </h3>
32
+ </div>
33
+ </div>
34
+
35
+ <div id="file-metadata">
36
+ <div id="file-list-section" class="section">
37
+ <h3 class="section-header">In Files</h3>
38
+ <div class="section-body">
39
+ <ul>
40
+
41
+ <li><a href="../lib/abanalyzer/abtest_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
42
+ class="thickbox" title="lib/abanalyzer/abtest.rb">lib/abanalyzer/abtest.rb</a></li>
43
+
44
+ </ul>
45
+ </div>
46
+ </div>
47
+
48
+
49
+ </div>
50
+
51
+ <div id="class-metadata">
52
+
53
+ <!-- Parent Class -->
54
+
55
+ <div id="parent-class-section" class="section">
56
+ <h3 class="section-header">Parent</h3>
57
+
58
+ <p class="link">Object</p>
59
+
60
+ </div>
61
+
62
+
63
+ <!-- Namespace Contents -->
64
+
65
+
66
+ <!-- Method Quickref -->
67
+
68
+ <div id="method-list-section" class="section">
69
+ <h3 class="section-header">Methods</h3>
70
+ <ul class="link-list">
71
+
72
+ <li><a href="#method-c-chi2dist">::chi2dist</a></li>
73
+
74
+ <li><a href="#method-c-new">::new</a></li>
75
+
76
+ <li><a href="#method-i-chisquare_p">#chisquare_p</a></li>
77
+
78
+ <li><a href="#method-i-chisquare_score">#chisquare_score</a></li>
79
+
80
+ <li><a href="#method-i-df">#df</a></li>
81
+
82
+ <li><a href="#method-i-different%3F">#different?</a></li>
83
+
84
+ <li><a href="#method-i-expected">#expected</a></li>
85
+
86
+ <li><a href="#method-i-gtest_p">#gtest_p</a></li>
87
+
88
+ <li><a href="#method-i-gtest_score">#gtest_score</a></li>
89
+
90
+ <li><a href="#method-i-test_sufficient_data">#test_sufficient_data</a></li>
91
+
92
+ </ul>
93
+ </div>
94
+
95
+
96
+ <!-- Included Modules -->
97
+
98
+ </div>
99
+
100
+ <div id="project-metadata">
101
+
102
+
103
+ <div id="fileindex-section" class="section project-section">
104
+ <h3 class="section-header">Files</h3>
105
+ <ul>
106
+
107
+ <li class="file"><a href="../README_rdoc.html">README.rdoc</a></li>
108
+
109
+ </ul>
110
+ </div>
111
+
112
+
113
+ <div id="classindex-section" class="section project-section">
114
+ <h3 class="section-header">Class Index
115
+ <span class="search-toggle"><img src="../images/find.png"
116
+ height="16" width="16" alt="[+]"
117
+ title="show/hide quicksearch" /></span></h3>
118
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
119
+ <fieldset>
120
+ <legend>Quicksearch</legend>
121
+ <input type="text" name="quicksearch" value=""
122
+ class="quicksearch-field" />
123
+ </fieldset>
124
+ </form>
125
+
126
+ <ul class="link-list">
127
+
128
+ <li><a href="../ABAnalyzer.html">ABAnalyzer</a></li>
129
+
130
+ <li><a href="../ABAnalyzer/ABTest.html">ABAnalyzer::ABTest</a></li>
131
+
132
+ <li><a href="../ABAnalyzer/InsufficientDataError.html">ABAnalyzer::InsufficientDataError</a></li>
133
+
134
+ <li><a href="../ABAnalyzer/Matrix.html">ABAnalyzer::Matrix</a></li>
135
+
136
+ <li><a href="../ABAnalyzer/MatrixFormatError.html">ABAnalyzer::MatrixFormatError</a></li>
137
+
138
+ </ul>
139
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
140
+ </div>
141
+
142
+
143
+ </div>
144
+ </div>
145
+
146
+ <div id="documentation">
147
+ <h1 class="class">ABAnalyzer::ABTest</h1>
148
+
149
+ <div id="description">
150
+
151
+ </div>
152
+
153
+ <!-- Constants -->
154
+
155
+
156
+ <!-- Attributes -->
157
+
158
+
159
+ <!-- Methods -->
160
+
161
+ <div id="public-class-method-details" class="method-section section">
162
+ <h3 class="section-header">Public Class Methods</h3>
163
+
164
+
165
+ <div id="new-method" class="method-detail ">
166
+ <a name="method-c-new"></a>
167
+
168
+ <div class="method-heading">
169
+
170
+ <span class="method-name">new</span><span
171
+ class="method-args">(values)</span>
172
+ <span class="method-click-advice">click to toggle source</span>
173
+
174
+ </div>
175
+
176
+ <div class="method-description">
177
+
178
+ <p>
179
+ values should be hash of hashes, with top level hash the group names: {
180
+ :groupa => { :yes => 20, :no => 10 }, :groupb => { :yes => 18, :no => 8 } }
181
+ </p>
182
+
183
+
184
+
185
+ <div class="method-source-code"
186
+ id="new-source">
187
+ <pre>
188
+ <span class="ruby-comment cmt"># File lib/abanalyzer/abtest.rb, line 8</span>
189
+ 8: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">values</span>)
190
+ 9: <span class="ruby-ivar">@values</span> = <span class="ruby-constant">Matrix</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">values</span>
191
+ 10: <span class="ruby-keyword kw">end</span></pre>
192
+ </div>
193
+
194
+ </div>
195
+
196
+
197
+
198
+
199
+ </div>
200
+
201
+
202
+ </div>
203
+
204
+ <div id="private-class-method-details" class="method-section section">
205
+ <h3 class="section-header">Private Class Methods</h3>
206
+
207
+
208
+ <div id="chi-dist-method" class="method-detail ">
209
+ <a name="method-c-chi2dist"></a>
210
+
211
+ <div class="method-heading">
212
+
213
+ <span class="method-name">chi2dist</span><span
214
+ class="method-args">(degrees, score)</span>
215
+ <span class="method-click-advice">click to toggle source</span>
216
+
217
+ </div>
218
+
219
+ <div class="method-description">
220
+
221
+
222
+
223
+
224
+
225
+ <div class="method-source-code"
226
+ id="chi-dist-source">
227
+ <pre>
228
+ <span class="ruby-comment cmt"># File lib/abanalyzer/abtest.rb, line 58</span>
229
+ 58: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">chi2dist</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">score</span>)
230
+ 59: <span class="ruby-value">1</span> <span class="ruby-operator">-</span> <span class="ruby-constant">Statistics2</span>.<span class="ruby-identifier">chi2dist</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">score</span>)
231
+ 60: <span class="ruby-keyword kw">end</span></pre>
232
+ </div>
233
+
234
+ </div>
235
+
236
+
237
+
238
+
239
+ </div>
240
+
241
+
242
+ </div>
243
+
244
+ <div id="public-instance-method-details" class="method-section section">
245
+ <h3 class="section-header">Public Instance Methods</h3>
246
+
247
+
248
+ <div id="chisquare-p-method" class="method-detail ">
249
+ <a name="method-i-chisquare_p"></a>
250
+
251
+ <div class="method-heading">
252
+
253
+ <span class="method-name">chisquare_p</span><span
254
+ class="method-args">()</span>
255
+ <span class="method-click-advice">click to toggle source</span>
256
+
257
+ </div>
258
+
259
+ <div class="method-description">
260
+
261
+
262
+
263
+
264
+
265
+ <div class="method-source-code"
266
+ id="chisquare-p-source">
267
+ <pre>
268
+ <span class="ruby-comment cmt"># File lib/abanalyzer/abtest.rb, line 36</span>
269
+ 36: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">chisquare_p</span>
270
+ 37: <span class="ruby-constant">ABTest</span>.<span class="ruby-identifier">chi2dist</span>(<span class="ruby-identifier">df</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">chisquare_score</span>)
271
+ 38: <span class="ruby-keyword kw">end</span></pre>
272
+ </div>
273
+
274
+ </div>
275
+
276
+
277
+
278
+
279
+ </div>
280
+
281
+
282
+ <div id="chisquare-score-method" class="method-detail ">
283
+ <a name="method-i-chisquare_score"></a>
284
+
285
+ <div class="method-heading">
286
+
287
+ <span class="method-name">chisquare_score</span><span
288
+ class="method-args">()</span>
289
+ <span class="method-click-advice">click to toggle source</span>
290
+
291
+ </div>
292
+
293
+ <div class="method-description">
294
+
295
+
296
+
297
+
298
+
299
+ <div class="method-source-code"
300
+ id="chisquare-score-source">
301
+ <pre>
302
+ <span class="ruby-comment cmt"># File lib/abanalyzer/abtest.rb, line 16</span>
303
+ 16: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">chisquare_score</span>
304
+ 17: <span class="ruby-identifier">sum</span>=<span class="ruby-value">0</span>
305
+ 18: <span class="ruby-ivar">@values</span>.<span class="ruby-identifier">each_cell</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">colname</span>, <span class="ruby-identifier">rowname</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
306
+ 19: <span class="ruby-identifier">ex</span> = <span class="ruby-identifier">expected</span>(<span class="ruby-identifier">colname</span>, <span class="ruby-identifier">rowname</span>)
307
+ 20: <span class="ruby-identifier">test_sufficient_data</span>(<span class="ruby-identifier">colname</span>, <span class="ruby-identifier">rowname</span>, <span class="ruby-identifier">ex</span>, <span class="ruby-identifier">value</span>)
308
+ 21: <span class="ruby-identifier">sum</span> <span class="ruby-operator">+=</span> ((<span class="ruby-identifier">value</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">ex</span>) <span class="ruby-operator">**</span> <span class="ruby-value">2</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">ex</span>
309
+ 22: }
310
+ 23: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">sum</span>
311
+ 24: <span class="ruby-keyword kw">end</span></pre>
312
+ </div>
313
+
314
+ </div>
315
+
316
+
317
+
318
+
319
+ </div>
320
+
321
+
322
+ <div id="different--method" class="method-detail ">
323
+ <a name="method-i-different%3F"></a>
324
+
325
+ <div class="method-heading">
326
+
327
+ <span class="method-name">different?</span><span
328
+ class="method-args">(sig=0.05)</span>
329
+ <span class="method-click-advice">click to toggle source</span>
330
+
331
+ </div>
332
+
333
+ <div class="method-description">
334
+
335
+
336
+
337
+
338
+
339
+ <div class="method-source-code"
340
+ id="different--source">
341
+ <pre>
342
+ <span class="ruby-comment cmt"># File lib/abanalyzer/abtest.rb, line 12</span>
343
+ 12: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">different?</span>(<span class="ruby-identifier">sig</span>=<span class="ruby-value">0.05</span>)
344
+ 13: <span class="ruby-identifier">gtest_p</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">sig</span>
345
+ 14: <span class="ruby-keyword kw">end</span></pre>
346
+ </div>
347
+
348
+ </div>
349
+
350
+
351
+
352
+
353
+ </div>
354
+
355
+
356
+ <div id="gtest-p-method" class="method-detail ">
357
+ <a name="method-i-gtest_p"></a>
358
+
359
+ <div class="method-heading">
360
+
361
+ <span class="method-name">gtest_p</span><span
362
+ class="method-args">()</span>
363
+ <span class="method-click-advice">click to toggle source</span>
364
+
365
+ </div>
366
+
367
+ <div class="method-description">
368
+
369
+
370
+
371
+
372
+
373
+ <div class="method-source-code"
374
+ id="gtest-p-source">
375
+ <pre>
376
+ <span class="ruby-comment cmt"># File lib/abanalyzer/abtest.rb, line 40</span>
377
+ 40: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gtest_p</span>
378
+ 41: <span class="ruby-constant">ABTest</span>.<span class="ruby-identifier">chi2dist</span>(<span class="ruby-identifier">df</span>, <span class="ruby-value">2</span>*<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">gtest_score</span>)
379
+ 42: <span class="ruby-keyword kw">end</span></pre>
380
+ </div>
381
+
382
+ </div>
383
+
384
+
385
+
386
+
387
+ </div>
388
+
389
+
390
+ <div id="gtest-score-method" class="method-detail ">
391
+ <a name="method-i-gtest_score"></a>
392
+
393
+ <div class="method-heading">
394
+
395
+ <span class="method-name">gtest_score</span><span
396
+ class="method-args">()</span>
397
+ <span class="method-click-advice">click to toggle source</span>
398
+
399
+ </div>
400
+
401
+ <div class="method-description">
402
+
403
+
404
+
405
+
406
+
407
+ <div class="method-source-code"
408
+ id="gtest-score-source">
409
+ <pre>
410
+ <span class="ruby-comment cmt"># File lib/abanalyzer/abtest.rb, line 26</span>
411
+ 26: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gtest_score</span>
412
+ 27: <span class="ruby-identifier">sum</span>=<span class="ruby-value">0</span>
413
+ 28: <span class="ruby-ivar">@values</span>.<span class="ruby-identifier">each_cell</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">colname</span>, <span class="ruby-identifier">rowname</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
414
+ 29: <span class="ruby-identifier">ex</span> = <span class="ruby-identifier">expected</span>(<span class="ruby-identifier">colname</span>, <span class="ruby-identifier">rowname</span>)
415
+ 30: <span class="ruby-identifier">test_sufficient_data</span>(<span class="ruby-identifier">colname</span>, <span class="ruby-identifier">rowname</span>, <span class="ruby-identifier">ex</span>, <span class="ruby-identifier">value</span>)
416
+ 31: <span class="ruby-identifier">sum</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">value</span> * <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">value</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">ex</span>)
417
+ 32: }
418
+ 33: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">sum</span>
419
+ 34: <span class="ruby-keyword kw">end</span></pre>
420
+ </div>
421
+
422
+ </div>
423
+
424
+
425
+
426
+
427
+ </div>
428
+
429
+
430
+ </div>
431
+
432
+ <div id="private-instance-method-details" class="method-section section">
433
+ <h3 class="section-header">Private Instance Methods</h3>
434
+
435
+
436
+ <div id="df-method" class="method-detail ">
437
+ <a name="method-i-df"></a>
438
+
439
+ <div class="method-heading">
440
+
441
+ <span class="method-name">df</span><span
442
+ class="method-args">()</span>
443
+ <span class="method-click-advice">click to toggle source</span>
444
+
445
+ </div>
446
+
447
+ <div class="method-description">
448
+
449
+
450
+
451
+
452
+
453
+ <div class="method-source-code"
454
+ id="df-source">
455
+ <pre>
456
+ <span class="ruby-comment cmt"># File lib/abanalyzer/abtest.rb, line 54</span>
457
+ 54: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">df</span>
458
+ 55: (<span class="ruby-ivar">@values</span>.<span class="ruby-identifier">columns</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>) * (<span class="ruby-ivar">@values</span>.<span class="ruby-identifier">rows</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
459
+ 56: <span class="ruby-keyword kw">end</span></pre>
460
+ </div>
461
+
462
+ </div>
463
+
464
+
465
+
466
+
467
+ </div>
468
+
469
+
470
+ <div id="expected-method" class="method-detail ">
471
+ <a name="method-i-expected"></a>
472
+
473
+ <div class="method-heading">
474
+
475
+ <span class="method-name">expected</span><span
476
+ class="method-args">(colname, rowname)</span>
477
+ <span class="method-click-advice">click to toggle source</span>
478
+
479
+ </div>
480
+
481
+ <div class="method-description">
482
+
483
+
484
+
485
+
486
+
487
+ <div class="method-source-code"
488
+ id="expected-source">
489
+ <pre>
490
+ <span class="ruby-comment cmt"># File lib/abanalyzer/abtest.rb, line 50</span>
491
+ 50: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">expected</span>(<span class="ruby-identifier">colname</span>, <span class="ruby-identifier">rowname</span>)
492
+ 51: (<span class="ruby-ivar">@values</span>.<span class="ruby-identifier">row_sum</span>(<span class="ruby-identifier">rowname</span>) * <span class="ruby-ivar">@values</span>.<span class="ruby-identifier">column_sum</span>(<span class="ruby-identifier">colname</span>)).<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-ivar">@values</span>.<span class="ruby-identifier">total_sum</span>.<span class="ruby-identifier">to_f</span>
493
+ 52: <span class="ruby-keyword kw">end</span></pre>
494
+ </div>
495
+
496
+ </div>
497
+
498
+
499
+
500
+
501
+ </div>
502
+
503
+
504
+ <div id="test-sufficient-data-method" class="method-detail ">
505
+ <a name="method-i-test_sufficient_data"></a>
506
+
507
+ <div class="method-heading">
508
+
509
+ <span class="method-name">test_sufficient_data</span><span
510
+ class="method-args">(colname, rowname, expected, value)</span>
511
+ <span class="method-click-advice">click to toggle source</span>
512
+
513
+ </div>
514
+
515
+ <div class="method-description">
516
+
517
+
518
+
519
+
520
+
521
+ <div class="method-source-code"
522
+ id="test-sufficient-data-source">
523
+ <pre>
524
+ <span class="ruby-comment cmt"># File lib/abanalyzer/abtest.rb, line 45</span>
525
+ 45: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">test_sufficient_data</span>(<span class="ruby-identifier">colname</span>, <span class="ruby-identifier">rowname</span>, <span class="ruby-identifier">expected</span>, <span class="ruby-identifier">value</span>)
526
+ 46: <span class="ruby-identifier">msg</span> = <span class="ruby-node">&quot;Insufficient data size for column #{colname} row #{rowname}. Expected value must be &gt;= 5, and value must be &gt; 0.&quot;</span>
527
+ 47: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InsufficientDataError</span>, <span class="ruby-identifier">msg</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">expected</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">5</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value">0</span>
528
+ 48: <span class="ruby-keyword kw">end</span></pre>
529
+ </div>
530
+
531
+ </div>
532
+
533
+
534
+
535
+
536
+ </div>
537
+
538
+
539
+ </div>
540
+
541
+
542
+ </div>
543
+
544
+
545
+ <div id="rdoc-debugging-section-dump" class="debugging-section">
546
+
547
+ <p>Disabled; run with --debug to generate this.</p>
548
+
549
+ </div>
550
+
551
+ <div id="validator-badges">
552
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
553
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
554
+ Rdoc Generator</a> 1.1.6</small>.</p>
555
+ </div>
556
+
557
+ </body>
558
+ </html>
559
+