<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Rohan Arora</title>
<link>https://arorarohan.com/posts.html</link>
<atom:link href="https://arorarohan.com/posts.xml" rel="self" type="application/rss+xml"/>
<description></description>
<generator>quarto-1.7.32</generator>
<lastBuildDate>Mon, 05 Jan 2026 22:00:00 GMT</lastBuildDate>
<item>
  <title>Null but not a void: Examining a non-zero null hypothesis</title>
  <dc:creator>Rohan Arora</dc:creator>
  <link>https://arorarohan.com/posts/20260106-non-zero-null/</link>
  <description><![CDATA[ 





<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://arorarohan.com/posts/20260106-non-zero-null/nz-null-pastel.jpg" id="hero" class="img-fluid quarto-figure quarto-figure-center anchored figure-img" alt="Random GPT generated hero banner." width="533"></p>
</figure>
</div>
<section id="introduction" class="level1">
<h1>Introduction</h1>
<p>This will be a relatively short post. We are generally used to defining the null hypothesis in an A/B test as there being <em>no difference in performance</em> (most often the conversion rate) between two designs. But from a strictly mathematical point of view, this doesn’t necessarily have to be the case.</p>
<p>We can instead define a non-zero null hypothesis and run an experiment to see if the new design results in a better performance by some non-zero margin. This may be useful, for example, in a situation where a new design must guarantee a certain minimum improvement to be viable.</p>
<p>The more useful scenario is when running sequential tests, which will be discussed in a separate post. Now, on to the math.</p>
</section>
<section id="the-math" class="level1">
<h1>The Math</h1>
<p>Somewhat informally, statistical power is the probability of the statistic under test being in the rejection region under the alternate hypothesis. Unless we are dealing with average power across multiple possible alternative thresholds, this boils down to establishing the required sample-size for a fixed-sample statistical test for a <em>given</em> choice of the alternative hypothesis, i.e.&nbsp;a point alternative.</p>
<p>We’ll denote the impact of change as the random variable <img src="https://latex.codecogs.com/png.latex?%5CDelta">, whose realised value will be denoted as <img src="https://latex.codecogs.com/png.latex?%5Cdelta">. <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5CDelta%7D"> is the estimator for <img src="https://latex.codecogs.com/png.latex?%5CDelta">. Under the usual i.i.d. assumptions and random allocation, <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5CDelta%7D"> is considered to be normally distributed with some mean <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> and sampling variance <img src="https://latex.codecogs.com/png.latex?%5Ctau%5E2">.</p>
<p><span id="eq-1"><img src="https://latex.codecogs.com/png.latex?%0A%5CDelta%20%5Cmid%20%5Chat%7B%5CDelta%7D%20=%20%5Cdelta,%20%5Ctau%5E2%20~%20%5Cmathcal%7BN%7D(%5Cdelta,%5Ctau%5E2)%0A%5Ctag%7B1%7D"></span></p>
<p>The sampling variance for the estimator is usually considered to be a constant.</p>
<p>Usually, the null is defined as <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BH%7D_0:%5Cdelta_0%20=%200"> but we’ll define the null and effect-size (i.e.&nbsp;alternative at a fixed point) as:</p>
<p><span id="eq-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7BH%7D_0:%5Cdelta_0%20%5Cne%200%20%5C;%5C;%5C;%20%5C&amp;%20%5C;%5C;%5C;%20%5Cmathcal%7BH%7D_a:%5Cdelta_a%20%5Cne%200%0A%5Ctag%7B2%7D"></span></p>
<p>This causes the statistical power – for a given type 1 error rate <img src="https://latex.codecogs.com/png.latex?%5Calpha"> – to be modified as follows:</p>
<p><span id="eq-3"><img src="https://latex.codecogs.com/png.latex?%0A%5CPi(%5Cdelta_0,%5Cdelta_a,%5Ctau%5E2,%5Calpha)%20=%20%5CBig%5B1%20-%20%5CPhi%5CBig(%5CPhi%5E%7B-1%7D(1-%5Calpha/2)%20-%20%5Cfrac%7B%5Cdelta_a-%5Cdelta_0%7D%7B%5Ctau%7D%5CBig)%5CBig%5D%20+%20%5CBig%5B%5CPhi%5CBig(%5CPhi%5E%7B-1%7D(%5Calpha/2)%20-%20%5Cfrac%7B%5Cdelta_a-%5Cdelta_0%7D%7B%5Ctau%7D%5CBig)%5CBig%5D%0A%5Ctag%7B3%7D"></span></p>
<p>We can also denote power as <img src="https://latex.codecogs.com/png.latex?%5CPi%20=%201%20-%20%5Cbeta">.</p>
<p>The key thing to notice here is that the effect size has changed from being defined by just the alternate point-hypothesis to both the null and the alternate point-hypotheses.</p>
<p>It’s easy to see that this reduces to the usual form for <img src="https://latex.codecogs.com/png.latex?%5Cdelta_0=0">. The tricky part, however, is analysing the impact on sample-size and the potential lift values where the null will be rejected.</p>
<section id="the-curious-case-of-cro." class="level2">
<h2 class="anchored" data-anchor-id="the-curious-case-of-cro.">The curious case of CRO.</h2>
<p>We’ll study non-zero null hypothesis testing for conversion rates. For CRO, we usually define an MDE<sup>1</sup>. With the usual zero null, <img src="https://latex.codecogs.com/png.latex?%5Cdelta_a%20=%20p_1*MDE.">, where <img src="https://latex.codecogs.com/png.latex?p_1"> represents the historical rate. For convenience, we’ll be defining the non-zero null in a similar fashion. Ergo, <img src="https://latex.codecogs.com/png.latex?%5Cdelta_0%20=%20p_1*TE">, where <em>TE</em> represents the <em>threshold effect</em> under the null hypothesis.</p>
<p>We’ll look at two cases of the alternative hypothesis with a non-zero null:</p>
<ol type="1">
<li><strong>Inclusive of null</strong>: The (scaled) effect-size is the difference between the null and the alternative. Therefore, <img src="https://latex.codecogs.com/png.latex?%5Cdelta_a%20-%20%5Cdelta_0%20=%20p_1*(MDE-TE)">.</li>
<li><strong>Over-and-above null</strong>: <img src="https://latex.codecogs.com/png.latex?%5Cdelta_a"> is defined as a difference over and above the null. Therefore, <img src="https://latex.codecogs.com/png.latex?%5Cdelta_a%20-%5Cdelta_0%20=%20p_1*(MDE)"> in the usual way.</li>
</ol>
<p>This distinction is necessary due to the fact that the sample-size is a function of the effect-size and the choice of the definition of <img src="https://latex.codecogs.com/png.latex?%5Cdelta_a"> will have implications for the amount of data that needs to be collected.</p>
<p>It’s common practice to estimate a sample-size from a historical rate, so we’ll use <img src="https://latex.codecogs.com/png.latex?p_1"> as the historical conversion rate (for design A). For the purpose of sample-size estimation, the conversion rate for design B will be <img src="https://latex.codecogs.com/png.latex?p_2%20=%20p_1*(1%20+%20MDE)">. Generally we can ignore either the first or the second term in the RHS of equation Equation&nbsp;3, so the calculation of <em>total</em> sample-size simplifies to:</p>
<p><span id="eq-4"><img src="https://latex.codecogs.com/png.latex?%0AN%20=%20%5CBig%5B%20%5Cfrac%7B%5CPhi%5E%7B-1%7D(1-%5Cbeta)+%5CPhi%5E%7B-1%7D(1-%5Calpha/2)%7D%7BE.S.%7D%5CBig%5D%5E2%0A%5Ctag%7B4%7D"></span></p>
<p>where E.S. represents the <em>effect size</em>. For conversion rates,</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AE.S.%20=%20%5Cfrac%7B%5Cdelta_a-%5Cdelta_0%7D%7B%5Csqrt%7B%5Cfrac%7Bp_1*q_1%7D%7B%5Cmathcal%7Bv%7D%7D+%5Cfrac%7Bp_1*q_1%7D%7B%5Cmathcal%7B1-v%7D%7D%7D%7D%0A"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?q_i=1-p_i"> and <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bv%7D%20%5Cin%20(0,1)"> represents the share of the sample-size for design A. The optimal of course is at <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bv%7D=50%5C%25">. Okay, let’s look at the implications.</p>
</section>
</section>
<section id="the-implications" class="level1">
<h1>The Implications</h1>
<section id="sample-size" class="level2">
<h2 class="anchored" data-anchor-id="sample-size">Sample-size</h2>
<p>It’s easy enough to see that the sample-size increases if the effect-size decreases, which will decrease if the point alternative is ‘inclusive of null’ as defined earlier. If the point alternative is ‘over-and-above’ the null, the sample-size should then remain the same as what we would get for a zero-null.</p>
<p><em>Note that m.d.e. should not equal t.e. as that would set the effect-size to zero.</em></p>
<p>The more crucial implications are about how the null hypothesis gets rejected.</p>
</section>
<section id="rejection-region" class="level2">
<h2 class="anchored" data-anchor-id="rejection-region">Rejection Region</h2>
<p>Rejection region<sup>2</sup> is the set of values for the observed statistic <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5CDelta%7D"> where the null hypothesis gets rejected. Shifting the null hypothesis changes the rejection region.</p>
</section>
</section>
<section id="visualising-the-implications" class="level1">
<h1>Visualising the implications</h1>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(glue)</span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#library(furrr)</span></span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggthemes)</span>
<span id="cb1-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#library(progressr)</span></span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(extrafont) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#You can skip it if you like, it's for text on charts.</span></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gridExtra)</span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(knitr)</span>
<span id="cb1-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rlang)</span>
<span id="cb1-10"></span>
<span id="cb1-11"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">##Modify this as per your computing setup</span></span>
<span id="cb1-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#plan(strategy = 'multisession',workers = 16)</span></span></code></pre></div>
</details>
</div>
<p>Let’s take some example values as follows:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ap_1%20=%2010%5C%25%20%5Cquad%20MDE%20=%205%5C%25%20%5Cquad%20TE%20=%202%5C%25%20%5Cquad%20%5Cmathcal%7Bv%7D=0.5%5C;;%5C;%20%5Calpha=10%5C%25%20%5Cquad%20%5Cbeta=20%5C%25%0A"> We’ll use a 2-tailed test of proportions.</p>
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">p1<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>; q1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p1</span>
<span id="cb2-2"></span>
<span id="cb2-3">mde<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span></span>
<span id="cb2-4">p2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>mde); q2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p2</span>
<span id="cb2-5"></span>
<span id="cb2-6">te<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">02</span>; v<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>; a<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>; b<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb2-7"></span>
<span id="cb2-8">ab_const <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>a<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>b))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb2-9">t2_const <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>v)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>(p2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>v))</span>
<span id="cb2-10"></span>
<span id="cb2-11">ss <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> ab_const<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">es0 =</span> (p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>mde)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">es1 =</span> (p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(mde<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>te))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">es2 =</span> (p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>mde)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>t2_const)</span>
<span id="cb2-12"></span>
<span id="cb2-13">scen_labels <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Zero Null'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Inclusive non-zero Null'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Over-n-above Non-zero Null'</span>)</span>
<span id="cb2-14"></span>
<span id="cb2-15">dt1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb2-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Scenario =</span> scen_labels, </span>
<span id="cb2-17">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Estd. Sample-size</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</span>(ss), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.mark =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.interval =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>L))</span>
<span id="cb2-18"></span>
<span id="cb2-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(dt1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">align =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'l'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'r'</span>))</span></code></pre></div>
</details>
<div id="tbl-01" class="quarto-layout-panel anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-01-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: Required total sample-size under various scenarios
</figcaption>
<div aria-describedby="tbl-01-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: center;">
<table class="do-not-create-environment cell caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Scenario</th>
<th style="text-align: right;">Estd. Sample-size</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Zero Null</td>
<td style="text-align: right;">90,995</td>
</tr>
<tr class="even">
<td style="text-align: left;">Inclusive non-zero Null</td>
<td style="text-align: right;">252,764</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Over-n-above Non-zero Null</td>
<td style="text-align: right;">90,995</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</figure>
</div>
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">crit_bounds <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map2</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.x =</span> ss, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>te,p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>te), </span>
<span id="cb3-2">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{round(qnorm(c(a/2,1-a/2),.y,sqrt(t2_const/.x))/p1*100,2)}%"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_cols</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Bound Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Lower Bound'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Upper Bound'</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id_cols =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Bound Type</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Scenario =</span> scen_labels) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Scenario, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Lower Bound</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Upper Bound</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)</span>
<span id="cb3-6"></span>
<span id="cb3-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(crit_bounds,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">align =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'l'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'c'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'c'</span>))</span></code></pre></div>
</details>
<div id="tbl-02" class="quarto-layout-panel anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-02-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;2: Critical bounds for observed lift where the null will be rejected
</figcaption>
<div aria-describedby="tbl-02-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: center;">
<table class="do-not-create-environment cell caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Scenario</th>
<th style="text-align: center;">Lower Bound</th>
<th style="text-align: center;">Upper Bound</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Zero Null</td>
<td style="text-align: center;">-3.31%</td>
<td style="text-align: center;">3.31%</td>
</tr>
<tr class="even">
<td style="text-align: left;">Inclusive non-zero Null</td>
<td style="text-align: center;">0.02%</td>
<td style="text-align: center;">3.98%</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Over-n-above Non-zero Null</td>
<td style="text-align: center;">-1.31%</td>
<td style="text-align: center;">5.31%</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</figure>
</div>
<p>When the point alternative hypothesis is defined as ‘over-and-above’ the null hypothesis, we see that the critical bounds shift by the value of the threshold effect (i.e., the non-zero null). So while we retain the original sample-size requirement, the bound at which the null gets rejected in favour of the new design are harder to breach – we will need to observe a larger positive lift. On the other hand, a smaller lift will allow us to reject the null in favour of the incumbent design much faster — owing to a potential harm on the conversion rate.</p>
<p>Hence, this is quite a subjective call as this is a form of bias in favour of the incumbent design (usually denoted as design A).</p>
<p>In case of the inclusive shift however, there is sizeable increase in the sample-size requirement. The same conditions of there being a bias in favour the incumbent design apply here as well. But owing to the increased sample-size requirement, the critical bounds are tighter. It may therefore seem rather irrelevant to incorporate an inclusive shift.</p>
<p>Its true utility comes through in sequential testing which will be (hopefully) discussed in a later post.</p>
</section>
<section id="section" class="level1">
<h1>…</h1>
<p>We briefly looked at the implications of defining a non-zero point null hypothesis, even if the motivating reason to explore these scenarios was simply the question, “why do I never see a non-zero null hypothesis? Is it even feasible?”</p>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>MDE: Minimum Detectable Effect. The smallest change in a metric that an A/B test can detect for a given sample-size. Please refer <a href="https://statsig.com/perspectives/minimal-detectable-effect-impact" title="Statsig: What is MDE?">here</a> for a detailed discussion.↩︎</p></li>
<li id="fn2"><p><a href="https://www.statisticshowto.com/rejection-region/" class="uri">https://www.statisticshowto.com/rejection-region/</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Product</category>
  <category>Experimentation</category>
  <category>AB Testing</category>
  <category>Statistical Power</category>
  <category>Frequentist</category>
  <guid>https://arorarohan.com/posts/20260106-non-zero-null/</guid>
  <pubDate>Mon, 05 Jan 2026 22:00:00 GMT</pubDate>
  <media:content url="https://arorarohan.com/posts/20260106-non-zero-null/index-img.png" medium="image" type="image/png" height="217" width="144"/>
