<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/from-power-calculations-to-p-values-ab-testing-at-stack-overflow/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://juliasilge.com/blog/ab-testing/"> Rstats on Julia Silge</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><em>Note: cross-posted <a rel="nofollow" href="https://stackoverflow.blog/2017/10/17/power-calculations-p-values-ab-testing-stack-overflow/" target="_blank">with the Stack Overflow blog</a>.</em></p>
<p>If you hang out on <a rel="nofollow" href="https://stackoverflow.com/help/whats-meta" target="_blank">Meta Stack Overflow</a>, you may have noticed news from time to time about <a rel="nofollow" href="https://meta.stackoverflow.com/questions/337745/were-soon-to-be-a-b-testing-some-changes-to-the-top-nav" target="_blank">A/B tests of various features</a> here at Stack Overflow. We use A/B testing to compare a new version to a baseline for a design, a machine learning model, or practically any feature of what we do here at Stack Overflow; these tests are part of our decision-making process. Which version of a button, predictive model, or ad is better? We don’t have to guess blindly, but instead we can use tests as part of our decision-making toolkit.</p>
<p>I get excited about A/B tests because tests like these harness the power of statistics and data to impact the day-to-day details of our business choices. Des Navadeh is the product manager of the <a rel="nofollow" href="https://stackoverflow.com/jobs" target="_blank">Jobs</a> team here at Stack Overflow, and she has used testing extensively on her team to guide decisions. Des says, “A/B testing helps us gain confidence in the change we’re making. It helps us validate new ideas and guides decision making. Without A/B testing, we’re leaving much of what we do up to chance.”</p>
<p>At the same time, there can be confusion about how to approach an A/B test, what the statistical concepts involved in such a test are, and what you do <em>before</em> a test vs. <em>after</em> a test. Des and her team have learned a lot by implementing many tests, but also have had some stumbles. “We didn’t realize it at the time, but when we started A/B testing, we took a very strict approach in the calculations to determine sample size. As a result, we were running tests for an unnecessary length of time and most were deemed inconclusive. We basically set up our tests to be almost 100% confident which isn’t very realistic or productive!” Des says.</p>
<p>To start testing off on the right foot, we need to plan for an A/B test and perform a power calculation. This requires defining a hypothesis and test groups, and then considering two questions.</p>
<ul>
<li>How sure do we need to be that we are measuring a real change?</li>
<li>How big is the change we expect to see because of the new version, compared to the baseline?</li>
</ul>
<p>Let’s start with the first question.</p>
<div>
<h2>How sure do you need to be?</h2>
<p>I am sad to have to break this to you all, but the answer to that first question can’t be 100%. When we measure something in the real world, we never measure with exact accuracy and precision. (That’s basically why I have a job, I think!) There are two main quantities that statisticians use to talk about how much and in what way we can be wrong in measuring.</p>
<ul>
<li>What percentage of the time are we willing to miss a real effect? This is measured by <strong>power</strong>.</li>
<li>What percentage of the time are we willing to be fooled into seeing an effect by random chance? This is called <strong>significance level</strong>, and more precisely, we would state this as the probability of rejecting the <a rel="nofollow" href="https://stats.stackexchange.com/questions/85903/why-do-statisticians-say-a-non-significant-result-means-you-cant-reject-the-nu" target="_blank">null hypothesis</a>.</li>
</ul>
<p>We also talk about these kinds of errors as the false negative rate and false positive rate, which can be <a rel="nofollow" href="https://flowingdata.com/2014/05/09/type-i-and-ii-errors-simplified/" target="_blank">very easy to understand given the right example</a>.</p>
<p>Typical statistical standards for these quantities are 80% for power (i.e., 20% chance of a false negative) and 5% for significance level. Why are these standards used in practice? That’s a great question with a fair amount of baggage and tradition behind it. If we choose standards that are too strict, perhaps 95% for power and 1% for significance level, all our A/B tests will need to run longer and we will have to invest more time and resources into testing. We won’t be able to iterate quickly to solve our business problems. On the other hand, we’re not curing cancer here, right?! What if we relaxed these statistical standards? Then we risk making change after change in our product that does not improve anything, and investing work from our developers and other team members in changes that do not move us forward toward our goals. We want to be Goldilocks-just-right when it comes to these standards for our purposes. For us at Stack Overflow, that means consistently using 80% for power and 5% for significance level in our power calculations before an A/B test.</p>
</div>
<div>
<h2>How big is your change?</h2>
<p>Our second question here is not about statistical standards, but instead is about how big of a difference we expect to see with the proposed change compared to the status quo. Some phrases that people use to talk about this concept are effect size, expected improvement, and improvement threshold. Effect size can be different in different contexts and different parts of our business.</p>
<p>Estimating effect size requires strategic product thinking. Des says, “You need to first understand how different areas of your product perform. Understanding how each part of your funnel converts today helps you decide how big of an effect you’d need to see for the new change to be worth it. We use different questions to help estimate the effect size. How much development work is required to graduate the test? How strategically important is it? Does this feature support future plans? What is the size of audience or action are we optimizing for? These answers are detailed as success criteria in our test plans.” Some of the factors Des takes into account when estimating effect size are volume of events that enter the funnel that is being considered, baseline conversion rate of the feature, and how the expected improvement impacts overall product metrics.</p>
</div>
<div>
<h2>Power calculations</h2>
<p>Once we have estimated an effect size for our test and know the statistical standards we are going to use in planning, we can do a power calculation to find out how big of a sample size we need for our test. The point of power calculations like these is to find out what sample size we need for our A/B test, how many views or users or form submissions or other interactions we need in each group to achieve the necessary power for our test. Then we can finally start our test! Time to wait for those events to roll in.</p>
<p>How do we calculate how big of a sample we need, to measure the change we expect with the statistical standards we’ve chosen? For most tests, our product teams use online calculators to find the sample size. I’m an R developer, so I would use a <a rel="nofollow" href="https://stat.ethz.ch/R-manual/R-devel/library/stats/html/power.prop.test.html" target="_blank">function in R</a> for such a test. For more complicated tests, we on the data team sometimes run simulations for power calculations.</p>
<p>When we calculate power, we see first-hand how power, significance level, and effect size interact with sample size and the baseline conversion rate that we were dealing with to start with. I built a <a rel="nofollow" href="https://juliasilge.shinyapps.io/power-app/" target="_blank">Shiny app</a> to demonstrate how these factors are related for a proportion test, which is typically applicable in our A/B tests.</p>
<p><a rel="nofollow" href="https://juliasilge.shinyapps.io/power-app/" target="_blank"><img src="https://i0.wp.com/juliasilge.com/figs/2017-10-17-ab-testing/app_screenshot.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<p>You can click the “Source Code” button on the app to see the R code that built this app. Notice the shapes of the curves, and how they change when you move the sliders. We need bigger sample sizes to measure small effect sizes, or to achieve low significance levels. If the baseline rate is higher to start with, the sample size needed for a given power goes down. These complicated interactions affect our A/B tests at Stack Overflow.</p>
<p>“We realized that we couldn’t standardize power calculations across all tests. Some parts of our funnel were highly optimized and converted well, which meant we needed smaller samples sizes to detect the same effect we would want to see in an area that didn’t convert as well,” Des says. “Other areas had higher volume, like page views, but did not convert at well. While higher volume helps us reach the sample size need faster, we needed a larger effect size for the change to make an impact.”</p>
</div>
<div>
<h2>Analyzing results</h2>
<p>What happens after the test? After we have collected enough events to meet our sample size requirements, it’s time to analyze the results. At Stack Overflow, we have testing infrastructure for teams to automatically see analysis of results, or if I am performing an analysis myself, I might use a statistical test like a <a rel="nofollow" href="https://stat.ethz.ch/R-manual/R-devel/library/stats/html/prop.test.html" target="_blank">proportion test using R</a>. “We know we can end a test when we’ve reached the sample size we set out to collect, and then we check out the p-value,” Des says. The p-value of an A/B test is the probability that we would get the observed difference between the A and B groups (or a more extreme difference) by random chance. When the p-value is high, that means the probability that we could just randomly see that difference between the A and B groups is high, due only to sampling noise. When the p-value of our A/B test is low enough (below our threshold), we can say that the probability of seeing such a difference randomly is low and we can feel confident about making the change to the new alternative from our original version.</p>
<p>If you pay attention to the world of statistics, you may have seen some hubbub about changing the threshold for p-values; a <a rel="nofollow" href="https://cos.io/blog/we-should-redefine-statistical-significance/" target="_blank">recent paper claimed that moving from a threshold of 0.05 to 0.005</a> would solve the reproducibility crisis in science and fix, well, lots of things. It’s true that using a threshold of p &lt; 0.05 means being <a rel="nofollow" href="https://xkcd.com/882/" target="_blank">fooled 1 in 20 times</a>, but ultimately, the problem with using statistics and measurement isn’t p-values. <a rel="nofollow" href="https://twitter.com/thosjleeper/status/888806305103785985" target="_blank">The problem is us.</a> We can’t apply these kinds of thresholds without careful consideration of context and domain knowledge, and a commitment to honesty (especially to ourselves!) when it comes to p-values. We are sticking with a p-value threshold of 0.05 for our A/B tests, but these tests must always be interpreted holistically by human beings with an understanding of our data and our business.</p>
</div>
<div>
<h2>When to JUST SAY NO to an A/B test</h2>
<p>Tests like the ones Des and I have talked about in this post are a powerful tool, but sometimes the best choice is knowing when not to run an A/B test. We at Stack Overflow have encountered this situation when considering a feature used by a small number of users and a potential change to that feature that we have other reasons for preferring to the status quo. The length of a test needed to achieve adequate statistical power in such a situation is impractically long, and the best choice for us in our real-life situation is to forgo a test and make the decision based on non-statistical considerations.</p>
<p>“Product thinking is critical here. Sometimes a change is obviously better UX but the test would take months to be statistically significant. If we are confident that the change aligns with our product strategy and creates a better experience for users, we may forgo an A/B test. In these cases, we may take qualitative approaches to validate ideas such as running usability tests or user interviews to get feedback from users,” says Des. “It’s a judgement call. If A/B tests aren’t practical for a given situation, we’ll use another tool in the toolbox to make progress. Our goal is continuous improvement of the product. In many cases, A/B testing is just one part of our approach to validating a change.”</p>
<p>Along the same lines, sometimes the results of an A/B test can be inconclusive, with no measurable difference between the baseline and new version, either positive or negative. What should we do then? Often we stay with the original version of our feature, but in some situations, we still decide to make a change to a new version, depending on other product considerations.</p>
<p>Dealing with data means becoming comfortable with uncertainty, and A/B tests make this reality extremely apparent. Handling uncertainty wisely and using statistical tools like A/B tests well can give us the ability to make better decisions. Des and her team have used extensive testing to make <a rel="nofollow" href="https://stackoverflow.com/jobs" target="_blank">Stack Overflow Jobs</a> a great tool for developers in the market for a new opportunity, so be sure to check it out!</p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://juliasilge.com/blog/ab-testing/"> Rstats on Julia Silge</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/AlAAGMmt5gU" height="1"></a></div>