</item>
<item>
  <title>Technically Correct Bayesian A/B Testing without Monte Carlo Simulations</title>
  <dc:creator>Rohan Arora</dc:creator>
  <link>https://arorarohan.com/posts/20251118-bayesian-ab-3/</link>
  <description><![CDATA[ 





<p><em>Note: This is part 3 of a series on Bayesian A/B testing.</em> <a href="../../posts/20251107-bayesian-ab-1/index.html" title="Common-Sense Bayesian A/B Tests are Flawed">Part 1</a> discusses the most common approach and its limitations. <a href="../../posts/20251112-bayesian-aa-2/index.html" title="Bayesian A/A Tests using the common-sense method">Part 2</a> uses simulations of A/A tests to delve deeper.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://arorarohan.com/posts/20251118-bayesian-ab-3/bayes-candy.jpg" id="hero" class="quarto-figure quarto-figure-center anchored figure-img" alt="Random GPT generated hero banner." width="639" height="434"></p>
</figure>
</div>
<section id="introduction" class="level1">
<h1>Introduction</h1>
<p>In the previous posts we explored the the limits and problems in implementation of the Independent Beta Estimator(IBE) approach of Bayesian A/B Testing.</p>
<p>As a recap, there are following modeled and implementation errors in an IBE Bayesian test:</p>
<ol type="1">
<li><p>Poor choice of priors - too strong, too useless, or improperly estimated,</p></li>
<li><p>Inadvertently running a 1-tailed test while believing you are running a 2-tailed test,</p></li>
<li><p>Implicit definition of a non-rejection region for the observed lift by comparing ratios or differences rather than an explicit prior on the MDE/modeled lift itself.</p></li>
<li><p>Implicit definition of a common prior on the baseline conversion rate for the two designs rather than having the model explicitly use a common prior for the lift (e.g.&nbsp;<img src="https://latex.codecogs.com/png.latex?lift%20%5Csim%20N(0,.2)">)</p></li>
</ol>
<p>Today we’ll discuss an alternative approach that uses a prior directly on the expectation around lift. I first came across this approach in <a href="https://docs.geteppo.com/statistics/confidence-intervals/statistical-nitty-gritty/#bayesian-analysis" title="Bayesian Modeling of observed lifit with a normal prior on the lift">Eppo’s reference</a> documentation<sup>1</sup> on their statistical engine. While my preferred model is the Logistic Transformation Model <span class="citation" data-cites="hoffmann2022">(Hoffmann, Hofman, and Wagenmakers 2022)</span>, I will be discussing this <em>Normal-Normal</em> (both prior and posterior are normally distributed) approach first for a few key reasons:</p>
<ol type="1">
<li>Right off the bat the mathematical model reflects what we are trying to do: establish a conversion rate difference between two designs, i.e., lift rather than model two independent conversion rates, followed by forcing a common prior, and then bringing in the modeling of lift through the backdoor.</li>
<li>The model also explicitly honours the idea that the difference in rates cannot vary wildly beyond a certain range under most circumstances.</li>
<li>It’s an elegant model in the sense that prior and the posterior are both normally distributed. Further, just like the IBE model, the posterior can be arrived at analytically. While in both models there really is no need to simulate the posterior distribution of the lift as both can be solved analytically, the normal-normal model on the (possible values of) lift makes it obvious. This is because there is no requirement of taking the ratio or difference of two independent estimators.</li>
</ol>
</section>
<section id="lets-become-normal-normal-the-model" class="level1">
<h1>Let’s become Normal-Normal: The model</h1>
<p>There is nothing complicated to it. The prior is considered to be normally distributed with the parameters set to some initializing values. Please note that in this illustration the prior is on the difference between conversion rates <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp%7D_b%20-%20%5Chat%7Bp%7D_a"> and not relative difference, i.e.&nbsp;lift. You can think of it as akin to a prior expectation about the <a href="https://en.wikipedia.org/wiki/Average_treatment_effect" title="ATE, Wikipedia">average treatment effect</a>.</p>
<p><span id="eq-1"><img src="https://latex.codecogs.com/png.latex?%0A%5Chat%7B%5CDelta%7D_%7Bprior%7D%20%5Csim%20%5Cmathcal%7BN%7D(%5Cmu_%7Bprior%7D,%5C,%5Csigma%5E%7B2%7D_%7Bprior%7D)%0A%5Ctag%7B1%7D"></span></p>
<p>The likelihood is also considered to be normally distributed, i.e., there is a single observation of the lift after ‘N’ data points are collected and the difference in conversion rates is modeled as normally distributed. You can also imagine it as multiple Bayesian updates after collecting some ‘n’ data-points at some regular or irregular intervals. Under usual assumptions of the Classical CLT, this <em>observed</em> difference in conversion rates (i.e.&nbsp;the estimated ATE) of two designs can also be considered to be normally distributed. This leads to a posterior difference in rates, <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5CDelta%7D_%7Bpost%7D"> , with parameters described as:</p>
<p><span id="eq-2"><img src="https://latex.codecogs.com/png.latex?%0A%5Chat%7B%5CDelta%7D_%7Bpost%7D%20%5Csim%20%5Cmathcal%7BN%7D(%5Cmu_%7Bpost%7D,%5Csigma%5E%7B2%7D_%7Bpost%7D)%0A%5Ctag%7B2%7D"></span></p>
<p><span id="eq-3"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_%7Bpost%7D%20=%20%5Cfrac%7B%5Cfrac%7B1%7D%7B%5Csigma%5E%7B2%7D_%7Bprior%7D%7D.%5Cmu_%7Bprior%7D%20+%20%5Cfrac%7B1%7D%7B%5Chat%7B%5Csigma%7D%5E%7B2%7D_%7B%5CDelta%7D%7D.%5Chat%7B%5Cmu%7D_%7B%5CDelta%7D%7D%7B%5Cfrac%7B1%7D%7B%5Csigma%5E%7B2%7D_%7Bprior%7D%7D%20+%20%5Cfrac%7B1%7D%7B%5Chat%7B%5Csigma%7D%5E%7B2%7D_%7B%5CDelta%7D%7D%7D%0A%5Ctag%7B3%7D"></span></p>
<p><span id="eq-4"><img src="https://latex.codecogs.com/png.latex?%0A%5Csigma%5E%7B2%7D_%7Bpost%7D%20=%20%5Cfrac%7B1%7D%7B%5Cfrac%7B1%7D%7B%5Csigma%5E%7B2%7D_%7Bprior%7D%7D%20+%20%5Cfrac%7B1%7D%7B%5Chat%7B%5Csigma%7D%5E%7B2%7D_%7B%5CDelta%7D%7D%7D%0A%5Ctag%7B4%7D"></span></p>
<p>For a formal derivation of how to arrive at the Normal-Normal posterior, please refer this <a href="../..\posts/20251118-bayesian-ab-3/bayes_Normal_Normal.pdf" title="Robert Jacobs, University of Rochester">document</a>.</p>
<p>Note that their is a minor dissonance in this model. For most A/B tests, our observations are after-all event counts – a user takes or doesn’t take an action of interest, as a function of the design they saw (i.e.&nbsp;CRO). Thus, the model is not truly representative of the data generating process when modeling event rates or proportions. This is the primary reason for my preference of the Logistic Transformation Model (LTT) for proportions or CRO.</p>
<p>But the ability to run an analysis quickly with just plug-and-play values is useful and most often the results won’t be particularly different. Therefore, this model works great for a quick sense-check as well as for planning and scenario analysis before running an experiment.</p>
<p>We’ll now look at the process of defining the parameters for the prior.</p>
</section>
<section id="defining-the-prior" class="level1">
<h1>Defining the Prior</h1>
<section id="prior-under-the-null-hypothesis-mathcalh_0delta-0" class="level2">
<h2 class="anchored" data-anchor-id="prior-under-the-null-hypothesis-mathcalh_0delta-0">Prior under the Null Hypothesis <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BH%7D_0:%5CDelta%20=%200"></h2>
<p>Of course, under the null, <img src="https://latex.codecogs.com/png.latex?%5Cmu_%7Bprior%7D%20=%200">. All we need now is an appropriate value for <img src="https://latex.codecogs.com/png.latex?%5Csigma_%7Bprior%7D">. For convenience, we’ll be using standard deviation instead of the variance. <img src="https://latex.codecogs.com/png.latex?%5Csigma_%7Bprior%7D"> sets our <em>a priori</em> expectation for the range over which difference in rates can vary. We can use a wide range like <img src="https://latex.codecogs.com/png.latex?%5Csigma_%7Bprior%7D%20=%20.05"> or a narrow range like <img src="https://latex.codecogs.com/png.latex?%5Csigma_%7Bprior%7D%20=%20.01">.</p>
<p>Typically, however, in A/B testing we do the analysis in terms of the lift and a base or historical rate. Therefore, we can define <img src="https://latex.codecogs.com/png.latex?%5CDelta_%7Bprior%7D/p_%7B0%7D%20=%20%5Cmathcal%7Bl%7D"> where <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bl%7D"> is a choice of lift and <img src="https://latex.codecogs.com/png.latex?p_%7B0%7D"> is the historical conversion rate. Thus, we are defining the range relative to the base rate.</p>
<p>Please note that <a href="https://docs.geteppo.com/statistics/confidence-intervals/statistical-nitty-gritty/#bayesian-analysis" title="Bayesian Modeling of observed lifit with a normal prior on the lift">Eppo’s</a> reference model is based directly on <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bl%7D">.</p>
<p>Let’s use <img src="https://latex.codecogs.com/png.latex?p_%7B0%7D%20=%2010%5C%25"> and model various values of plausible (not observed) <em>range of lift</em><sup>2</sup>, viz.&nbsp;1%, 3%, 5% and 10%. Please note that we are plotting the null for mean lift of 0. The gymnastics above are to visualise the impact of <img src="https://latex.codecogs.com/png.latex?%CF%83_%7Bprior%7D/p_%7B0%7D">.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(glue)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(furrr)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggthemes)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(progressr)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(extrafont) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#You can skip it if you like, it's for text on charts.</span></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gridExtra)</span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(knitr)</span>
<span id="cb1-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rlang)</span>
<span id="cb1-10"></span>
<span id="cb1-11"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">##Modify this as per your computing setup</span></span>
<span id="cb1-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plan</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strategy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'multisession'</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">workers =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span></code></pre></div>
</details>
</div>
<div class="cell fig-cap-location-bottom" data-layout-align="center">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb2" data-cap-location="bottom" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">p0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-2">lift <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">01</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">03</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-3"></span>
<span id="cb2-4">chart_labs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{lift*100}%"</span>)</span>
<span id="cb2-5"></span>
<span id="cb2-6">mu_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb2-7">sig_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> p0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>lift</span>
<span id="cb2-8"></span>
<span id="cb2-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We are plotting lift instead of difference, but we can plot difference by changing lift[] to sig_p[]. It's just scaling.</span></span>
<span id="cb2-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggplot() + "</span>,</span>
<span id="cb2-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue_collapse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"geom_function(fun = dnorm, n =10^4, args=list(mean=mu_p,sd=lift[{i}]), aes(col = chart_labs[{i}]),lwd=.6)"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">i =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(lift)),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" + "</span>)) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> cc</span>
<span id="cb2-12"></span>
<span id="cb2-13"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eval</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parse</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> cc)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span>chart_labs) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n.breaks =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb2-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Modeling the range of prior"</span>,</span>
<span id="cb2-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"\u03BC_prior = 0, p_0 = 10%"</span>,</span>
<span id="cb2-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Note: Plot is under the null hypothesis that the mean lift is zero for the prior."</span>,</span>
<span id="cb2-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Choice of \u03C3_prior/p0"</span>,</span>
<span id="cb2-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>,</span>
<span id="cb2-22">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Possible Lift"</span>,</span>
<span id="cb2-23">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parse =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_clean</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>), </span>
<span id="cb2-25">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.text.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'right'</span>, </span>
<span id="cb2-26">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>),</span>
<span id="cb2-27">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.caption  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb2-28">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb2-29">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>))</span></code></pre></div>
</details>
<div class="cell-output-display">
<div id="fig-01" class="quarto-float quarto-figure quarto-figure-center anchored" data-fig-align="center" data-cap-location="bottom">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-01-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://arorarohan.com/posts/20251118-bayesian-ab-3/index_files/figure-html/fig-01-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-01-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Modeled Priors
</figcaption>
</figure>
</div>
</div>
</div>
<p>No surprises here. A larger value for σ<sub>prior</sub> (possible lift) leads to a larger range over which the prior is spread out about 0. Essentially, a larger value indicates more uncertainty about zero and a smaller value indicates less uncertainty about zero. Since the prior is set to a mean value of zero, a smaller value for σ<sub>prior</sub> indicates both a stronger and a more conservative prior. You can also see that the prior is symmetric about zero. Most of the time this is a good thing.</p>
<p>Generally speaking, as the baseline rate gets larger, the observed lifts during an experiment will be smaller, while also being meaningful. This is to say that a 1% relative improvment on 70% is comparable to a 5% relative improvement on 10%. Ergo, an absolute value like <img src="https://latex.codecogs.com/png.latex?%5Csigma_%7Bprior%7D=0.01"> may work well across most circumstances.</p>
</section>
<section id="strength-of-prior-assessment-through-imputed-sample-size" class="level2">
<h2 class="anchored" data-anchor-id="strength-of-prior-assessment-through-imputed-sample-size">Strength of Prior – Assessment through imputed sample-size</h2>
<p>When usually running A/B tests for conversion rate optimisation, we generally tend to understand that the more data we collect, the less uncertainty we have about our estimate of the lift (or of individual designs’ conversion rates for that matter).</p>
<p>In my opinion, we can extend that analogy to the Normal prior as defined in Equation&nbsp;1 to <em>impute</em> a sample-size. This helps us understand how strong the prior is as a function of the amount of data we hope to collect. Alternatively, we can use this figure to plan the amount of data we will collect for an A/B test. Please note that strictly speaking these are not Bayesian concepts, or even established academic concepts of any sort.</p>
<p>But in my opinion even a Bayesian inference framework should have some underpinnings on the amount of data we should reasonably collect before arriving at a decision. And this method helps us take an educated guess in that direction.</p>
<p>Essentially, all we do is assume that we arrived at the range of our prior by collecting some data about a design and we ran an A/A test for that design. In this case, we can safely say that <img src="https://latex.codecogs.com/png.latex?%5Cmu_%7Bprior%7D%20=%200"> and <img src="https://latex.codecogs.com/png.latex?%5Csigma_%7Bprior%7D%20=%20%5Csqrt%7B%5Cfrac%7Bp_0.q_0%7D%7B%5Cmathcal%7Bn%7D%7D%20+%20%5Cfrac%7Bp_0.q_0%7D%7B%5Cmathcal%7Bn%7D%7D%7D">, where <img src="https://latex.codecogs.com/png.latex?p_0"> becomes the conversion rate for this hypothetical A/A test (<img src="https://latex.codecogs.com/png.latex?q_0%20=%201-p_0">).<sup>3</sup></p>
<p>For a given choice of <img src="https://latex.codecogs.com/png.latex?%5Csigma_%7Bprior%7D">, we can invert this value to arrive at <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bn%7D">. Let’s try this for <img src="https://latex.codecogs.com/png.latex?p_0%20=%2012%5C%25"> .</p>
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">p0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span></span>
<span id="cb3-2">q0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p0</span>
<span id="cb3-3">lift <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">01</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">03</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb3-4"></span>
<span id="cb3-5">chart_labs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{lift*100}%"</span>)</span>
<span id="cb3-6"></span>
<span id="cb3-7">mu_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb3-8">sig_p <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> p0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>lift</span>
<span id="cb3-9"></span>
<span id="cb3-10">dt1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Lift =</span> chart_labs, </span>
<span id="cb3-11">             σ<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">_prior=</span>sig_p, </span>
<span id="cb3-12">             <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Imputed SS</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>sig_p<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.mark =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.interval =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>L))</span>
<span id="cb3-13"></span>
<span id="cb3-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(dt1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">align =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'c'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'r'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'r'</span>))</span></code></pre></div>
</details>
<div id="tbl-01" class="quarto-layout-panel anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-01-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: Imputed Sample size of the Prior (p0 = 12%)
</figcaption>
<div aria-describedby="tbl-01-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: center;">
<table class="do-not-create-environment cell caption-top table">
<thead>
<tr class="header">
<th style="text-align: center;">Lift</th>
<th style="text-align: right;">σ_prior</th>
<th style="text-align: right;">Imputed SS</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">1%</td>
<td style="text-align: right;">0.0012</td>
<td style="text-align: right;">146,667</td>
</tr>
<tr class="even">
<td style="text-align: center;">3%</td>
<td style="text-align: right;">0.0036</td>
<td style="text-align: right;">16,297</td>
</tr>
<tr class="odd">
<td style="text-align: center;">5%</td>
<td style="text-align: right;">0.0060</td>
<td style="text-align: right;">5,867</td>
</tr>
<tr class="even">
<td style="text-align: center;">10%</td>
<td style="text-align: right;">0.0120</td>
<td style="text-align: right;">1,467</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</figure>
</div>
<p>Clearly a narrower prior indicates a larger imputed sample-size. The only question that remains is, “how do we use this?? Well, my suggestion is to collect at least as much data as the imputed sample-size of the prior. And perhaps not use priors that are too narrow if the amount of data that can be reasonably collected does not match-up.</p>
<p>I will readily admit that the choice of prior is not a straightforward thing. To be fair, it’s equally convoluted in the IBE methodology – it’s just hidden way from the user through uninformative priors in some mainstream stats engines. I will cover the topic of selecting priors in a separate post.</p>
<p>For programs that have a long history of experimentation, it should be possible to rely on historical results around observed lifts for similar experiments or for experiments where the conversion rate was similar to what is expected in the upcoming experiment.</p>
</section>
</section>
<section id="running-a-truly-bayesian-hypothesis-test" class="level1">
<h1>Running a truly Bayesian Hypothesis Test</h1>
<section id="where-is-the-point-alternative-hypothesis" class="level2">
<h2 class="anchored" data-anchor-id="where-is-the-point-alternative-hypothesis">Where is the (point) alternative hypothesis?</h2>
<p>The astute reader would have noticed that in our previous discussions around Bayesian A/B and A/A Testing (<a href="../../posts/20251107-bayesian-ab-1/index.html" title="Common-Sense Bayesian A/B Tests are Flawed">Part 1</a> and <a href="../../posts/20251112-bayesian-aa-2/index.html" title="Bayesian A/A Tests using the common-sense method">Part 2</a> respectively), we never really defined a point alternative hypothesis, i.e., an MDE, like we do in frequentist A/B testing.</p>
<p>In the frequentist test of proportions, defining a power (and therefore a sample-size that controls both Type 1 and Type 2 errors), <em>requires</em> defining the alternative at a point, i.e.&nbsp;it demands an effect-size or MDE. (<img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BH%7D_a:%20%5CDelta%20=%20%5Cbig%5Clvert%20p_0.MDE%20%5Cbig%5Crvert">)<sup>4</sup>.</p>
<p>So far we have not defined an alternative hypothesis, let alone an alternative around an MDE. This is where Bayes Factor comes in. The good news is that for our specific use-case, we don’t require the definition of an MDE, as we are not really defining a formal sample-size requirement<sup>5</sup>.</p>
<p>We can therefore continue with defining our alternative hypothesis in the usual way as a two-sided non-zero comparison. This brings us to the Bayes Factor.</p>
</section>
<section id="bayes-factor" class="level2">
<h2 class="anchored" data-anchor-id="bayes-factor">Bayes Factor</h2>
<p>I first came across this concept in Will Kurt’s <a href="https://www.countbayesie.com/blog/2015/2/27/building-a-bayesian-voight-kampff-test" title="countbayesie.com, Will Kurt">blog</a><sup>6</sup>.</p>
<p>Bayes Factor is essentially a ratio of relative evidence favouring one modeling assumption over the other, or one hypothesis over the other.</p>
<p>Formally, let <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_i"> denote possible models for explaining data <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7B%5Cmathcal%7By%7D%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7Bi%7D%20%5Cin%20%5B1,2%5D"><sup>7</sup>. Then,</p>
<p><span id="eq-5"><img src="https://latex.codecogs.com/png.latex?%0Ap(%5Cmathcal%7BM%7D_i%7C%5Cmathcal%7By%7D)%20=%20%5Cfrac%7Bp(%5Cmathcal%7By%7D%7C%5Cmathcal%7BM%7D_i).p(%5Cmathcal%7BM%7D_i)%7D%7B%5Csum_%7Bi%7D%7Bp(%5Cmathcal%7By%7D%7C%5Cmathcal%7BM%7D_i).p(%5Cmathcal%7BM%7D_i)%7D%7D%0A%5Ctag%7B5%7D"></span></p>
<p><span id="eq-6"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7BBF%7D_%7B12%7D%20=%20%5Cfrac%7Bp(%5Cmathcal%7By%7D%7C%5Cmathcal%7BM%7D_1)%7D%7Bp(%5Cmathcal%7By%7D%7C%5Cmathcal%7BM%7D_2)%7D%20=%20%5Cfrac%7Bp(%5Cmathcal%7BM%7D_1%7C%5Cmathcal%7By%7D)%7D%7Bp(%5Cmathcal%7BM%7D_2%7C%5Cmathcal%7By%7D)%7D%20%5Ctimes%20%5Cfrac%7Bp(%5Cmathcal%7BM%7D_2)%7D%7Bp(%5Cmathcal%7BM%7D_1)%7D%0A%5Ctag%7B6%7D"></span></p>
<p>where the first term is the posterior odds and the second term is the inverse of prior odds. Bayes Factor is therefore the ratio of likelihood of the observed data under two different modeling assumptions. In our case this simplifies to the null and the alternative hypothesis respectively.</p>
<p>Please note that this ratio is invertible, i.e.&nbsp;<img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BBF%7D_%7B12%7D%20=%201/%5Cmathcal%7BBF%7D_%7B21%7D">. Also note that in most circumstances both (or all) models are <em>a priori</em> considered equally likely, i.e., the prior odds are 1. The Bayes Factor then reduces to the ratio of the posteriors under the two models or hypotheses.</p>
<p>For a more detailed explanation of this section and the next one, I refer you to this excellent <a href="https://www.ejwagenmakers.com/2010/WagenmakersEtAlCogPsy2010.pdf" title="Bayesian hypothesis testing for psychologists: A tutorial on the Savage–Dickey method">paper</a>.</p>
<div id="tbl-bf" class="striped quarto-float quarto-figure quarto-figure-center anchored" data-tbl-colwidths="[20,40,40]">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-bf-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;2: The Bayes factor scale as proposed by <span class="citation" data-cites="jeffreys1998">Jeffreys (1998)</span>.
</figcaption>
<div aria-describedby="tbl-bf-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table class="table-striped caption-top table">
<colgroup>
<col style="width: 20%">
<col style="width: 40%">
<col style="width: 40%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;"><img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BBF%7D_%7B12%7D"></th>
<th style="text-align: left;"><strong>Interpretation</strong></th>
<th></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">&gt;100</td>
<td style="text-align: left;">Extreme evidence for <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_1"></td>
<td></td>
</tr>
<tr class="even">
<td style="text-align: right;">30−100</td>
<td style="text-align: left;">Very strong evidence for <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_1"></td>
<td></td>
</tr>
<tr class="odd">
<td style="text-align: right;">10−30</td>
<td style="text-align: left;">Strong evidence for <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_1"></td>
<td></td>
</tr>
<tr class="even">
<td style="text-align: right;">3−10</td>
<td style="text-align: left;">Moderate evidence for <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_1"></td>
<td></td>
</tr>
<tr class="odd">
<td style="text-align: right;">1−3</td>
<td style="text-align: left;">Anecdotal evidence for <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_1"></td>
<td></td>
</tr>
<tr class="even">
<td style="text-align: right;">1</td>
<td style="text-align: left;">No evidence</td>
<td></td>
</tr>
<tr class="odd">
<td style="text-align: right;">11−13</td>
<td style="text-align: left;">Anecdotal evidence for <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_2"></td>
<td></td>
</tr>
<tr class="even">
<td style="text-align: right;">13−110</td>
<td style="text-align: left;">Moderate evidence for <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_2"></td>
<td></td>
</tr>
<tr class="odd">
<td style="text-align: right;">110−130</td>
<td style="text-align: left;">Strong evidence for <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_2"></td>
<td></td>
</tr>
<tr class="even">
<td style="text-align: right;">130−1100</td>
<td style="text-align: left;">Very strong evidence for <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_2"></td>
<td></td>
</tr>
<tr class="odd">
<td style="text-align: right;">&lt;1100</td>
<td style="text-align: left;">Extreme evidence for <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_2"></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
<p>With most of the math out of the way, we can finally tackle the last remaining piece: the <em>Savage-Dickey Density Ratio.</em></p>
</section>
<section id="comparing-densities-at-a-point-null-using-the-savage-dickey-density-ratio" class="level2">
<h2 class="anchored" data-anchor-id="comparing-densities-at-a-point-null-using-the-savage-dickey-density-ratio">Comparing Densities at a point null using the Savage-Dickey Density Ratio</h2>
<p>In our usual hypothesis testing framework, we express our two models as:</p>
<p><span id="eq-7"><img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7BH%7D_0:%20%5Cmu%20=%200%20%5Cquad%20;%20%5Cquad%20%5Cmathcal%7BH%7D_1:%20%5Cmu%20%5Cne%200%0A%5Ctag%7B7%7D"></span></p>
<p>where <img src="https://latex.codecogs.com/png.latex?%5Cmu"> represents the difference in conversion rates in terms of the notation we have used so far.</p>
<p>Ergo, <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_1%20=%20%5Cmathcal%7BH%7D_0"> and <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BM%7D_2%20=%20%5Cmathcal%7BH%7D_1">.</p>
<p>The Savage-Dickey Density ratio simplifies the computation of the Bayes Factor <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BBF%7D_%7B01%7D"> to the ratio of density of the prior at the point null to that of the density of the posterior at that null.</p>
<blockquote class="blockquote">
<p><strong>Theorem (<span class="citation" data-cites="faulkenberry2019">Faulkenberry (2019)</span>):</strong></p>
<p>Consider two competing models on data <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7By%7D"> containing parameters δ and φ, namely ℋ<sub>0</sub>: δ = δ<sub>0</sub>, φ and ℋ<sub>1</sub> : δ, φ. In this context, we say that δ is a parameter of interest, φ is a nuisance parameter (i.e., common to all models), and ℋ<sub>0</sub> is a sharp point hypothesis nested within ℋ<sub>1</sub>. Suppose further that the prior for the nuisance parameter φ in ℋ<sub>0</sub> is equal to the prior for φ in ℋ<sub>1</sub> after conditioning on the restriction – that is, p(φ | ℋ<sub>0</sub>) = p(φ | δ = δ<sub>0</sub>, ℋ<sub>1</sub>). Then:</p>
<p><span id="eq-8"><img src="https://latex.codecogs.com/png.latex?%20%5Cmathcal%7BBF%7D_%7B01%7D%20=%20%5Cfrac%7Bp(%5Cdelta%20=%20%5Cdelta_0%7C%20%5Cmathbb%7By%7D,%5Cmathcal%7BH%7D_1)%7D%7Bp(%5Cdelta%20=%20%5Cdelta_0%7C%20%5Cmathcal%7BH%7D_1)%7D%20%20%5Ctag%7B8%7D"></span></p>
</blockquote>
<p>For a proof you can look at the citation above or check this link <a href="https://statproofbook.github.io/P/bf-sddr.html" title="The Book of Statistical Proofs">here</a>.</p>
<p>In the context of our models and assumptions, <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20=%20%5Cmu_%7Bpost%7D%20=%200">, and <img src="https://latex.codecogs.com/png.latex?%5Cvarphi%20=%20%5Csigma_%7Bpost%7D"> is the nuisance parameter. It’s trivial to show that without data <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7By%7D">, <img src="https://latex.codecogs.com/png.latex?%5Cmu"> and <img src="https://latex.codecogs.com/png.latex?%5Csigma"> reduce to their values from the prior.</p>
<p>Thus, in order to calculate <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BBF%7D_%7B01%7D">, all we need is the densities at <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20=%200"> for the posterior and the prior. Let’s try an example.</p>
</section>
<section id="run-the-ab-test-already" class="level2">
<h2 class="anchored" data-anchor-id="run-the-ab-test-already">Run the A/B test already!</h2>
<p>We’ll run an A/B test for 12K users for both designs, and let’s say the conversion rates were 10.5% and 12% for A and B respectively. Our prior is set to parameters <img src="https://latex.codecogs.com/png.latex?%5Cmu_%7Bprior%7D%20=%200;%5C;%20%5Csigma_%7Bprior%7D%20=%20.005">. We are assuming that <img src="https://latex.codecogs.com/png.latex?%5Csigma"> was derived from a base rate of 10% and a usual lift range of 5%.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">p0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb4-2">lift <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span></span>
<span id="cb4-3">mu_pr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb4-4">var_pr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (p0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>lift)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb4-5">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12000</span></span>
<span id="cb4-6">pa <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">105</span></span>
<span id="cb4-7">pb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span></span>
<span id="cb4-8"></span>
<span id="cb4-9">qa <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> pa</span>
<span id="cb4-10">qb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> pb</span>
<span id="cb4-11"></span>
<span id="cb4-12">mu_obs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> pb <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> pa</span>
<span id="cb4-13">var_obs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> pa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>pb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n </span>
<span id="cb4-14"></span>
<span id="cb4-15">mu_po <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (mu_pr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_pr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> mu_obs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_obs)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_pr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_obs)</span>
<span id="cb4-16">var_po <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_pr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_obs)</span>
<span id="cb4-17"></span>
<span id="cb4-18">dens_pr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,mu_pr,p0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>lift)</span>
<span id="cb4-19">dens_po <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,mu_po,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(var_po))</span>
<span id="cb4-20"></span>
<span id="cb4-21">bf_01 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> dens_po<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>dens_pr</span>
<span id="cb4-22"></span>
<span id="cb4-23">prior_ss <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p0)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_pr), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.mark =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.interval =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>L)</span>
<span id="cb4-24">post_ss <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</span>((pa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>pb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qb)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_po), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.mark =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.interval =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>L)</span></code></pre></div>
</details>
</div>
<div id="tbl-abtest" class="striped quarto-float quarto-figure quarto-figure-center anchored" data-tbl-colwidths="[30,25,45]">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-abtest-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;3: Outputs of the example A/B Test (S.S. are per design).
</figcaption>
<div aria-describedby="tbl-abtest-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table class="table-striped caption-top table">
<colgroup>
<col style="width: 30%">
<col style="width: 25%">
<col style="width: 45%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: center;"><strong>Attribute</strong></th>
<th style="text-align: right;"><strong>Value</strong></th>
<th style="text-align: center;"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">Observed lift</td>
<td style="text-align: right;">14.29%</td>
<td style="text-align: center;"></td>
</tr>
<tr class="even">
<td style="text-align: center;">Posterior Lift</td>
<td style="text-align: right;">8.58%</td>
<td style="text-align: center;"></td>
</tr>
<tr class="odd">
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BBF%7D_%7B01%7D"></td>
<td style="text-align: right;">0.0272</td>
<td style="text-align: center;"></td>
</tr>
<tr class="even">
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BBF%7D_%7B10%7D"></td>
<td style="text-align: right;">36.72</td>
<td style="text-align: center;"></td>
</tr>
<tr class="odd">
<td style="text-align: center;">Imputed S.S. (Prior)</td>
<td style="text-align: right;">7,200</td>
<td style="text-align: center;"></td>
</tr>
<tr class="even">
<td style="text-align: center;">Imputed S.S. (Post.)</td>
<td style="text-align: right;">19,983</td>
<td style="text-align: center;"></td>
</tr>
<tr class="odd">
<td style="text-align: center;">p(<img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BH%7D_1">)<sup>8</sup></td>
<td style="text-align: right;">97.35%</td>
<td style="text-align: center;"></td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
<p>Let’s look at this visually.</p>
<div class="cell fig-cap-location-bottom" data-layout-align="center">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb5" data-cap-location="bottom" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">chart_labs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Prior"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Posterior"</span>)</span>
<span id="cb5-2"></span>
<span id="cb5-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dnorm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span>mu_pr,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd=</span>p0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>lift), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dnorm, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span>mu_po,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(var_po)), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>dens_pr)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">003</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> dens_pr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"density = {round(dens_pr,2)}"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>dens_po)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">003</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> dens_po<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"density = {round(dens_po,2)}"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> mu_po,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks=</span>chart_labs) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">limits =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">01</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">02</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n.breaks =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb5-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Results of the A/B Test"</span>,</span>
<span id="cb5-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"\u03BC_prior = 0, \u03C3_prior = {y}"</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> p0<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>lift),</span>
<span id="cb5-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Note: Dots indicate the point where BF01 was calculated."</span>,</span>
<span id="cb5-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb5-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>,</span>
<span id="cb5-20">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"\u0394"</span>,</span>
<span id="cb5-21">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parse =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_clean</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>), </span>
<span id="cb5-23">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.text.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'right'</span>, </span>
<span id="cb5-24">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb5-25">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.caption  =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb5-26">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.title    =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>),</span>
<span id="cb5-27">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">plot.subtitle =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>))</span></code></pre></div>
</details>
<div class="cell-output-display">
<div id="fig-02" class="quarto-float quarto-figure quarto-figure-center anchored" data-fig-align="center" data-cap-location="bottom">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-02-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://arorarohan.com/posts/20251118-bayesian-ab-3/index_files/figure-html/fig-02-1.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-02-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: A/B Test Results
</figcaption>
</figure>
</div>
</div>
</div>
<p>In this particular case, the prior adequately regularized the collected data, which we can see from the reduced lift (8.58% as opposed to 14.29%).</p>
<p>There is about 97.35% probability in favour of <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BH%7D_1">.</p>
<p>A caveat here: if we were to run a frequentist 2-sample test of proportions in this scenario, the power for the comparison (<img src="https://latex.codecogs.com/png.latex?%5Calpha=10%5C%25">, <img src="https://latex.codecogs.com/png.latex?p_0=10.5%5C%25"> and <img src="https://latex.codecogs.com/png.latex?m.d.e.=10%5C%25">) would be around 83%. For the amount of data we have collected, we could have just as easily run a frequentist A/B test, for all practical purposes. (An observed lift of 8.5% would be detectable in this scenario with appropriate error controls).</p>
<p>This is to be expected as a prior defined about 0 is naturally going to reduce an observed lift, depending on its relative strength to the data collected.</p>
<section id="using-the-ratio-instead-of-difference" class="level3">
<h3 class="anchored" data-anchor-id="using-the-ratio-instead-of-difference">Using the Ratio instead of difference</h3>
<p>For comparison’s sake, let’s run the same scenario as above but with relative difference defined as <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Chat%7Bp_b%7D%7D%7B%5Chat%7Bp_a%7D%7D-1">, as opposed to the absolute difference. The distribution of the above statistic is also considered to be Normal albeit under some approximations to arrive at the <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Cmu%7D_%5CDelta"> and <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Csigma%7D_%5CDelta"> via Taylor’s expansion <span class="citation" data-cites="duris2018">(Duris et al. 2018)</span> or the <a href="https://en.wikipedia.org/wiki/Delta_method" title="Delta Method, Wikipedia">delta method</a>.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">p0 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb6-2">lift <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span></span>
<span id="cb6-3">mu_pr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb6-4">var_pr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> lift<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb6-5">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12000</span></span>
<span id="cb6-6">pa <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">105</span></span>
<span id="cb6-7">pb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span></span>
<span id="cb6-8"></span>
<span id="cb6-9">qa <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> pa</span>
<span id="cb6-10">qb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> pb</span>
<span id="cb6-11"></span>
<span id="cb6-12">var_a <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> pa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n</span>
<span id="cb6-13">var_b <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> pb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n</span>
<span id="cb6-14"></span>
<span id="cb6-15">mu_obs  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> pb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pa <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb6-16">var_obs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> ((pb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pa)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(pa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>pb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>pb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) </span>
<span id="cb6-17"></span>
<span id="cb6-18">mu_po <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (mu_pr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_pr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> mu_obs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_obs)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_pr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_obs)</span>
<span id="cb6-19">var_po <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_pr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_obs)</span>
<span id="cb6-20"></span>
<span id="cb6-21">dens_pr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,mu_pr,lift)</span>
<span id="cb6-22">dens_po <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dnorm</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,mu_po,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(var_po))</span>
<span id="cb6-23"></span>
<span id="cb6-24">bf_01 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> dens_po<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>dens_pr</span>
<span id="cb6-25"></span>
<span id="cb6-26">prior_ss <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p0)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(var_pr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p0)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.mark =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.interval =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>L)</span>
<span id="cb6-27">post_ss <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</span>(((pb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>pa)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(pa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(pa<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>pb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(pb<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>var_po), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.mark =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">big.interval =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>L)</span></code></pre></div>
</details>
</div>
<div id="tbl-abtest" class="striped quarto-float quarto-figure quarto-figure-center anchored" data-tbl-colwidths="[30,25,45]">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-abtest-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;4: Outputs from the ratio based A/B Test (S.S. are per design).
</figcaption>
<div aria-describedby="tbl-abtest-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table class="table-striped caption-top table">
<colgroup>
<col style="width: 30%">
<col style="width: 25%">
<col style="width: 45%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: center;"><strong>Attribute</strong></th>
<th style="text-align: right;"><strong>Value</strong></th>
<th style="text-align: center;"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">Observed lift</td>
<td style="text-align: right;">14.29%</td>
<td style="text-align: center;"></td>
</tr>
<tr class="even">
<td style="text-align: center;">Posterior Lift</td>
<td style="text-align: right;">8.45%</td>
<td style="text-align: center;"></td>
</tr>
<tr class="odd">
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BBF%7D_%7B01%7D"></td>
<td style="text-align: right;">0.0474</td>
<td style="text-align: center;"></td>
</tr>
<tr class="even">
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BBF%7D_%7B10%7D"></td>
<td style="text-align: right;">21.11</td>
<td style="text-align: center;"></td>
</tr>
<tr class="odd">
<td style="text-align: center;">Imputed S.S. (Prior)</td>
<td style="text-align: right;">7,200</td>
<td style="text-align: center;"></td>
</tr>
<tr class="even">
<td style="text-align: center;">Imputed S.S. (Post.)</td>
<td style="text-align: right;">20,285</td>
<td style="text-align: center;"></td>
</tr>
<tr class="odd">
<td style="text-align: center;">p(<img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BH%7D_1">)</td>
<td style="text-align: right;">95.48%</td>
<td style="text-align: center;"></td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
</section>
</section>
</section>
<section id="advantages-of-the-bayesian-framework" class="level1">
<h1>Advantages of the Bayesian Framework</h1>
<p>As is obvious, just about any framework will work if you can collect enough data.</p>
<p>The value of the Bayesian framework is therefore not in economising the sample size, although that can be a use-case in certain scenarios. Rather it’s value is in:</p>
<ol type="1">
<li><p>The regularizing of the observed data through a well-defined prior.</p></li>
<li><p>Allowing you to define a prior using historical experiments.</p></li>
<li><p>Direct interpretability: instead of butting our heads about a mythical p-value, we get a straightforward interpretation through a Bayes Factor (odds in favour of a hypothesis) and the probabilistic evidence in favour of a hypothesis of interest.</p>
<ol type="i">
<li>The posterior distribution is exactly what you think it is: a range of possible lifts with some values being more probable than others.</li>
<li>Combined with an appropriate revenue function, this allows you to calculate the expected revenue over a full range of possibilities.</li>
</ol></li>
<li><p>As we go along and explore more complex models, we’ll see that we can also adjust the prior odds of the model. This may be useful if let’s say we are running a series of experiments and we already have some evidence in favour of the alternative hypothesis from previous experiments.</p></li>
<li><p>No peeking adjustment required (usually): Since today’s posterior is tomorrow’s prior, adjustments are not required for checking results at the interim intervals. I am not completely sure about this but there seems to be some consensus around this.</p></li>
</ol>
</section>
<section id="caveats-of-the-normal-normal-model" class="level1">
<h1>Caveats of the Normal-Normal Model</h1>
<p>The core advantage of this approach is of course being able to use it without needing to run simulations of any sort. There are however certain caveats that should be highlighted:</p>
<ol type="1">
<li>Not the most accurate model: At the end of the day, the point of Bayesian Inference is to define your model as closely as possible to the data generating process<sup>9</sup>. The utility of the IBE model comes precisely from resembling the actual process of observing a series of conversion events.</li>
<li>The model places some non-zero weight on differences that cannot occur. The difference of two rates cannot exceed the limits of -1 and 1. This is one of the reasons why this model is not as accurate as say a well defined Hierarchical Bayesian Model like the Logistic Transformation Model of A/B Testing (<span class="citation" data-cites="wagenmakers2010">Wagenmakers et al. (2010)</span>). Of course we can rely on the ratio metric to address this.</li>
<li>The prior and the posterior will always be symmetric about the mean. While this is a desirable property most of the time, sometimes it might be better to have a skewed or a heavier tailed distribution. Even if we were to change just the prior to a more appropriate distribution, the parametric simplicity due to it being the conjugate of the posterior would very often disappear. Then we are back to simulations.</li>
</ol>
<p>Despite all the caveats, I have used this approach extensively as a first pass due to its simplicity. The eventual result may come from a more complex model, but this should definitely be the multi-utility tool in your A/B testing kit.</p>
<p>And hey, most of the time the complexity may not be required, so why not save on the electricity needed to run those MCMC simulations?</p>
</section>
<section id="section" class="level1">
<h1>…</h1>
<p>We looked at the Normal-Normal model of running a Bayesian A/B test. We combined it with the Savage-Dickey Density Ratio to run a bi-directional superiority (inferiority) hypothesis test for a point null defined on a parameter of interest.</p>
<p>Please note that there are version of this approach that can handle equivalence/non-inferiority testing as well as directional superiority (inferiority) hypothesis testing.</p>
<p>We explored ways in which the above approach is an upgrade over the IBE model of Bayesian A/B testing.</p>



</section>


<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-duris2018" class="csl-entry">
Duris, Frantisek, Juraj Gazdarica, Iveta Gazdaricova, Lucia Strieskova, Jaroslav Budis, Jan Turna, and Tomas Szemes. 2018. <span>“Mean and Variance of Ratios of Proportions from Categories of a Multinomial Distribution.”</span> <em>Journal of Statistical Distributions and Applications</em> 5 (1). <a href="https://doi.org/10.1186/s40488-018-0083-x">https://doi.org/10.1186/s40488-018-0083-x</a>.
</div>
<div id="ref-faulkenberry2019" class="csl-entry">
Faulkenberry, Thomas J. 2019. <span>“A Tutorial on Generalizing the Default Bayesian t-Test via Posterior Sampling and Encompassing Priors.”</span> <em>Communications for Statistical Applications and Methods</em> 26 (2): 217–38. <a href="https://doi.org/10.29220/csam.2019.26.2.217">https://doi.org/10.29220/csam.2019.26.2.217</a>.
</div>
<div id="ref-hoffmann2022" class="csl-entry">
Hoffmann, Tabea, Abe Hofman, and Eric-Jan Wagenmakers. 2022. <span>“Bayesian Tests of Two Proportions: A Tutorial with r and JASP.”</span> <em>Methodology</em> 18 (4): 239–77. <a href="https://doi.org/10.5964/meth.9263">https://doi.org/10.5964/meth.9263</a>.
</div>
<div id="ref-jeffreys1998" class="csl-entry">
Jeffreys, Harold. 1998. <em>Theory of Probability</em>. Oxford University PressOxford. <a href="https://doi.org/10.1093/oso/9780198503682.001.0001">https://doi.org/10.1093/oso/9780198503682.001.0001</a>.
</div>
<div id="ref-wagenmakers2010" class="csl-entry">
Wagenmakers, Eric-Jan, Tom Lodewyckx, Himanshu Kuriyal, and Raoul Grasman. 2010. <span>“Bayesian Hypothesis Testing for Psychologists: A Tutorial on the Savage<span></span>Dickey Method.”</span> <em>Cognitive Psychology</em> 60 (3): 158–89. <a href="https://doi.org/10.1016/j.cogpsych.2009.12.001">https://doi.org/10.1016/j.cogpsych.2009.12.001</a>.
</div>
</div></section><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Eppo’s model is based on lift or relative difference. I am using the difference in rates or absolute difference.↩︎</p></li>
<li id="fn2"><p>I am intentionally avoiding calling the plausible lift ‘MDE’ as that would be misleading.↩︎</p></li>
<li id="fn3"><p>Or we can define an MDE and use <img src="https://latex.codecogs.com/png.latex?%5Csigma_%7Bprior%7D%20=%20%5Csqrt%7B%5Cfrac%7Bp_1.q_1%7D%7B%5Cmathcal%7Bn%7D%7D%20+%20%5Cfrac%7Bp_2.q_2%7D%7B%5Cmathcal%7Bn%7D%7D%7D"> where <img src="https://latex.codecogs.com/png.latex?p_2%20=%20p1.(1+MDE)">.↩︎</p></li>
<li id="fn4"><p>I understand that there will be disagreements here, but I request the seasoned academician to let this one slide for now.↩︎</p></li>
<li id="fn5"><p>I believe it’s possible to define the power of a Bayesian Hypothesis Test using a Bayes Factor, but that’s something I’ll cover in a separate post.↩︎</p></li>
<li id="fn6"><p>I owe my initiation into Bayesian statistics to this blog. You could say that my own blog is inspired from Will Kurt’s work.↩︎</p></li>
<li id="fn7"><p>We can have more than two models, but right now we are constraining ourselves to two, the null and the alternative hypothesis.↩︎</p></li>
<li id="fn8"><p>Since the Bayes Factor in our case is essentially odds in favour or against any one of the two hypothesis, we can convert the odds to a probability.↩︎</p></li>
<li id="fn9"><p>This gets into the cogency v/s similitude debate, whereby we decide what’s more important - a complex process that is closer to the DGP v/s a simpler process that gives a very close approximation. Thank you <a href="https://www.linkedin.com/in/tyler-buffington-82a1a212a/">Tyler Buffington</a> for pointing this out.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Product</category>
  <category>Experimentation</category>
  <category>AB Testing</category>
  <category>Bayes Factor</category>
  <category>Bayesian</category>
  <guid>https://arorarohan.com/posts/20251118-bayesian-ab-3/</guid>
  <pubDate>Wed, 19 Nov 2025 22:00:00 GMT</pubDate>
  <media:content url="https://arorarohan.com/posts/20251118-bayesian-ab-3/index-img.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>Running a classical Bayesian A/A Test, and paying for our priors.</title>
  <dc:creator>Rohan Arora</dc:creator>
  <link>https://arorarohan.com/posts/20251112-bayesian-aa-2/</link>
  <description><![CDATA[ 





<p><em>Note: This is part 2 of a series on Bayesian A/B testing. Check part 1 <a href="../../posts/20251107-bayesian-ab-1/index.html">here</a>.</em></p>
<section id="introduction" class="level1">
<h1>Introduction</h1>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://arorarohan.com/posts/20251112-bayesian-aa-2/bayes_remorse.jpg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="292"></p>
</figure>
</div>
<p>There’s nothing better than an A/A test to bring all your weird modeling assumptions to the table, because it takes one key challenge away - that of detecting a true difference between designs.</p>
<p>We explore the the limits and problems in implementation of the Incremental Beta Estimator(IBE) approach of Bayesian A/B Testing.</p>
<p>For a discussion on what the model is, check <a href="../../posts/20251107-bayesian-ab-1/index.html">part 1</a> of this series.</p>
<p><em>Note: The first section is a reproduction from <a href="../../posts/20251110-is-pa-pb/index.html#sec-bayes-aa" title="Bayesian A/A">here</a>.</em></p>
<p>As a recap, there are following modeled and implementation errors in an IBE Bayesian test:</p>
<ol type="1">
<li><p>Poor choice of priors - too strong, too useless, or improperly estimated,</p></li>
<li><p>Inadvertently running a 1-tailed test while believing you are running a 2-tailed test,</p></li>
<li><p>Implicit definition of a non-rejection region for the observed lift by comparing ratios or differences rather than an explicit prior on the MDE/modeled lift itself.</p></li>
<li><p>Implicit definition of a common prior on the baseline conversion rate for the two designs rather than having the model explicitly use a common prior for the lift (e.g.&nbsp;<img src="https://latex.codecogs.com/png.latex?lift%20%5Csim%20N(0,.2)">)</p></li>
</ol>
</section>
<section id="running-a-bayesian-aa-test-classical-approach" class="level1">
<h1>Running a Bayesian A/A Test – Classical Approach</h1>
<p>We use the independent conversion rate beta-binomial model where it is assumed that the underlying data generating process is a binomial model. The priors are separate and assumed to be beta distributed.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(glue)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(furrr)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggthemes)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(progressr)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(extrafont) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#You can skip it if you like, it's for text on charts.</span></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(gridExtra)</span>
<span id="cb1-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(knitr)</span>
<span id="cb1-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(rlang)</span>
<span id="cb1-10"></span>
<span id="cb1-11"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">##Modify this as per your computing setup</span></span>
<span id="cb1-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plan</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strategy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'multisession'</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">workers =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span></code></pre></div>
</details>
</div>
<p>It’s simple, really. We take “n” draws from both posterior simulations and then create a ratio as A2/A1 (and A1/A2) in the usual way. To keep the comparison same as a 2-tailed 2-sample test of proportions, we use the following decision rule: <img src="https://latex.codecogs.com/png.latex?p(ECDF(ratio%20%3C=%201))%20%3C%20p.value%5C%20threshold/2">.</p>
<p>Yes, this is no rocket science. But my blog isn’t aimed at seasoned stats professionals/academicians but rather at a more general audience, to who all of this may not be immediately obvious.</p>
<p>The key is defining a reasonable prior. There is no real point in using a Bayesian methodology if stronger assumptions aren’t made, so we won’t be using an uninformative prior like Beta(1,1). And since we are planning an A/A test, we will be keeping the parameters equal, i.e.&nbsp;𝛂<sub>A1</sub> = 𝛂<sub>A2</sub> = 𝛂 and 𝛃<sub>A1</sub> = 𝛃<sub>A2</sub> = 𝛃.</p>
<p>We consider the historical rate of our design as 10%, so really, the question is whether the prior should be beta(10,90) or beta(1000,9000).</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-2">q1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p1</span>
<span id="cb2-3">prior_alpha <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p1</span>
<span id="cb2-4">prior_beta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p1)</span>
<span id="cb2-5"></span>
<span id="cb2-6">n_sim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span></span>
<span id="cb2-7">set.seed <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">145</span></span>
<span id="cb2-8">prior_ratios <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.x =</span> prior_alpha,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.y =</span> prior_beta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nn =</span>n_sim),</span>
<span id="cb2-9">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> \(.x,.y,nn) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbeta</span>(nn,.x,.y)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbeta</span>(nn,.x,.y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb2-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_cols</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename_with</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.fn =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>LETTERS[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Priors'</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Ratio'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Priors =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Priors,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered =</span> T))</span>
<span id="cb2-11"></span>
<span id="cb2-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(prior_ratios,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Ratio,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Priors, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> Priors)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb2-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Various Choices for Priors"</span>,</span>
<span id="cb2-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Base Rate = 10% AA Test, \u03B1(A1) = \u03B1(A2) = \u03B1 and \u03B2(A1) = \u03B2(A2) = \u03B2"</span>,</span>
<span id="cb2-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Note: Plot is under the null hypothesis that a priori expected lift is zero."</span>,</span>
<span id="cb2-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Choice of Prior"</span>,</span>
<span id="cb2-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ratio of Conversion Rates from Priors"</span>,</span>
<span id="cb2-19">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parse =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"\u03B1="</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"100"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1k"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>),</span>
<span id="cb2-21">                                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" \u03B2="</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"90"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"180"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"900"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9k"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minor_breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.75</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb2-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_clean</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb2-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://arorarohan.com/posts/20251112-bayesian-aa-2/index_files/figure-html/Chart-001-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>The choice of beta(10,90) seems reasonable. It doesn’t concentrate too heavily around a ratio of 1 and is more or less symmetric about 1. You can already see that the distributions can be right-skewed. Of course you could resolve that by using a difference instead of a ratio. But a ratio seems to be used more often by practitioners and proponents. The outcome of a beta(1,1) is also plotted for comparison. Clearly the range is too vast and it has no meaningful use.</p>
<p>Now let’s perform 10^4 A/A tests (lower count as we also need to simulate the posterior every time). But now comes the key question. In the frequentist paradigm, we just sampled from a normal distribution and each draw of <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp%7D"> was an A/A test.</p>
<p>In the Bayesian paradigm, we are dealing with the probability of an event. So, do we draw from the normal distribution or something else entirely? What we know is that the average rate has to be 10% and that we will collect some ‘n’ data-points. We can continue to keep the ‘n’ constant across all A/A tests. In fact, we had already assumed that our underlying data is binomially distributed - this is what allows our posterior to be beta distributed (read: conjugate priors).</p>
<p>We will use a nominal Type 1 Error Rae of 20%, a power of 90%, and an MDE of 5% to estimate the sample collected per A/A test per design. I understand that these are concepts from the frequentist paradigm, so we can say that we happen to collect the same amount of data and check if the rate of rejecting the null is similar – around 20%.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>; alpha <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>; power <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>; mde <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span></span>
<span id="cb3-2">prior_a<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>; prior_b<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span></span>
<span id="cb3-3">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power.prop.test</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p1 =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p2 =</span> p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>mde),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">power =</span> power,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sig.level =</span> alpha)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#ECDF generating function</span></span>
<span id="cb3-6">ecdf_gen <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x,y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>){<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ecdf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbeta</span>(reps,prior_a<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>y,prior_b<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>y)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbeta</span>(reps,prior_a<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>x,prior_b<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x))(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)}</span>
<span id="cb3-7"></span>
<span id="cb3-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#We are reusing p1 and 'n' values from earlier</span></span>
<span id="cb3-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">132</span>)</span>
<span id="cb3-10">n_sim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb3-11">sim_A1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbinom</span>(n_sim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prob =</span> p1) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#round(rnorm(n_sim, mean = n*p1, sd = sqrt(n*p1*q1)),0)</span></span>
<span id="cb3-12">sim_A2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbinom</span>(n_sim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prob =</span> p1) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#round(rnorm(n_sim, mean = n*p1, sd = sqrt(n*p1*q1)),0)</span></span>
<span id="cb3-13"></span>
<span id="cb3-14"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">with_progress</span>({</span>
<span id="cb3-15">  p<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">progressor</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> n_sim)</span>
<span id="cb3-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">future_map2</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.x=</span>sim_A1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.y =</span> sim_A2,</span>
<span id="cb3-17">            <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>{<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">p</span>();<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">A2&gt;A1</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ecdf_gen</span>(.x,.y,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">A1&gt;A2</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ecdf_gen</span>(.y,.x)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)},</span>
<span id="cb3-18">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.options =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">furrr_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">132</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb3-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb3-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</span>(),<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(.x)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_sim<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Comparison'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Nulls Rejected(%)'</span>) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> dt1</span>
<span id="cb3-21">})</span></code></pre></div>
</details>
</div>
<p>The table below indicates the number of times (% of simulations) we reject the null in favour of either A1 or A2:</p>
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(dt1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">align =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'c'</span>)</span></code></pre></div>
</details>
<div id="tbl-001" class="quarto-layout-panel anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl quarto-uncaptioned" id="tbl-001-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1
</figcaption>
<div aria-describedby="tbl-001-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 50.0%;justify-content: center;">
<table class="do-not-create-environment caption-top table">
<thead>
<tr class="header">
<th style="text-align: center;">Comparison</th>
<th style="text-align: center;">Nulls Rejected(%)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">A2&gt;A1</td>
<td style="text-align: center;">10.20</td>
</tr>
<tr class="even">
<td style="text-align: center;">A1&gt;A2</td>
<td style="text-align: center;">10.09</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</figure>
</div>
<p>Our rate of rejecting the null was slightly higher than 20%.</p>
<p>This is despite the fact that using the same prior for both <img src="https://latex.codecogs.com/png.latex?p_%7BA1%7D"> and <img src="https://latex.codecogs.com/png.latex?p_%7BA2%7D"> should lower it as we are adding <em>a priori</em> evidence for the baseline being the same. In all honesty this is more or less a simulation artifact and we can use a stronger prior like beta(100,900). But the gaps in the beta-binomial approach should now be clear.</p>
<section id="ibe-bayesian-aa-test---conclusions" class="level2">
<h2 class="anchored" data-anchor-id="ibe-bayesian-aa-test---conclusions">IBE Bayesian A/A Test - Conclusions</h2>
<p>Notice how we consciously made a comparison on both sides (A2&gt;A1 and A1&gt;A2). When running an A/B test, we typically look to find evidence to justify a new design – there is a built-in directional bias. This gets reflected in the math when typically the ratio is compared on only one side. But an A/A test forces us to rethink this. Clearly the comparison should be made on both sides.</p>
<p>Before any data is collected, it is equally likely that design B is worse than design A. Yet, this isn’t taken into account when practitioners compare the ECDF of ratio of conversion rates solely in the direction where B is greater.</p>
<p>In practice, I have seen practitioners first check the direction, and then take the ratio as <img src="https://latex.codecogs.com/png.latex?p_%7Bb%7D/p_%7Ba%7D"> or <img src="https://latex.codecogs.com/png.latex?p_%7Ba%7D/p_%7Bb%7D">, whatever is convenient. It should be obvious that this is a post-hoc selection of direction, and obviously unless the p-value is halved, this is also equivalent to a 1-tailed test.</p>
<p><strong>Once again, the problem isn’t the math, the problem is in the implementation. There are clear disadvantages to the IBE model.</strong></p>
</section>
</section>
<section id="a-note-on-a-weird-prior-selection-method-in-the-wild-the-time-series-trauma-technique" class="level1">
<h1>A note on a weird prior selection method in the wild – The Time Series Trauma Technique</h1>
<section id="a-primer-about-the-beta-distribution-and-its-role-as-a-prior" class="level2">
<h2 class="anchored" data-anchor-id="a-primer-about-the-beta-distribution-and-its-role-as-a-prior">A primer about the beta distribution and its role as a prior</h2>
<p>Here is a fun exercise: what does it really mean to say that your prior is beta(1,9)? In simple terms, it means that if you collected 10 data-points, one of them should indicate a conversion. The expected value of a beta distribution is usually <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Calpha%7D%7B%5Calpha+%5Cbeta%7D">, where <img src="https://latex.codecogs.com/png.latex?%5Calpha"> and <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> are termed shape parameters. They essentially govern the shape of what the beta distribution would like on its support of 0 to 1. In essence, a beta distribution places weights on most likely conversion rates of an event.</p>
<p>The expected value of beta(10,90) and beta(100,900) are the same, yet the latter is a much stronger assertion that the conversion rate is 10%. Think of it like drawing 100 data-points in the former case while drawing 1000 in the latter case, and then claiming that the observed conversion rate is 10%. The latter has a lower standard deviation and places more mass around 10% as opposed to the former.</p>
<p>Formally,</p>
<p><img src="https://latex.codecogs.com/png.latex?%0AE%5BP%5D%20=%20%5Cfrac%7B%5Calpha%7D%7B%5Calpha+%5Cbeta%7D%0A"></p>
<p><img src="https://latex.codecogs.com/png.latex?%0AVar%5BP%5D%20=%20%5Cfrac%7B%5Calpha.%5Cbeta%7D%7B(%5Calpha+%5Cbeta)%5E2.(%5Calpha+%5Cbeta+1)%7D%0A"></p>
<p>Historical data can really only tell you about the former, and the choice of the shape parameters is essentially a choice in how strong you want your prior to be. <em>This is the crux of the Bayesian Inference paradigm</em> – <em>choosing the appropriate strength of your prior once you have chosen the model.</em></p>
<p>Historical data isn’t going to help you in this regard. However, practical considerations force us to estimate how much data we reasonably expect to collect for an A/B test. If you have the luxury of being able to collect a lot of data for your A/B Test in a short span of time, then it doesn’t really matter whether you use a beta(1,1) model or a frequentist model or, heck, ask my mum to look at 10% and 12% after a million data points and see if she thinks B is better than A (spoiler alert: it’s always A; B is for those who didn’t work hard in school).</p>
<p>A reasonable rule of thumb can be – <em>don’t make your prior dominate your data</em> – unless you have good reasons for this to be the case. So, if you expect to collect 20K data-points per design, a prior like beta(10K,90K) can be highly inappropriate. You might as well not run the test, especially if the aim is to establish a decent magnitude of lift. Always remember:</p>
<blockquote class="blockquote">
<p>The posterior distribution is a compromise between the prior and the likelihood as derived from the data.</p>
</blockquote>
<p>Let’s try and see this from visualizations! We’ll plot a beta prior for a single conversion rate.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb5-2">q1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p1</span>
<span id="cb5-3"></span>
<span id="cb5-4">chart_labs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Beta(10,90)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Beta(50,450)"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Beta(100,900)"</span>)</span>
<span id="cb5-5"></span>
<span id="cb5-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">450</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">900</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>])) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb5-12">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Strength of Priors"</span>,</span>
<span id="cb5-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Base Rate = 10%; Shape Changes as shape parameters change."</span>,</span>
<span id="cb5-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Note: We are plotting prior for a single conversion rate."</span>,</span>
<span id="cb5-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>,</span>
<span id="cb5-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Beta Priors'</span>,</span>
<span id="cb5-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parse =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minor_breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">275</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb5-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> chart_labs) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_clean</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb5-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>))</span></code></pre></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://arorarohan.com/posts/20251112-bayesian-aa-2/index_files/figure-html/Chart-002-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>We can see above that as both α and β increase, the beta distribution gets narrower, i.e.&nbsp;the spread or standard deviation reduces. From the variance formula above we can see that the denominator grows faster than the numerator as either of those shape parameters increases.</p>
<p>Now let’s look at the impact of the prior on the posterior. To increase contrast, we’ll assume that the historical conversion rate was 10% for the design, but lately it’s been around 11%. We observe 2000 data-points. Note that we are still speaking of a single conversion rate in this illustrative example.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span></span>
<span id="cb6-2">q1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p1</span>
<span id="cb6-3">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span></span>
<span id="cb6-4">chart_labs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Prior"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Likelihood"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Posterior"</span>)</span>
<span id="cb6-5"></span>
<span id="cb6-6">plt1<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb6-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb6-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Prior: Beta(10,90)"</span>,</span>
<span id="cb6-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Posterior is dominated by the data."</span>,</span>
<span id="cb6-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>,</span>
<span id="cb6-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parse =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minor_breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">275</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> chart_labs) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_clean</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>)</span>
<span id="cb6-21"></span>
<span id="cb6-22">plt2<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb6-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">450</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">450</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb6-29">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Prior: Beta(50,450)"</span>,</span>
<span id="cb6-30">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Posterior is diffused a bit."</span>,</span>
<span id="cb6-31">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>,</span>
<span id="cb6-32">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parse =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minor_breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">275</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-34">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> chart_labs) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-35">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_clean</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-36">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>)</span>
<span id="cb6-37"></span>
<span id="cb6-38">plt3<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb6-39"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">900</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-41">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-42">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_function</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> dbeta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">args=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape1=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">shape2=</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">900</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> chart_labs[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">linetype =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-43">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guides</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">colour =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guide_legend</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-44">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb6-45">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Prior: Beta(100,900)"</span>,</span>
<span id="cb6-46">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Posterior is pulled by the prior."</span>,</span>
<span id="cb6-47">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>,</span>
<span id="cb6-48">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parse =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-49">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minor_breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">025</span>, .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">275</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-50">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> chart_labs) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-51">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_clean</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-52">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>), ,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position =</span>  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"none"</span>)</span>
<span id="cb6-53"></span>
<span id="cb6-54">plt4<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb6-55"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,chart_labs),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col=</span>chart_labs)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_line</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-56">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> chart_labs) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb6-57">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Curve Type"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-58">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_clean</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb6-59">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>), ,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>))</span>
<span id="cb6-60"></span>
<span id="cb6-61">extract_legend <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(my_ggp) {</span>
<span id="cb6-62">  step1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot_gtable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot_build</span>(my_ggp))</span>
<span id="cb6-63">  step2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sapply</span>(step1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>grobs, <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>name) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"guide-box"</span>)</span>
<span id="cb6-64">  step3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> step1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>grobs[[step2]]</span>
<span id="cb6-65">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(step3)</span>
<span id="cb6-66">}</span>
<span id="cb6-67"></span>
<span id="cb6-68">shared_legend <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extract_legend</span>(plt4)</span>
<span id="cb6-69">  </span>
<span id="cb6-70"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grid.arrange</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrangeGrob</span>(plt1,plt2,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrangeGrob</span>(plt3,shared_legend, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://arorarohan.com/posts/20251112-bayesian-aa-2/index_files/figure-html/Chart-003-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="using-historical-time-based-data-to-estimate-the-shape-parameters" class="level2">
<h2 class="anchored" data-anchor-id="using-historical-time-based-data-to-estimate-the-shape-parameters">Using historical time-based data to estimate the shape parameters</h2>
<p>Since we have two shape parameters, in order to estimate them from historical data, we’ll need two inputs. One is of course the average rate. If we can somehow insinuate a variance from somewhere, we’ll have a second parameter.</p>
<p>The variance of a conversion rate is generally expressed as <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7Bp.(1-p)%7D%7Bn%7D">, so if we were to keep aggregating data over a sufficiently large number of hours or days or weeks, our uncertainty in the conversion rate would be lowered, <em>ceteris paribus</em> (all else remaining equal, i.e., no structural shift in the conversion rate). Most often, we are talking about a conversion rate over the recent past, e.g., the most recent quarter.</p>
<p>Our variance input in this case is just a function of how much data we choose to aggregate, so to me at least this does not seem like a particularly useful method, but it can be made to work, when combined with an appropriate rule-of-thumb like the prior’s volume should not dominate that of the data you expect to collect.</p>
<p>A particularly diabolical approach that I have seen however is calculating the conversion rate over a fixed time-window for ‘T’ periods and then calculating the average and variance from there! Yes, you read that right, some people will calculate daily conversion rate over a 90-day period, then promptly use that to calculate a standard deviation. I cannot even begin to imagine how someone thought that calculating the standard deviation of the time series is the same as estimating the standard deviation of a conversion metric.</p>
<p>Then again, I have made my fair share of purgatorial choices, in life and in work. But let’s look at the impact of such a choice for building priors.</p>
<p>We’ll simulate a few conversion rate scenarios varying with some degree around 10%, and then we’ll calculate the average rate and standard deviation of the time-series over 30, 91 and 180 days.</p>
<p>Then we’ll reverse it and calculate the α and β parameters.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">134</span>)</span>
<span id="cb7-2"></span>
<span id="cb7-3">ll <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t_count =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">91</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">180</span>), </span>
<span id="cb7-4">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scenarios =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s1 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dist =</span> rbeta,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dname =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'beta'</span>, </span>
<span id="cb7-5">                                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">params =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>),</span>
<span id="cb7-6">                                                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>),</span>
<span id="cb7-7">                                                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">900</span>),</span>
<span id="cb7-8">                                                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9000</span>))),</span>
<span id="cb7-9">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">s2 =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dist =</span> runif,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dname =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'unif'</span>, </span>
<span id="cb7-10">                                      <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">params =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">08</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">12</span>),</span>
<span id="cb7-11">                                                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">09</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>),</span>
<span id="cb7-12">                                                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">095</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">105</span>),</span>
<span id="cb7-13">                                                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0975</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1025</span>)))</span>
<span id="cb7-14">                            )</span>
<span id="cb7-15">           )</span>
<span id="cb7-16"></span>
<span id="cb7-17"></span>
<span id="cb7-18"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.x =</span> ll<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t_count, </span>
<span id="cb7-19">    \(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> .x) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.x =</span> ll<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>scenarios,</span>
<span id="cb7-20">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map2</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(.x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>dist), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.y =</span> .x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>params, </span>
<span id="cb7-21">                             \(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fn=</span>.x,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pars =</span> .y) {a <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fn</span>(n,pars[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>],pars[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]); </span>
<span id="cb7-22">                             <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mu =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mean</span>(a),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sd</span>(a)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>()})</span>
<span id="cb7-23">                  ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>()</span>
<span id="cb7-24">    ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> a</span>
<span id="cb7-25"></span>
<span id="cb7-26">scen_names <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(ll<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>scenarios, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(.x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>dname, .x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>params)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>()</span>
<span id="cb7-27">ab_table <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">t_count =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(ll<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t_count, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">each =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(scen_names)), </span>
<span id="cb7-28">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Scenario =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rep</span>(scen_names,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(ll<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t_count)), a) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb7-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(((<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> sd<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> mu) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb7-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">beta =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(alpha <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> mu <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)))</span></code></pre></div>
</details>
</div>
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">k1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(ll<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t_count, </span>
<span id="cb8-2">         <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>ab_table <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(t_count <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> .x) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>t_count)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_names</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"t_tbl_"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(ll<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>t_count)))</span>
<span id="cb8-3"></span>
<span id="cb8-4"></span>
<span id="cb8-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(k1[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb8-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(k1[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb8-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(k1[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span></code></pre></div>
</details>
<div id="tbl-002" class="quarto-layout-panel anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-002-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;2: Reverse Calculation of α and β
</figcaption>
<div aria-describedby="tbl-002-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="quarto-layout-row">
<div class="cell-output-display quarto-layout-cell-subref quarto-layout-cell" data-ref-parent="tbl-002" style="flex-basis: 100.0%;justify-content: center;">
<div id="tbl-002-1" class="do-not-create-environment quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-tbl figure">
<figcaption class="quarto-float-caption-top quarto-subfloat-caption quarto-subfloat-tbl" id="tbl-002-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(a) T = 30
</figcaption>
<div aria-describedby="tbl-002-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table id="tbl-002-1" class="do-not-create-environment caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Scenario</th>
<th style="text-align: right;">mu</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">alpha</th>
<th style="text-align: right;">beta</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">beta c(1, 9)</td>
<td style="text-align: right;">0.092</td>
<td style="text-align: right;">0.099</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10</td>
</tr>
<tr class="even">
<td style="text-align: left;">beta c(10, 90)</td>
<td style="text-align: right;">0.095</td>
<td style="text-align: right;">0.036</td>
<td style="text-align: right;">6</td>
<td style="text-align: right;">57</td>
</tr>
<tr class="odd">
<td style="text-align: left;">beta c(100, 900)</td>
<td style="text-align: right;">0.099</td>
<td style="text-align: right;">0.011</td>
<td style="text-align: right;">77</td>
<td style="text-align: right;">704</td>
</tr>
<tr class="even">
<td style="text-align: left;">beta c(1000, 9000)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.003</td>
<td style="text-align: right;">932</td>
<td style="text-align: right;">8362</td>
</tr>
<tr class="odd">
<td style="text-align: left;">unif c(0.08, 0.12)</td>
<td style="text-align: right;">0.102</td>
<td style="text-align: right;">0.012</td>
<td style="text-align: right;">70</td>
<td style="text-align: right;">614</td>
</tr>
<tr class="even">
<td style="text-align: left;">unif c(0.09, 0.11)</td>
<td style="text-align: right;">0.099</td>
<td style="text-align: right;">0.006</td>
<td style="text-align: right;">268</td>
<td style="text-align: right;">2442</td>
</tr>
<tr class="odd">
<td style="text-align: left;">unif c(0.095, 0.105)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.003</td>
<td style="text-align: right;">871</td>
<td style="text-align: right;">7839</td>
</tr>
<tr class="even">
<td style="text-align: left;">unif c(0.0975, 0.1025)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.001</td>
<td style="text-align: right;">5193</td>
<td style="text-align: right;">46801</td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="cell-output-display quarto-layout-cell-subref quarto-layout-cell" data-ref-parent="tbl-002" style="flex-basis: 100.0%;justify-content: center;">
<div id="tbl-002-2" class="do-not-create-environment quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-tbl figure">
<figcaption class="quarto-float-caption-top quarto-subfloat-caption quarto-subfloat-tbl" id="tbl-002-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(b) T = 91
</figcaption>
<div aria-describedby="tbl-002-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table id="tbl-002-2" class="do-not-create-environment caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Scenario</th>
<th style="text-align: right;">mu</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">alpha</th>
<th style="text-align: right;">beta</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">beta c(1, 9)</td>
<td style="text-align: right;">0.093</td>
<td style="text-align: right;">0.077</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">10</td>
</tr>
<tr class="even">
<td style="text-align: left;">beta c(10, 90)</td>
<td style="text-align: right;">0.099</td>
<td style="text-align: right;">0.030</td>
<td style="text-align: right;">10</td>
<td style="text-align: right;">91</td>
</tr>
<tr class="odd">
<td style="text-align: left;">beta c(100, 900)</td>
<td style="text-align: right;">0.101</td>
<td style="text-align: right;">0.009</td>
<td style="text-align: right;">112</td>
<td style="text-align: right;">996</td>
</tr>
<tr class="even">
<td style="text-align: left;">beta c(1000, 9000)</td>
<td style="text-align: right;">0.101</td>
<td style="text-align: right;">0.003</td>
<td style="text-align: right;">985</td>
<td style="text-align: right;">8815</td>
</tr>
<tr class="odd">
<td style="text-align: left;">unif c(0.08, 0.12)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.011</td>
<td style="text-align: right;">75</td>
<td style="text-align: right;">677</td>
</tr>
<tr class="even">
<td style="text-align: left;">unif c(0.09, 0.11)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.006</td>
<td style="text-align: right;">238</td>
<td style="text-align: right;">2138</td>
</tr>
<tr class="odd">
<td style="text-align: left;">unif c(0.095, 0.105)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.003</td>
<td style="text-align: right;">1129</td>
<td style="text-align: right;">10128</td>
</tr>
<tr class="even">
<td style="text-align: left;">unif c(0.0975, 0.1025)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.001</td>
<td style="text-align: right;">4170</td>
<td style="text-align: right;">37594</td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
</div>
</div>
<div class="quarto-layout-row">
<div class="cell-output-display quarto-layout-cell-subref quarto-layout-cell" data-ref-parent="tbl-002" style="flex-basis: 100.0%;justify-content: center;">
<div id="tbl-002-3" class="do-not-create-environment quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-tbl figure">
<figcaption class="quarto-float-caption-top quarto-subfloat-caption quarto-subfloat-tbl" id="tbl-002-3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(c) T = 180
</figcaption>
<div aria-describedby="tbl-002-3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table id="tbl-002-3" class="do-not-create-environment caption-top table">
<thead>
<tr class="header">
<th style="text-align: left;">Scenario</th>
<th style="text-align: right;">mu</th>
<th style="text-align: right;">sd</th>
<th style="text-align: right;">alpha</th>
<th style="text-align: right;">beta</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">beta c(1, 9)</td>
<td style="text-align: right;">0.107</td>
<td style="text-align: right;">0.089</td>
<td style="text-align: right;">1</td>
<td style="text-align: right;">8</td>
</tr>
<tr class="even">
<td style="text-align: left;">beta c(10, 90)</td>
<td style="text-align: right;">0.098</td>
<td style="text-align: right;">0.027</td>
<td style="text-align: right;">12</td>
<td style="text-align: right;">110</td>
</tr>
<tr class="odd">
<td style="text-align: left;">beta c(100, 900)</td>
<td style="text-align: right;">0.099</td>
<td style="text-align: right;">0.009</td>
<td style="text-align: right;">108</td>
<td style="text-align: right;">985</td>
</tr>
<tr class="even">
<td style="text-align: left;">beta c(1000, 9000)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.003</td>
<td style="text-align: right;">883</td>
<td style="text-align: right;">7949</td>
</tr>
<tr class="odd">
<td style="text-align: left;">unif c(0.08, 0.12)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.012</td>
<td style="text-align: right;">68</td>
<td style="text-align: right;">613</td>
</tr>
<tr class="even">
<td style="text-align: left;">unif c(0.09, 0.11)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.006</td>
<td style="text-align: right;">285</td>
<td style="text-align: right;">2579</td>
</tr>
<tr class="odd">
<td style="text-align: left;">unif c(0.095, 0.105)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.003</td>
<td style="text-align: right;">1028</td>
<td style="text-align: right;">9271</td>
</tr>
<tr class="even">
<td style="text-align: left;">unif c(0.0975, 0.1025)</td>
<td style="text-align: right;">0.100</td>
<td style="text-align: right;">0.001</td>
<td style="text-align: right;">4428</td>
<td style="text-align: right;">39825</td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
</div>
</div>
</div>
</figure>
</div>
<p>As the average daily conversion rate becomes more stable, the role of the prior becomes progressively larger. No surprises there. But what seems weird is that changing the number of days has a somewhat of an unpredictable impact. Sometimes it leads to a stronger prior while sometimes it leads to a weaker prior.</p>
<p>Again, this could very well be an artifact of simulation.</p>
<p>Nevertheless, I have great reservations about this approach for the following reason:</p>
<p>It says nothing about what is really going to happen with your experiment data. It could get drowned out by the prior, or it could make the prior completely redundant. Given that:</p>
<ul>
<li><p>a Bayesian methodology is most often preferred where we expect to collect an insufficient amount of data w.r.t. a fixed-sample frequentist test of proportion,</p></li>
<li><p>We most often use the same prior for design A and B, which automatically means that the posterior lift is going to be less than the lift observed from raw data,</p></li>
</ul>
<p>this style of building your prior is often going to drown your results exactly where you need support of modeled beliefs, especially on those assets where the conversion rate is more or less quite stable.</p>
<p>I am repeating myself here, but if you can collect a large amount of data for your experiment in a short span of time, Bayesian methodologies of any flavour aren’t going to give you a particularly contrary result as compared to the frequentist approach.</p>
<p>Crucially, this approach abstracts away the important practice, art and science of building principled priors, since your priors are essentially appearing auto-magically. We have also not talked about a scenario where there may be value in biasing your prior for a non-zero MDE (where you set α and β for the two designs distinctly) up front. While a rare situation, there are times when a non-zero null makes sense, either in a frequentist or a Bayesian approach.</p>
</section>
</section>
<section id="section" class="level1">
<h1>…</h1>
<p>We saw some pitfalls in how A/B tests based on IBE Bayesian approach can suffer from implementation errors and inadvertent inflation of Type 1 error rates.</p>
<p>We also a particularly weird way of defining priors.</p>
<p>Our final conclusion is that the problem is often between the chair and the keyboard, and in the fear of codifying your prior beliefs incorrectly, thereby screwing up your annual bonus.</p>
<p>In the <a href="../../posts/20251118-bayesian-ab-3/index.html" title="Technically Correct Bayesian A/B Testing w/o MC sims">next post</a> we look at an alternative Bayesian methodology that potentially mitigates these implementation errors.</p>


</section>

 ]]></description>
  <category>Product</category>
  <category>Experimentation</category>
  <category>AB Testing</category>
  <category>AA Testing</category>
  <category>Bayesian</category>
  <guid>https://arorarohan.com/posts/20251112-bayesian-aa-2/</guid>
  <pubDate>Tue, 11 Nov 2025 22:00:00 GMT</pubDate>
  <media:content url="https://arorarohan.com/posts/20251112-bayesian-aa-2/aa_test.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>Is H0: 𝛿= |pb - pa| = 0 the same as H0: pb = pa?</title>
  <dc:creator>Rohan Arora</dc:creator>
  <link>https://arorarohan.com/posts/20251110-is-pa-pb/</link>
  <description><![CDATA[ 





<p><em>Note: I have blind spots. With limited formal training in advanced statistics, often I won’t know what I don’t know. One key reason to start this blog was to iron out those blind-spots, and all help in that regard is welcome.</em></p>
<section id="introduction" class="level1">
<h1>Introduction</h1>
<p>I look at hypothesis testing in three stages:</p>
<ol type="1">
<li>Null view of the world.</li>
<li>Alternate view of the world.</li>
<li>Uncertain but observable underlying reality.</li>
</ol>
<p>My previous <a href="https://arorarohan.com/posts/20251107-bayesian-ab-1/" title="Bayesian A/B Testing Musings, Rohan Arora">post</a> created a bit of kerfuffle around whether or not there is an implicit assumption that the Type 1 Error Rate is 50% when applying a decision rule that compares the simulations of two distributions under differing parameters.</p>
</section>
<section id="is-h_0-p_b-p_a-same-as-h_0-p_b---p_a0" class="level1">
<h1>Is <img src="https://latex.codecogs.com/png.latex?H_0%20:%20p_b%20=%20p_a"> same as <img src="https://latex.codecogs.com/png.latex?H_0%20:%20%7Cp_b%20-%20p_a%7C=0"> ?</h1>
<p>When do we commit a Type 1 Error? In the simplest terms, when planning an experiment, I have to define a rejection region where I will reject the null hypothesis. When the observed reality appears in the rejection region, there is a chance that it was a fluke and the there is no underlying causal effect.</p>
<p>It can also be the case that the underlying effect is real and in fact larger or just at the boundary of the rejection region. Either way rejecting the null was the right decision but I cannot really know. There will always be a chance that even with a large enough effect there really is no difference between the two samples being compared.</p>
<p>When I observe the data, I either reject the null or I don’t (or say that there isn’t enough evidence to apply the decision rule). It’s not possible to know if I committed an error or if I correctly rejected the null. We hope to minimise the probability of making an error in the planning stage, but after collecting the data the decision is made and that is that.</p>
<p>The purpose of this section is to point out how expressing the null hypothesis as <img src="https://latex.codecogs.com/png.latex?H_0%20:%20p_b%20=%20p_a"> while being technically correct, can be misleading. It makes it seem like we are comparing two different random variables, both of which are ultimately an estimator of the unobservable (mean?) conversion rate of individual Bernoulli trials under two different treatments. But really all we do is either take their ratio or difference and study that. The ratio or the difference is a different random variable and studying that variable in a hypothesis test is not the same as estimating the conversion rates of two designs.</p>
<p>When are two random variables equal (or almost equal)? Let’s take the less strict definition, that when they are ‘equal in distribution’. That is, they have the same set of possible values and the same probabilities for all of those values.</p>
<p>Even an A/A test does not result in a situation where the estimates of <img src="https://latex.codecogs.com/png.latex?p_a"> and <img src="https://latex.codecogs.com/png.latex?p_b"> would be exactly equal. Essentially this null hypothesis, if applied strictly, would result in a situation where an effect is always present.</p>
<p>In practice, if we force ourselves to not use the difference of estimated rates as the test statistic, we can choose to simulate data from two distributions and count the number of times one exceeds the other. Let’s understand this with a code exercise. We’ll use the following values for the planning stage:</p>
<p>Historical Rate: 10%, MDE: 5%, T1 Error Rate = 10%, Power = 90%, Type = 2-tailed</p>
<p>We’ll also run a <em>hypothetical A/B test</em> where the observed lift was 2.2%. For simplicity, we assume that the observed rate for design A was 10%. Note that this is the observed reality, and we are always uncertain about it.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(glue)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(furrr)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggthemes)</span>
<span id="cb1-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(progressr)</span>
<span id="cb1-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(extrafont) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#You can skip it if you like, it's for text on charts.</span></span>
<span id="cb1-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(knitr)</span>
<span id="cb1-8"></span>
<span id="cb1-9"><span class="do" style="color: #5E5E5E;
background-color: null;
font-style: italic;">##Modify this as per your computing setup</span></span>
<span id="cb1-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plan</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strategy =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'multisession'</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">workers =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span></code></pre></div>
</details>
</div>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb2-2">p2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">105</span></span>
<span id="cb2-3">q1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p1</span>
<span id="cb2-4">q2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p2</span>
<span id="cb2-5"></span>
<span id="cb2-6">alpha <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span></span>
<span id="cb2-7">power <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span></span>
<span id="cb2-8"></span>
<span id="cb2-9">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power.prop.test</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p1 =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p2 =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">105</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sig.level =</span> alpha,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">power =</span> power)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n)</span>
<span id="cb2-10"></span>
<span id="cb2-11">sd_unpooled <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>p2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n)</span>
<span id="cb2-12"></span>
<span id="cb2-13">lift_crit_bounds_2t <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qnorm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> sd_unpooled)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>p1</span>
<span id="cb2-14">crit_bounds<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sprintf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"%.3f%%"</span>,lift_crit_bounds_2t<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)</span></code></pre></div>
</details>
</div>
<p>Critical lift boundaries(%) for selected parameters under null view that 𝛿=0: -2.810%, 2.810%</p>
<p>Now let’s apply the test of proportions for the hypothetical A/B Test.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">obs_lift<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">022</span></span>
<span id="cb3-2">x<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">prop.test</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(p1,p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>obs_lift))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(n,n))</span>
<span id="cb3-3">x</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>
    2-sample test for equality of proportions with continuity correction

data:  c(p1, p1 * (1 + obs_lift)) * n out of c(n, n)
X-squared = 1.6541, df = 1, p-value = 0.1984
alternative hypothesis: two.sided
95 percent confidence interval:
 -0.00554429  0.00114429
sample estimates:
prop 1 prop 2 
0.1000 0.1022 </code></pre>
</div>
</div>
<p>We see that the p.value of 19.84% is above the p.value threhsold of 10% when the observed positive lift 2.2% is within the critical lift boundaries for our 2-tailed test of proportions.</p>
<p>Now let’s use a simulation to analyse the same hypothetical experiment.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Simulations for the same boundary</span></span>
<span id="cb5-2">pp2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>obs_lift)</span>
<span id="cb5-3">qq2<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>pp2</span>
<span id="cb5-4">n_sim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span></span>
<span id="cb5-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">132</span>)</span>
<span id="cb5-6">sim_p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span>n_sim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span>p1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n))</span>
<span id="cb5-7">sim_p2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span>n_sim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span>pp2,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(pp2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qq2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n))</span>
<span id="cb5-8"></span>
<span id="cb5-9">pct_superior <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sim_p2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>sim_p1))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_sim</span></code></pre></div>
</details>
</div>
<p>When estimated E(pa) = 10% and E(pb) = 10.22%, the simulated values of pb exceed pa 90.26% of the time.</p>
<p>If we interpret this to be the same as p.value, then the p.value here is ~9.74%, which is below the threshold of 0.1%. But how can that be?</p>
<p>The answer lies in the fact that the two comparisons are not the same. The latter comparison is one tailed. For continuous variables, if I were to sum <img src="https://latex.codecogs.com/png.latex?p(p_a%3Ep_b)"> and <img src="https://latex.codecogs.com/png.latex?p(p_a%3Cp_b)">, this would sum to 1. This is like saying that an effect is always present.</p>
<p>Let’s break character a bit and use the ratio of the two simulations, and look at the quantiles.</p>
<p>Quantiles of the ratio of conversion rates from design B and design A’s simulated data:</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(sim_p2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>sim_p1,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">95</span>))</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>       5%       10%       50%       90%       95% 
0.9941954 1.0002433 1.0220187 1.0442273 1.0506892 </code></pre>
</div>
</div>
<p>Percentage of simulations where ratio is at or below 1: 9.74%.</p>
<p>Notice how the 5th percentile of the ratio of the two simulations is below 1. This is important. Now let’s assume that observed lift of our hypothetical experiment was in fact 2.81%, which is at the boundary of our rejection region under the null defined as <strong>𝛿=0</strong> under the 2-sample test of proportions. At lift = 2.81%, the null will be rejected in favour of design B by the 2-sample test of proportions.</p>
<p>Let’s simulate this scenario.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#Simulations for the same boundary</span></span>
<span id="cb8-2">pp2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0281</span></span>
<span id="cb8-3">qq2<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>pp2</span>
<span id="cb8-4">n_sim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span></span>
<span id="cb8-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">132</span>)</span>
<span id="cb8-6">sim_p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span>n_sim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span>p1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n))</span>
<span id="cb8-7">sim_p2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span>n_sim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span>pp2,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(pp2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>qq2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n))</span></code></pre></div>
</details>
</div>
<p>Quantiles of the ratio of conversion rates from design B and design A’s simulated data:</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">quantile</span>(sim_p2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>sim_p1,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">95</span>))</span></code></pre></div>
</details>
<div class="cell-output cell-output-stdout">
<pre><code>      5%      10%      50%      90%      95% 
1.000173 1.006252 1.028119 1.050425 1.056911 </code></pre>
</div>
</div>
<p>Percentage of simulations where ratio is at or below 1: 4.89%</p>
<p>At the boundary condition, the 5th percentile of the ratio of the conversion rates is above 1.</p>
<p>If the decision rule is changed,</p>
<ul>
<li><p>From: checking if the count of the ratio exceeds 1 at least (1-𝛂)% of times</p></li>
<li><p>To: checking that the 𝛂/2 percentile value of the simulation ratios is above 1,</p></li>
</ul>
<p>the two decision criteria are essentially at par. But this is to be expected. 5th Percentile is α/2 for our chosen value of α=10%. There is only a 4.8% chance that true conversion rate of design B is worse than that of design A.</p>
<p>Ergo, we are insisting on both a two-tailed comparison and defining a zone of uncertainty by looking at the 5th percentile of the ratio of the two simulations. Please note that if <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp_2%7D%3C%5Chat%7Bp_1%7D">, the comparison needs to be performed for the inverse ratio (you can add them if you prefer, thereby making the comparison direction agnostic).</p>
<p><strong>In conclusion, the two definitions of the null hypothesis are indeed equivalent but in practice the latter can lead to improper application.</strong></p>
<section id="gripe-with-the-ecdf-decisioning-rule-used-in-bayesian-ab-testing" class="level2">
<h2 class="anchored" data-anchor-id="gripe-with-the-ecdf-decisioning-rule-used-in-bayesian-ab-testing">Gripe with the ECDF decisioning rule used in Bayesian A/B Testing</h2>
<p>This is my gripe with the application of ecdf in this <a href="www.countbayesie.com/blog/2015/4/25/bayesian-ab-testing" title="Bayesian Hypothesis Testing, Will Kurt">article</a> on Bayesian A/B testing. It’s not that it is incorrect, but that people often misinterpret this decisioning rule and end up applying a 1-tailed test while insisting that the IBE model leads to reduction in sample-size requirements as compared to a 2-tailed test of proportions.</p>
<p>If we stick to using the decisioning rule that the ECDF at 1 for the ratio of conversion rates should be less than the p-value threshold (or its half for a 2-tailed test), the decision rule will work at par in an IBE Bayesian framework with an uninformative Beta(1,1) prior.</p>
<p>This should hopefully become more apparent in the next section.</p>
<p>Another minor gripe is claiming that you get an entire range of values for the possible improvement using an ECDF. While this is technically correct, a confidence interval around the mean observed lift also provides an entire range of possible values, even though there are subtle differences in the interpretation of the two results.</p>
<p>Most business executives and product people I worked with took me to the cleaners at the mention of a confidence (or credible) interval. <em>It’s incredible how little confidence they had in me.</em></p>
<p>Practically, we are almost always focused on the mean or median value.</p>
</section>
<section id="why-i-am-of-the-opinion-that-defining-h_0-p_b-p_a-leads-to-an-inflated-t1-error-rate" class="level2">
<h2 class="anchored" data-anchor-id="why-i-am-of-the-opinion-that-defining-h_0-p_b-p_a-leads-to-an-inflated-t1-error-rate">Why I am of the opinion that defining <img src="https://latex.codecogs.com/png.latex?H_0%20:%20p_b%20=%20p_a"> leads to an inflated T1 Error Rate?</h2>
<p>I am open to being criticized here and in fact I have debated this with myself many times. I figured that the only way to know is to spark a public fallout, so here goes nothing.</p>
<p><strong>The premise is that the error is in the application, not the mathematical equivalence of the two formats of expressing the null hypothesis.</strong></p>
<p>Let’s look at a very practical example: the A/A test. If I run an A/A for a sufficient duration, do I expect to reject the null half the time or 𝛂% of the time or all of the time?</p>
<p>The purpose of an A/A test is to detect anomalies in your experimentation infrastructure. A signal that there is a difference in conversion rates observed in two samples indicates potential issues with the setup or infrastructure implementation.</p>
<p>In a frequentist perspective, just about any difference is detectable given you collect enough data. And it’s almost never the case that the difference of two samples of conversion rates will be zero.</p>
<p>But let’s assume that we plan it like a usual fixed-sample test. We’ll use a historical rate of 10%, an MDE of 5%, 𝛂 of 20% and power of 90%.</p>
<p>We’ll simulate 10^6 A/A tests of sample-size ‘n’. We’ll reject the null hypothesis in four ways: once with a test of proportions, once with comparing <img src="https://latex.codecogs.com/png.latex?p_a"> and <img src="https://latex.codecogs.com/png.latex?p_b"> in simulations - both one tailed and two tailed, and once by comparing them at a threshold.</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb11-2">p2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">105</span></span>
<span id="cb11-3">q1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p1</span>
<span id="cb11-4">q2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p2</span>
<span id="cb11-5"></span>
<span id="cb11-6">alpha <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span></span>
<span id="cb11-7">power <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span></span>
<span id="cb11-8"></span>
<span id="cb11-9">n_sim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span></span>
<span id="cb11-10"></span>
<span id="cb11-11">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power.prop.test</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p1 =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p2 =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">105</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sig.level =</span> alpha,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">power =</span> power)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n)</span>
<span id="cb11-12"></span>
<span id="cb11-13">sd_unpooled <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>p2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n)</span>
<span id="cb11-14"></span>
<span id="cb11-15">lift_crit_bounds_2t <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qnorm</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> sd_unpooled)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>p1</span>
<span id="cb11-16"></span>
<span id="cb11-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">132</span>)</span>
<span id="cb11-18">sim_A1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span>n_sim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span>p1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n))</span>
<span id="cb11-19">sim_A2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n=</span>n_sim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean=</span>p1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n))</span>
<span id="cb11-20"></span>
<span id="cb11-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">future_map2</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.x=</span>sim_A1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.y =</span> sim_A2, </span>
<span id="cb11-22">     \(.x,.y) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">null_rejected =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">prop.test</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(.x,.y)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(n,n))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>p.value<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(.y<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>.x,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'A2&gt;A1'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'A1&gt;A2'</span>)), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.options =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">furrr_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">169</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">direction =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(null_rejected,direction,<span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(null_rejected,direction) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pct=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_sim<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.groups =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'keep'</span>) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> dt0</span>
<span id="cb11-23"></span>
<span id="cb11-24">pct_prop <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> dt0 <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(null_rejected) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(pct) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>()</span>
<span id="cb11-25">x1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sim_A1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>sim_A2))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_sim</span>
<span id="cb11-26">x2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sim_A1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>sim_A2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(sim_A1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>sim_A2))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_sim</span>
<span id="cb11-27">x3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>((sim_A2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>sim_A1)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>lift_crit_bounds_2t[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>((sim_A2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>sim_A1)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>lift_crit_bounds_2t[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]))<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_sim</span></code></pre></div>
</details>
</div>
<p>The table below indicates the number of times (% of simulations) we reject the null in favour of either A1 or A2:</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(dt0, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<table class="caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: left;">null_rejected</th>
<th style="text-align: left;">direction</th>
<th style="text-align: right;">pct</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">FALSE</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">80.4</td>
</tr>
<tr class="even">
<td style="text-align: left;">TRUE</td>
<td style="text-align: left;">A1&gt;A2</td>
<td style="text-align: right;">9.8</td>
</tr>
<tr class="odd">
<td style="text-align: left;">TRUE</td>
<td style="text-align: left;">A2&gt;A1</td>
<td style="text-align: right;">9.8</td>
</tr>
</tbody>
</table>
</div>
</div>
<ol type="1">
<li><p>Probability of rejecting the null with a two tailed test of proportions per table above: 19.6%.</p></li>
<li><p>Probability of rejecting the null with a one tailed comparison at zero threshold (x1 above): 49.96%.</p></li>
<li><p>Probability of rejecting the null with a two tailed comparison at zero threshold (x2 above): 100%.</p></li>
<li><p>Probability of rejecting the null with a two tailed comparison at critical lift threshold (x3 above): 19.49%.</p></li>
</ol>
<p>Of course it’s trivial to claim that if the boundary condition is at ‘any difference’ goes, the null will be rejected 50% of the time for a one-tailed comparison and 100% of the time for a 2-tailed comparison.</p>
<p>What’s interesting however is that if I apply the same critical boundary as the proportions test to the simulations, my rate of rejecting the null was more or less the same (prob 1 and 4 above).</p>
<p>If I define no zone of uncertainty, I cannot really run an A/A test. We are ALWAYS comparing either the ratio or a difference in rates irrespective of whether we use a parametric test or a simulation. So why express the null as <img src="https://latex.codecogs.com/png.latex?H_0%20:%20p_b%20=%20p_a"> and cause confusion?</p>
<p>This is another reason why I am skeptical of the decision-system whereby we simply compare the instance of the simulations under <img src="https://latex.codecogs.com/png.latex?p_b"> that are greater than those under <img src="https://latex.codecogs.com/png.latex?p_a">. This system does not seem to work very well unless I always use a 1-sided comparison. In an unqualified 2-sided comparison, a simulation tells us that either A1 or A2 is always better, since the two rates are never exactly equal.</p>
</section>
</section>
<section id="sec-bayes-aa" class="level1">
<h1>What about an IBE Bayesian A/A Test?</h1>
<p>It’s simple, really. We take “N” draws from both posterior simulations and then create a ratio as A2/A1 in the usual way. To keep the comparison same as a 2-tailed 2-sample test of proportions, we use the following decision rule: <img src="https://latex.codecogs.com/png.latex?p(ECDF(ratio%20%3C=%201))%20%3C%20p.value%5C%20threshold/2">.</p>
<p>Yes, this is no rocket science. But my blog isn’t aimed at seasoned stats professionals/academicians but rather at a more general audience, to who all of this may not be immediately obvious.</p>
<p>The key however is defining a prior. There is no real point in using a Bayesian methodology if stronger assumptions aren’t made, so we won’t be using an uninformative prior like Beta(1,1). And since we are planning an A/A test, we will be keeping the parameters equal, i.e.&nbsp;𝛂<sub>A1</sub> = 𝛂<sub>A2</sub> = 𝛂 and 𝛃<sub>A1</sub> = 𝛃<sub>A2</sub> = 𝛃.</p>
<p>We kept our historical rate as 10%, so really, the question is whether the prior should be beta(10,90) or beta(1000,9000).</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb13-2">prior_alpha <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>p1</span>
<span id="cb13-3">prior_beta <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>p1)</span>
<span id="cb13-4"></span>
<span id="cb13-5">n_sim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span></span>
<span id="cb13-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">145</span>)</span>
<span id="cb13-7">prior_ratios <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pmap</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.x =</span> prior_alpha,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.y =</span> prior_beta, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nn =</span>n_sim),</span>
<span id="cb13-8">                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.f =</span> \(.x,.y,nn) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbeta</span>(nn,.x,.y)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbeta</span>(nn,.x,.y)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb13-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_cols</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename_with</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.fn =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>LETTERS[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">7</span>]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Priors'</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Ratio'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Priors =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(Priors,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered =</span> T))</span>
<span id="cb13-10"></span>
<span id="cb13-11"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(prior_ratios,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> Ratio,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>Priors, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> Priors)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_boxplot</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">coord_cartesian</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb13-13">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Various Choices for Priors"</span>,</span>
<span id="cb13-14">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Base Rate = 10% AA Test, \u03B1(A1) = \u03B1(A2) = \u03B1 and \u03B2(A1) = \u03B2(A2) = \u03B2"</span>,</span>
<span id="cb13-15">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Note: Plot is under the null hypothesis that a priori expected lift is zero."</span>,</span>
<span id="cb13-16">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Choice of Prior"</span>,</span>
<span id="cb13-17">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Ratio of Conversion Rates from Priors"</span>,</span>
<span id="cb13-18">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parse =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb13-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"\u03B1="</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"5"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"20"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"100"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1k"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>),</span>
<span id="cb13-20">                                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" \u03B2="</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"45"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"90"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"180"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"900"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"9k"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"1"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb13-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minor_breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">4.75</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb13-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_color_colorblind</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_clean</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb13-23">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://arorarohan.com/posts/20251110-is-pa-pb/index_files/figure-html/chart-priors-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>The choice of beta(10,90) seems reasonable. It doesn’t concentrate too heavily around a ratio of 1 and is more or less symmetric about 1. You can already see that the distributions can be right-skewed. Of course you could resolve that by using a difference instead of a ratio. But a ratio seems to be used more often by practitioners and proponents. The outcome of a beta(1,1) is also plotted for comparison. Clearly the range is too vast and it has no meaningful use.</p>
<p>Now let’s perform 10^4 A/A tests (lower count as we also need to simulate the posterior every time). But now comes the key question. In the frequentist paradigm, we just sampled from a normal distribution and each draw of <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp%7D"> was an A/A test.</p>
<p>In the Bayesian paradigm, we are really dealing with the probability of an event. So, do we draw from the normal distribution or something else entirely? What we know is that the average rate has to be 10% and that we will collect same ‘n’ data-points as earlier. Since we kept ‘n’ constant earlier, we can continue to do the same. In fact, we had already assumed that our underlying data is binomially distributed - this is what allows our posterior to be beta distribution (read: conjugate priors).</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">prior_a<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>; prior_b<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span></span>
<span id="cb14-2"></span>
<span id="cb14-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#ECDF generating function</span></span>
<span id="cb14-4">ecdf_gen <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x,y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>){<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ecdf</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbeta</span>(reps,prior_a<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>y,prior_b<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>y)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbeta</span>(reps,prior_a<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>x,prior_b<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x))(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)}</span>
<span id="cb14-5"></span>
<span id="cb14-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#We are reusing p1 and 'n' values from earlier</span></span>
<span id="cb14-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">132</span>)</span>
<span id="cb14-8">n_sim <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb14-9">sim_A1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbinom</span>(n_sim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prob =</span> p1) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#round(rnorm(n_sim, mean = n*p1, sd = sqrt(n*p1*q1)),0)</span></span>
<span id="cb14-10">sim_A2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbinom</span>(n_sim, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> n,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">prob =</span> p1) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#round(rnorm(n_sim, mean = n*p1, sd = sqrt(n*p1*q1)),0)</span></span>
<span id="cb14-11"></span>
<span id="cb14-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">with_progress</span>({</span>
<span id="cb14-13">  p<span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">progressor</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">steps =</span> n_sim)</span>
<span id="cb14-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">future_map2</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.x=</span>sim_A1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.y =</span> sim_A2,</span>
<span id="cb14-15">            <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>{<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">p</span>();<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">A2&gt;A1</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ecdf_gen</span>(.x,.y,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reps =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">A1&gt;A2</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ecdf_gen</span>(.y,.x)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)},</span>
<span id="cb14-16">            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.options =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">furrr_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">seed =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">132</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb14-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span></span>
<span id="cb14-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">summarise</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</span>(),<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(.x)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n_sim<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_longer</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">everything</span>(),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Comparison'</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_to =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Nulls Rejected(%)'</span>) <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-&gt;</span> dt1</span>
<span id="cb14-19">})</span></code></pre></div>
</details>
</div>
<p>The table below indicates the number of times (% of simulations) we reject the null in favour of either A1 or A2:</p>
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(dt1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">digits =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div>
</details>
<div class="cell quarto-layout-panel" data-layout-ncol="1">
<div class="quarto-layout-row">
<div class="quarto-layout-cell" style="flex-basis: 100.0%;justify-content: center;">
<table class="caption-top table table-sm table-striped small">
<thead>
<tr class="header">
<th style="text-align: left;">Comparison</th>
<th style="text-align: right;">Nulls Rejected(%)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">A2&gt;A1</td>
<td style="text-align: right;">10.20</td>
</tr>
<tr class="even">
<td style="text-align: left;">A1&gt;A2</td>
<td style="text-align: right;">10.09</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Our rate of rejecting the null was slightly higher than 20%.</p>
<p>This is despite the fact that using the same prior for both <img src="https://latex.codecogs.com/png.latex?p_%7BA1%7D"> and <img src="https://latex.codecogs.com/png.latex?p_%7BA2%7D"> should lower it as we are adding <em>a priori</em> evidence for the baseline being the same. In all honesty this is more or less a simulation artifact and we can use a stronger prior like beta(100,900). But the gaps in the beta-binomial approach should now be clear.</p>
<section id="ibe-bayesian-aa-test---conclusions" class="level2">
<h2 class="anchored" data-anchor-id="ibe-bayesian-aa-test---conclusions">IBE Bayesian A/A Test - Conclusions</h2>
<p>Notice how we consciously made a comparison on both sides (A2&gt;A1 and A1&gt;A2). When running an A/B test, we typically are looking to implement a new design – there is a built-in directional bias. This gets reflected in the implementation when typically the ratio is compared on only one side for an A/B test. But an A/A test forces us to rethink this. Clearly the comparison should be made on both sides.</p>
<p>Before any data is collected, it is equally likely that design B is worse than design A. Yet, this isn’t taken into account when practitioners compare the ECDF of ratio of conversion rates solely in the direction where B is greater.</p>
<p>In practice, I have seen practitioners first check the direction, and then take the ratio as <img src="https://latex.codecogs.com/png.latex?p_%7Bb%7D/p_%7Ba%7D"> or <img src="https://latex.codecogs.com/png.latex?p_%7Ba%7D/p_%7Bb%7D">, whatever is convenient. It should be obvious that this is a post-hoc selection of direction, and obviously unless the p-value is halved, this is also equivalent to a 1-tailed test.</p>
<p><strong>Once again, the problem isn’t the math, the problem is in the implementation. There are clear disadvantages to the IBE model.</strong></p>
</section>
</section>
<section id="section" class="level1">
<h1>…</h1>
<p>We examined some critical issues in implementation errors when we express our null hypothesis in frequentist approach as: <img src="https://latex.codecogs.com/png.latex?H_0:%20p_b%20=%20p_a">.</p>
<p>We also examined some critical issues in the implementation of Bayesian tests that utilise the IBE model. We also saw that priors on conversion rate ratio can be skewed.</p>
<p>I want to reiterate that the fault is in the model and the implementation, not Bayesian A/B (or A/A) testing. There are more tractable ways of running Bayesian experiments which we will explore in future posts.</p>


</section>

 ]]></description>
  <category>Product</category>
  <category>Experimentation</category>
  <category>AB Testing</category>
  <category>AA Testing</category>
  <category>Causal Inference</category>
  <guid>https://arorarohan.com/posts/20251110-is-pa-pb/</guid>
  <pubDate>Sun, 09 Nov 2025 22:00:00 GMT</pubDate>
  <media:content url="https://arorarohan.com/posts/20251110-is-pa-pb/ecdf.webp" medium="image" type="image/webp"/>
</item>
<item>
  <title>Common-sense Bayesian A/B Tests are flawed</title>
  <dc:creator>Rohan Arora</dc:creator>
  <link>https://arorarohan.com/posts/20251107-bayesian-ab-1/</link>
  <description><![CDATA[ 





<p><em>Note: This is part 1 of a series of posts I will be writing on Bayesian A/B Testing. This part is about common errors in application of Bayesian inference. The <a href="../../posts/20251112-bayesian-aa-2/index.html">next</a> one will use simulations to illustrate the point.</em></p>
<p><em>Note 2: The statement about having a Type 1 Error Rate of 50% was removed in an edit, but is addressed in a separate post <a href="https://arorarohan.com/posts/20251110-is-pa-pb" title="Is H0: pa=pb same as H0: |pa-pb| =0?">here</a>.</em></p>
<section id="introduction" class="level1">
<h1>Introduction</h1>
<p>It’s a common occurrence in a lot of product experimentation and CRO optimisation to suggest that Bayesian A/B Testing can lead to a reduction in the required sample-size. This is followed by a prompt suggestion to use the beta-binomial model of comparing two independent conversion rates with a prior slapped on. Often this prior is calculated from averaging the historical conversion rate of a metric of interest (KPI) over the last ‘n’ days. We’ll be examining the flaws of this method in details. This is not to say that Bayesian methods are not usable, but rather that they are being applied incorrectly.</p>
</section>
<section id="frequentist-ab-testing-a-quick-recap" class="level1">
<h1>Frequentist A/B Testing: A quick recap</h1>
<p>Please note that this will not be a full recap of the math of a frequentist A/B test. There are enough resources on that on the web. However, I will be taking that up later. We are going to examine the null hypothesis in some detail.</p>
<p>This will also not be a mathematically rigorous derivation of the Average Treatment Effect (ATE). For a detailed view from that perspective, please see this <a href="https://web.stanford.edu/~swager/causal_inf_book.pdf" title="Causal Inference by Stefan Wager, Stanford University">book</a>; refer the chapter on Randomized Control Trials.</p>
<p>Briefly, the null hypothesis for a usual A/B Test is that there is no material difference between conversion rates of two designs, as measured by independent and randomised assignment of users to one of the two designs. Please note two key ideas here:</p>
<ol type="1">
<li><p>The phrase <em>material difference</em> indicates that the observed difference is not large enough. This doesn’t mean that the observed difference has to be zero. It means that the deviation from zero is not sufficient to justify calling out a meaningful difference in conversion rates. For the amount of data collected, the evidence isn’t strong enough to say that the non-zero difference is in-fact attributable to design improvement. The extent of meaningful difference is defined of course by our choice of the ‘minimum detectable effect’.</p></li>
<li><p>Statistically, we are not looking at two separate conversion rates. The <em>statistic under test</em> is the difference (we can also formulate it as a ratio) of the two conversion rates. Mathematically, <img src="https://latex.codecogs.com/png.latex?H_0%20:%20%5Clvert%20p_b-p_a%20%5Crvert%20=%200"> and the statistic under test is <img src="https://latex.codecogs.com/png.latex?%5Clvert%20p_b-p_a%20%5Crvert">. If we assume the statistic under test to be normally distributed, then, under null: <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5Cdelta%7D%20=%20%5Cfrac%7B%5Clvert%5Chat%7Bp_b%7D%20-%20%5Chat%7Bp_a%7D%5Crvert%20%20-%200%7D%7B%5Csqrt%7B%5Cfrac%7B%5Chat%7Bp_a%7D*%5Chat%7Bq_a%7D%7D%7Bn_a%7D%20+%20%5Cfrac%7B%5Chat%7Bp_b%7D*%5Chat%7Bq_b%7D%7D%7Bn_b%7D%7D%7D%20"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?q_i%20=%201%20-%20p_i,%20i%20%5Cin%20%5Ba,b%5D"> and typically, <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bp_b%7D%20=%20%5Chat%7Bp_a%7D*(1+lift_%7Bobserved%7D)">. <strong>𝛿 is a normally distributed random variable,</strong> under the central limit theorem, so long as we collect enough data.</p></li>
</ol>
<p>The ‘hat’ sign here indicates that the rates are estimators of the unobservable underlying conversion rates. We have made no assumptions about the distributions of the conversion rates. More correctly, we can say that <strong>𝛿 hat</strong> represents the expected value of the average treatment effect. Which is a fancy way of saying that under reasonable assumptions, it is an unbiased estimator of observed lift.</p>
<p>The difference is subtle and counter-intuitive but crucial. Combined with the type I error rate, this implies that there is a zone of uncertainty. This is to say that if the observed value of <strong>𝛿</strong> is not sufficiently away from zero, we cannot conclusively say that there is a material difference in performance, or that the observed lift for a given setup of parameters indicates reliable evidence of impact of design (campaign/back-end whatever you are testing) on the conversion rate. Let’s use a visualisation to understand this better.</p>
<p>For simplicity we will assume that we are planning a fixed-sample A/B test and that our planning parameters are as follows: historical rate = 10% (this will substitute for <img src="https://latex.codecogs.com/png.latex?p_a">), MDE = 5%, Type 1 Error Rate = 11%, Power = 90%. We’ll considered a 2-tailed parametric test of proportions. We’ll assume that the split of traffic is even (<img src="https://latex.codecogs.com/png.latex?n_a%20=%20n_b%20=%20n">).</p>
<div class="cell">
<details class="code-fold">
<summary>Show the code</summary>
<div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(plotly)</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(tidyverse)</span>
<span id="cb1-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(ggthemes)</span>
<span id="cb1-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(extrafont)</span>
<span id="cb1-5"></span>
<span id="cb1-6">p1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb1-7">mde <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span></span>
<span id="cb1-8">alpha <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span></span>
<span id="cb1-9">power <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">9</span></span>
<span id="cb1-10"></span>
<span id="cb1-11">p2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>mde)</span>
<span id="cb1-12">q1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> p1</span>
<span id="cb1-13">q2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> p2</span>
<span id="cb1-14"></span>
<span id="cb1-15">n <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">power.prop.test</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p1 =</span> p1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p2 =</span> p2,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sig.level =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">power =</span> power,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alternative =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'two'</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>n</span>
<span id="cb1-16"></span>
<span id="cb1-17">delta_sd <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(p1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q1<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>p2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>q2<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>n)</span>
<span id="cb1-18"></span>
<span id="cb1-19">crit_points <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">qnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> delta_sd, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> alpha<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb1-20"></span>
<span id="cb1-21">crit_lift_bounds <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> crit_points<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>p1</span>
<span id="cb1-22"></span>
<span id="cb1-23">rand_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">density</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rnorm</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mean =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sd =</span> delta_sd, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">^</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>p1,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">from =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">to =</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1024</span>)</span>
<span id="cb1-24"></span>
<span id="cb1-25">dt <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> rand_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> rand_data<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|&gt;</span> </span>
<span id="cb1-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">loc =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">factor</span>(x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span>crit_lift_bounds[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span>crit_lift_bounds[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>],<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordered =</span> F))</span>
<span id="cb1-27"></span>
<span id="cb1-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> dt, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymin =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ymax =</span> y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> loc)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_ribbon</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'black'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_vline</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xintercept =</span> crit_lift_bounds, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lwd=</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geom=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'text'</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>crit_lift_bounds,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Negative Lift</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Detectable'</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Positive Lift</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Detectable'</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hjust =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">annotate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">geom=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'text'</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Inconclusive'</span>,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'white'</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">round</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">05</span>,.<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,crit_lift_bounds),<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-33">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(</span>
<span id="cb1-34">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Zone of uncertainty for an A/B Test"</span>,</span>
<span id="cb1-35">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subtitle =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Base Rate = 10%, MDE = 5%, alpha = 11%, Power = 90%"</span>,</span>
<span id="cb1-36">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">caption =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Note: Plot is under the null hypothesis that a priori expected lift is zero."</span>,</span>
<span id="cb1-37">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Observable Lift"</span>,</span>
<span id="cb1-38">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb1-39">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">parse =</span> T) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_clean</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb1-40">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text=</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">family=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Georgia"</span>),</span>
<span id="cb1-41">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.ticks.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb1-42">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">axis.text.y =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element_blank</span>(),</span>
<span id="cb1-43">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend.position=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'none'</span>)</span></code></pre></div>
</details>
<div class="cell-output-display">
<div>
<figure class="figure">
<p><img src="https://arorarohan.com/posts/20251107-bayesian-ab-1/index_files/figure-html/plot-001-1.png" class="img-fluid figure-img" width="672"></p>
</figure>
</div>
</div>
</div>
<p>From the chart above we can observe that when attempting to establish a meaningful difference in lift for an A/B Test, it has to be above/below a certain threshold, i.e.&nbsp;in the red shaded area on the x-axis. The area indicates the probability of lift being on that zone of the x-axis.</p>
<p>This long winded recap was to point out a critical flaw in the way a lot of people misinterpret A/B tests: <em>a non</em>-<em>zero value doesn’t automatically mean that a lift is statistically significant</em> (for a given sample-size determined by the chosen power threshold). It’s also not about claiming that the magnitude of change is ineffectual. It’s about saying that given the amount of data I have, I cannot be reasonably certain that this non-zero observed lift is not a fluke event.</p>
<p>I should also point out how many people misinterpret the null hypothesis when expressed as <img src="https://latex.codecogs.com/png.latex?H_0%20:%20p_b%20=%20p_a">, either implicitly running a 1-tailed Bayesian test or causing a set-up where an effect is always present.</p>
<p>Essentially, if the only time the null is rejected is when the two random variables are equal, the zone of uncertainty vanishes.</p>
<p>Yet, this is a common error in how Bayesian A/B Tests are interpreted! We look at this error in decision rule in this <a href="https://arorarohan.com/posts/20251110-is-pa-pb/" title="Is H0: pa=pb same as H0: |pa-pb| =0?">post</a>. The more common error is that often Bayesian A/B Tests are implicitly run for a 1-tailed comparison and then compared to a 2-tailed test of proportions.</p>
<p>Let me reiterate that I am not insisting that Bayesian inference methodologies are meaningless. I am in fact a proponent of Bayesian inference so long as you have useful prior information that can be correctly encoded in the estimators. I am critical of a common implementation that is incorrect.</p>
<p>And this takes us into the next section.</p>
</section>
<section id="the-bias-variance-trade-off" class="level1">
<h1>The Bias-Variance Trade-off</h1>
<p>In my view, the prior information can be looked at as a bias-variance trade-off. Adding prior information essentially adds information, i.e.&nbsp;bias. We can also reasonably say that collecting data is essentially about increasing the amount of available information. Adding a bias helps us get away with collecting less data. Or more correctly in the case of Bayesian estimation, using prior information to augment currently collected data helps us be less uncertain.</p>
<p>However, this certainty comes at the cost of either amplifying the new results or dampening them (positive or negative bias). Assuming the same prior performance for both designs is a reasonable assumption but it also means that we are dampening the nature of the new data collected in an A/B test. This is almost always a good thing however, as Bayesian A/B testing is most often used in scenarios where currently collected data-points are somewhat insufficient.</p>
<p>There is therefore no free lunch, a really strong prior can bias the results towards a non-zero lift and drown out any contrary evidence from new data, or over-amplify it and lead to an incorrect decision.</p>
<p>Our aim in Bayesian methodologies is to choose a reasonably informative prior and therefore make a reliable bias-variance trade-off.</p>
</section>
<section id="bayesian-ab-testing-the-flawed-way" class="level1">
<h1>Bayesian A/B Testing: The flawed way</h1>
<section id="the-mathematical-model-independent-beta-estimation-hoffmann2022" class="level2">
<h2 class="anchored" data-anchor-id="the-mathematical-model-independent-beta-estimation-hoffmann2022">The mathematical model: Independent Beta Estimation <span class="citation" data-cites="hoffmann2022">(Hoffmann, Hofman, and Wagenmakers 2022)</span></h2>
<p>I’ll try to limit the amount of time spent of theory. For a detailed view, please check the citation above or this <a href="https://meth.psychopen.eu/index.php/meth/article/download/9263/9263.html?inline=1" title="Bayesian Tests of Two Proportions: A Tutorial With R and JASP">link</a> by the same authors.</p>
<p>Briefly,</p>
<ol type="1">
<li>It is assumed that <em>n<sub>A</sub></em> and <em>n<sub>B</sub></em> samples are collected for the two designs A and B respectively, with successful conversion denoted as <em>y<sub>A</sub></em> and <em>y<sub>B</sub></em> .</li>
<li><em>y<sub>A</sub></em> and <em>y<sub>B</sub></em> are assumed to be binomially distributed, with respective underlying (successful) conversion rate parameters as θ<sub>A</sub> and θ<sub>B.</sub></li>
<li>θ<sub>A</sub> and θ<sub>B</sub> are assumed to be independently beta distributed (<a href="https://en.wikipedia.org/wiki/Beta_distribution" title="Beta Distribution">Beta Distribution</a>), with their individual hyperparameters 𝛂 and 𝛃. They can be interpreted as counts of hypothetical ‘𝛂’ successes from a total of ‘𝛂+𝛃’ data points.</li>
</ol>
<p>The choice of beta dsitribution is useful as it is the conjugate prior of the binomial distribution. In lay person terms, it allows the posterior estimation of conversion rates of designs A and B to follow a Beta distribution as well! Posterior rates are essentially <img src="https://latex.codecogs.com/png.latex?Beta(y_i+%F0%9D%9B%82_i%20,%20(n_i-y_i)+%F0%9D%9B%83_i)"> where <em>i</em> is A or B. Neat!</p>
<p>For a more detailed explanation on conjugate priors in Bayesian estimators, please check out this excellent <a href="https://randomservices.org/random/point/Bayes.html" title="Bayesian Point Estimation, Randomservices.org">website</a>. I can’t recommend it enough, it has collected all key ideas of probability and statistics in one place.</p>
<p>To summarise, <img src="https://latex.codecogs.com/png.latex?y_A%E2%88%BCBinomial(n_A,%CE%B8_A)"></p>
<p><img src="https://latex.codecogs.com/png.latex?y_B%E2%88%BCBinomial(n_B,%CE%B8_B)"> <img src="https://latex.codecogs.com/png.latex?%5Ctheta_A%E2%88%BCBeta(%CE%B1_A,%CE%B2_A)%20"></p>
<p><img src="https://latex.codecogs.com/png.latex?%5Ctheta_B%E2%88%BCBeta(%CE%B1_B,%CE%B2_B)%20"></p>
<p><img src="https://latex.codecogs.com/png.latex?p(%5Ctheta_A%7Cy_A,n_A)%20=%20%5Cfrac%7Bp(%5Ctheta_A)*p(y_A,n_A%7C%5Ctheta_A)%7D%7Bp(y_A,n_A)%7D"></p>
<p><img src="https://latex.codecogs.com/png.latex?p(%5Ctheta_B%7Cy_B,n_B)%20=%20%5Cfrac%7Bp(%5Ctheta_B)*p(y_B,n_B%7C%5Ctheta_B)%7D%7Bp(y_B,n_B)%7D"></p>
<p>These last equations simplify as follows:</p>
<p><img src="https://latex.codecogs.com/png.latex?p(%5Ctheta_A%7Cy_A,n_A)%20=%20Beta(y_A%20+%20%CE%B1_A,(n_A%20-%20y_A)%20+%20%CE%B2_A)"></p>
<p><img src="https://latex.codecogs.com/png.latex?p(%5Ctheta_B%7Cy_B,n_B)%20=%20Beta(y_B%20+%20%CE%B1_B,(n_B%20-%20y_B)%20+%20%CE%B2_B)"></p>
<p>Generally, we also assume that 𝛂<sub>A</sub> = 𝛂<sub>B</sub> = 𝛂 and 𝛃<sub>A</sub> = 𝛃<sub>B</sub> = 𝛃. This is like saying that the prior for both designs is the same.</p>
<p>This itself is a hint that things are a bit off. Why would I need to explicitly define two priors and then state that they are the same?</p>
<p>If you have been able to follow along so far, you’ll see that the problem is obvious. Earlier we were dealing with modelling a difference in rate or a lift. Now, we are modelling two independent rates. A more accurate Bayesian model would define a prior on the lift itself. Fortunately, some experimentation SaaS vendors out there implement precisely such a model. But we’ll leave that for subsequent posts.</p>
<p>Referring to the paper cited earlier, we’ll look at two key assumptions of this model.</p>
<p>The first assumption is the independence of success probabilities: learning about design A tells us nothing about design B. In practice, this assumption is rarely valid. Unless something is terribly off, if the conversion rate of design A (historical design) is around 10%, it is unlikely that conversion rate of design B is beyond the range of 8 to 12%. And i would be damned if it were in the range of 80 to 90%.</p>
<p>When defining an MDE or lift in the frequentist approach, we are placing an expectation on the difference in conversion rates from a common baseline. Yet somehow this isn’t the case in this model. This isn’t particularly problematic, as we can very easily use the same prior for both designs. But how do we place a prior on our expectation of there being some difference in the conversion rates of two designs if we set the two hyperparameters of the prior to be equal? There is no reason why we can’t have an expectation on the range of the possible lifts even if <em>a priori</em> we may expect its median value to be 0.</p>
<p>This too happens implicitly. When modeling the ratio or difference of these priors, the choice of 𝛂<sub>A</sub> = 𝛂<sub>B</sub> = 𝛂 and 𝛃<sub>A</sub> = 𝛃<sub>B</sub> = 𝛃 implicitly defines the median difference to be zero and imposes a certain ‘most probable’ range for the <em>a priori</em> lift.</p>
<p>This isn’t exactly a very stellar way of approaching an A/B test where after all the aim is to establish a post-experiment non-zero lift.</p>
<p>The other key assumption is that an effect is always present, that is one of design A or B is always better and there is never a situation where the evidence is inconclusive. This assumption follows from the fact that we aren’t able to assign some prior probability to a specific point-value such as 𝝳 = 0. In fact, we didn’t define a hypothesis test anywhere.</p>
<p>In practice, practitioners and proponents often draw posterior draws from the two independent distributions, take their ratio as a derived empirical random variable, and then check to see how often the ratio is greater than one (i.e.&nbsp;how often the conversion rate of design B is better than that of historical design A). This is essentially an implicit inflation of the type 1 error rate. This is what leads to a reduction in required sample-size w.r.t. 2-sample test of proportions, or equivalently, a viable but unreliable decision from insufficient data.</p>
<p>It biases the model to detect effects and fails to place appropriate weight on no effect being present.</p>
<p>With an uninformative prior combined with an appropriate decision boundary, this is the same as running a 2-sample test of proportions. So why even bother with a Bayesian method? Clearly, we must use a different Bayesian model that is an improvement over the classical A/B test.</p>
</section>
<section id="thanks-but-my-brain-hurts-can-you-show-this-through-code-and-visualisations" class="level2">
<h2 class="anchored" data-anchor-id="thanks-but-my-brain-hurts-can-you-show-this-through-code-and-visualisations">Thanks, but my brain hurts, can you show this through code and visualisations?</h2>
<p>That is exactly what I have done in the next post. You can check it <a href="../../posts/20251112-bayesian-aa-2/index.html" title="Examining assumptions of IBE model using A/A Tests.">here</a>.</p>
<p>For a head-start on how the IBE methodology is usually applied, you can refer this <a href="https://www.countbayesie.com/blog/2015/4/25/bayesian-ab-testing" title="bayesian AB Testing, Will Kurt, Countbayesie.com">post</a> by Will Kurt on his blog countbayesie.com.</p>
<p>For my gripes with flaws in the aforementioned methodology, refer <a href="https://arorarohan.com/posts/20251110-is-pa-pb" title="Is H0: pa=pb same as H0: |pa-pb| =0?"><em>here</em></a><em>.</em></p>



</section>
</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-hoffmann2022" class="csl-entry">
Hoffmann, Tabea, Abe Hofman, and Eric-Jan Wagenmakers. 2022. <span>“Bayesian Tests of Two Proportions: A Tutorial with r and JASP.”</span> <em>Methodology</em> 18 (4): 239–77. <a href="https://doi.org/10.5964/meth.9263">https://doi.org/10.5964/meth.9263</a>.
</div>
</div></section></div> ]]></description>
  <category>Product</category>
  <category>Experimentation</category>
  <category>AB Testing</category>
  <category>Bayesian</category>
  <category>Causal Inference</category>
  <guid>https://arorarohan.com/posts/20251107-bayesian-ab-1/</guid>
  <pubDate>Fri, 07 Nov 2025 22:00:00 GMT</pubDate>
  <media:content url="https://arorarohan.com/posts/20251107-bayesian-ab-1/bayesian.png" medium="image" type="image/png" height="60" width="144"/>
</item>
<item>
  <title>Building a rudimentary website with AI</title>
  <dc:creator>Rohan Arora</dc:creator>
  <link>https://arorarohan.com/posts/20251101-vibe-ai-website/</link>
  <description><![CDATA[ 





<p>It wasn’t always my plan to jump on to the current AI (or LLM) driven development or vibe-coding. But at some point my curiosity got the better of me and I wanted to see for myself what all the fuss on Linkedin was about.</p>
<p>While attending some professional events in Helsinki, I came across a presentation by someone on how they had built entire projects using Lovable and so I decided to give it a try. My agenda was to build a website for my newly established <a href="https://deestande.com">company</a> as a proof of concept. Additionally, I was aiming to have something portable that did not force me to get stuck with a hosting platform.</p>
<p>Here’s what i learnt.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://arorarohan.com/posts/20251101-vibe-ai-website/lovable.png" class="img-fluid figure-img"></p>
<figcaption>Lovable.dev</figcaption>
</figure>
</div>
<section id="the-process" class="level3">
<h3 class="anchored" data-anchor-id="the-process">The Process</h3>
<p>Since I have little to no experience building websites using modern Javascript/Typescript frameworks (although I can code in JS), I was almost completely reliant on Lovable getting the design patterns and architecture right. For a small website this isn’t necessarily a problem. There were a few key steps though.</p>
<ol type="1">
<li>An AI assistant drafts the prompt for Lovable. I used MS Copilot as i have a subscription. I instructed it to generate a prompt for Lovable in markdown as per my requirements.</li>
<li>Use the prompt in Lovable. It was fairly straightforward. Lovable generated the first draft and also some output in the chat window around the tech-stack decisions, theme and content choices and so forth.</li>
<li>Connecting with Github. After the first draft, the content was not as expected and it didn’t feel quite useful to have Lovable edit everything, not the least because there are limited free credits in the <em>gratis</em> account tier. I decided that this was a good opportunity to re-learn version control - something I hadn’t used in a few years. So I connected my project with my github and it was farily seamless in Lovable.</li>
<li>More github. I decided to create two branches from the master repo: one for Lovable and one for the edits that I made directly. This would allow me to revert changes if things went south. I used the Lovable branch for more involved tech changes, including writing a PHP script for connecting the contact form to the backend MySQL database on Hostinger platform. I kept my branch almost solely for content and design changes.</li>
<li>Upload the generated files to Hostinger. Generating the output was quite painless as well thanks to npm. Lovable generated an easy-to-follow <em>Readme.md</em> file that helped a lot.</li>
<li>Some modifications to the footer by prompting Lovable.</li>
<li>Connect the domain, test everything manually. I had to make sure that the contact submission form was working as expected.</li>
</ol>
<p><strong>And that was that, the website was live in about 20 hours of work.</strong></p>
</section>
<section id="what-i-learnt" class="level3">
<h3 class="anchored" data-anchor-id="what-i-learnt">What I learnt</h3>
<p>The overall process creates an illusion of fluidity and error-free development. However, the chickens can quickly come home to roost if you aren’t on top of the source-code and perform an audit. This style of development works satisfactorily for small-scale projects and rapid prototyping but I would be skeptical of how well it can function out of the box for more complex products.</p>
<p>With some experience in developing websites for pocket money back when I was a master’s student, there was some latent know-how on how to set things up and I had an experienced full-stack developer to lean on for advice. But i don’t think vibe-coding can completely replace experienced developers.</p>
<p>As an example, the PHP script that connects with the backend has to be written pretty defensively to prevent hacking attempts. Lovable also did not include any tests and didn’t automatically build a CI/CD pipeline. If you are not at least cursorily aware of these crucial best practices, the likelihood of building a project that works until it doesn’t remains substantial.</p>
<p>And I certainly wouldn’t launch something mission critical without an extensive audit with the help of seasoned professionals.</p>
<p>That said, not having to write boilerplate code and minutely worry about each and every transition, design and style element was a relief.</p>
</section>
<section id="next-steps" class="level3">
<h3 class="anchored" data-anchor-id="next-steps">Next Steps</h3>
<p>Since this is still more of a proof of concept project, I am leveraging it to improve my understanding of modern web interfaces and design patterns. I explicitly introduced tests by prompting Lovable and also used it to incorporate a CI/CD pipeline.</p>
<p>But once you get down this rabbit hole, there are other things that come to the fore. For example, your development environment needs to be set up for the tests to run, mimicking the functionality of the backend database.</p>
</section>
<section id="section" class="level3">
<h3 class="anchored" data-anchor-id="section">…</h3>
<p>All in all, there have been important learnings and it’s been a fun-ride so far. My future intention is to use more of these tools to improve my skills but marry my enthusiasm with a healthy dose of caution.</p>
<p>As regards to my business prospects, well it’s been a rough beginning. <em>C’est la vie.</em></p>
<p>Hey, at least I got a blog post out of it!</p>


</section>

 ]]></description>
  <category>AI</category>
  <category>vibe-coding</category>
  <guid>https://arorarohan.com/posts/20251101-vibe-ai-website/</guid>
  <pubDate>Sun, 02 Nov 2025 22:00:00 GMT</pubDate>
  <media:content url="https://arorarohan.com/posts/20251101-vibe-ai-website/hero.jpg" medium="image" type="image/jpeg"/>
</item>
</channel>
</rss>
