6 ms·
Show HN: Tea-tasting, a Python package for the statistical analysis of A/B tests
I'm excited to introduce tea-tasting, a Python package for the statistical analysis of A/B tests
It features Student's t-test, Bootstrap, variance reduction using CUPED, power analysis, and other statistical methods.
tea-tasting supports a wide range of data backends, including BigQuery, ClickHouse, PostgreSQL, Snowflake, Spark, and more, all thanks to Ibis.
I consider it ready for important tasks and use it for the analysis of switchback experiments in my work.
- nrjames 2y agoThis is awesome and very useful. Thanks!
- prashp 2y agoIt's called tea-tasting but doesn't include Fisher's exact test :( https://en.wikipedia.org/wiki/Fisher%27s_exact_test?useskin=vector#Purpose_and_scope https://en.wikipedia.org/wiki/Fisher%27s_exact_test?useskin=...
- deleted 2y ago[deleted]
- e10v_me 2y agoYeah, I know :) But it's in the roadmap. Btw, aren't Barnard's test or Boschloo's test better alternatives?
- deugtniet 2y agoI guess I'm not very versed in website A/B testing, but wouldn't it be much better to analyze these results in a regression framework where you can correct for the covariates? On top of this, logistic regression makes your units a lot more interpretable than just looking at differences in means. I.E. The odds of buying something are 1.1 when you are assigned in group B.
- e10v_me 2y agoThank you for the interest and for the suggestion. Yes, one can analyze A/B tests in a regression framework. In fact, CUPED is an equivalent to the linear regression with a single covariate. Would it be better? It depends on the definition of "better". There are several factors to consider. Scientific rigor is one of them. So is the computational efficiency. A/B tests are usually conducted at scale of thousands of randomization units (actually it's more like tens or hundreds of thousands). There are two consequences: 1. Computational efficiency is very important, especially if we take into account the number of experiments and the number of metrics. And pulling granular data into a Python environment and fitting a regression is much less efficient than calculating aggregated statistics like mean and variance. 2. I didn't check, but I'm pretty sure that, at such scale, logistic and linear regressions' results will be very close, if not equal. And even if, for some reason, there is a real need to analyze a test using logistic model, multi-level model, or a clustered error, in tea-tasting, it's possible via custom metrics: https://tea-tasting.e10v.me/custom-metrics/ https://tea-tasting.e10v.me/custom-metrics/
- crystal_revenge 2y ago> And pulling granular data into a Python environment and fitting a regression is much less efficient than calculating aggregated statistics like mean and variance. This is not true. You almost never need to perform logistic regression on individual observations. Consider that estimating a single Bernoulli rv on N observations is the same as estimate a single Binomial rv for k/N. Most common statistical software (e.g. statsmodels) will support this grouped format. If all of our covariates a discrete categories (which is typically the case for A/B tests) then you only need to regression on the number of examples equal to the number of unique configurations of the variables. That is if you're running an A/B test on 10 million users across 50 states and 2 variants you only need 100 observations for your final model.
- e10v_me 2y ago> Most common statistical software (e.g. statsmodels) will support this grouped format. Interesting, I didn't know this about statsmodels. But maybe documentation a bit misleading: "A nobs x k array where nobs is the number of observations and k is the number of regressors". Source: https://www.statsmodels.org/stable/generated/statsmodels.genmod.generalized_linear_model.GLM.html#statsmodels.genmod.generalized_linear_model.GLM https://www.statsmodels.org/stable/generated/statsmodels.gen... I would be grateful for the references on how to apply statsmodels for solving logistic model using only aggregated statistics. Or not statsmodels. Any references will do.
- thegginthesky 2y agoGreat package! I'll test it out on my free time. I'm wondering if you'd like to accept a contribution for Bayesian AB Testing, based on this whitepaper[0] and developed in Numpy. If so, we can chat at my email gbenatt92 at zohomail dot com, or I can open a draft PR to discuss the code and paper. [0]https://vwo.com/downloads/VWO_SmartStats_technical_whitepaper.pdf https://vwo.com/downloads/VWO_SmartStats_technical_whitepape...
- e10v_me 2y agoThank you! I hope it will be useful for you. Regarding your question, first, I'd like to understand what problem you want to solve, and whether this approach will be useful for other users of tea-tasting.
- thegginthesky 2y agoNo problem! I have most of the code in very small functions that I'd be willing to contribute. At my company we have very time sensitive AB tests that we have to run with very few data points (at most 20 conversions per week, after 1000 or so failures). We found out that using Bayesian A/B testing was excellent for our needs as it could be run with fewer data points than regular AB for the sort of conversion changes we aim for. It gives a probability of group B converting better than A, and we can run checks to see if we should stop the test. Regular ABs would take too long and the significance of the test wouldnt make much sense because after a few weeks we would be comparing apples to oranges.
- e10v_me 2y agoThank you for explanation. If I understand correctly, you use this approach to increase sensitivity (compared to NHST) using the same data. Most probably, in your case, higher sensitivity (or power) comes at the cost of higher type I error rate. And this might be fine. Sometimes making more changes and faster is more important than false positives. In this case, you can just use a higher p-value threshold in the NHST framework. You might argue that the discrete type I error does not concern you. And that the potential loss in metric value is what matters. This might be true in your setting. But in real life scenarios, in most cases, there are additional costs that are not taken into account in the proposed solution: increased complexity, more time spent on development, implementation, and maintenance. I suggest reading this old post by David Robinson: https://varianceexplained.org/r/bayesian-ab-testing/ https://varianceexplained.org/r/bayesian-ab-testing/ While the approach might fit in your setting, I don't believe most of other users of tea-tasting would benefit from it. For the moment, I must decline your kind contribution. But you still can use tea-tasting and perform the calculations described in the whitepaper. See the guide on how to define a custom metric with a statistical test of your choice: https://tea-tasting.e10v.me/custom-metrics/ https://tea-tasting.e10v.me/custom-metrics/
- NightMKoder 2y agoWould be great if it included sequential sampling as well: https://www.evanmiller.org/ab-testing/sequential.html https://www.evanmiller.org/ab-testing/sequential.html . Especially given how A/B tests usually get run in product companies, a peek proof method helps quite a bit.
- e10v_me 2y agoI will consider it. Thank you for the suggestion.
- 0cf8612b2e1e 2y agoWhat is a good resource for someone looking to learn more about A/B testing? Not specifically about website dark pattern optimization, but fine if that is the framing device.
- teej 2y agoI recommend “Trustworthy Online Controlled Experiments”. If you’re only going to read one book about it, it should be this one. It will walk you through why we experiment, how it’s typically done, and how to use them to improve your decision making.
- e10v_me 2y agoAgree. I also suggest looking at Alex Deng's unfinished book on causal inference and, particularly, A/B testing: https://alexdeng.github.io/causal/ https://alexdeng.github.io/causal/ Alex Deng worked with Ron Kohavi at Microsoft Analysis and Experimentation Team and co-autored many important papers on the topic, including paper about CUPED.
- crimsoneer 2y agoGoes way beyond t-tests, but I really like this free online book on causal inference more broadly https://matheusfacure.github.io/python-causality-handbook/landing-page.html https://matheusfacure.github.io/python-causality-handbook/la...
- deleted 2y ago[deleted]
- cschmidt 2y agoIt would probably be good to have something considering multiple comparisons (False Discovery Rate, Bonferroni correction), which is often the bane of running a whole series of A/B tests. And, as another poster has mentioned, an anytime approach that is resistant to early stopping due to peaking [1]. For those who haven't read about Fisher's tea experiment: There was a woman who claimed she could tell if the milk was put into the cup before or after pouring the tea. Fished didn't think so, and developed the experimental technique to test this idea. Indeed she could, getting them all right iirc. [1] see https://media.trustradius.com/product-downloadables/UP/GB/ADQZKJ2UQP7H.pdf https://media.trustradius.com/product-downloadables/UP/GB/AD... for a discussion of the problems with a t-test. There is also a more detailed whitepaper from Optimizely somewhere
- welder 2y agoAnd the Student's t-test which was named so because William Sealy Gosset's employer (Guinness beer) allowed him to publish it anonymously, so he published using the pseudonym "Student".
- gatopingado 2y agoFor anyone interested in anytime-valid testing, I wrote a Python library [1] implementing multinomial and time inhomogeneous Bernoulli / Poisson process tests based in [2]. [1] https://github.com/assuncaolfi/savvi/ https://github.com/assuncaolfi/savvi/ [2] https://openreview.net/forum?id=a4zg0jiuVi https://openreview.net/forum?id=a4zg0jiuVi
- e10v_me 2y agoI thought about multiple comparison corrections. Here what my thoughts were: 1. Experiments with 3 or more variants are quite rare in my practice. I usually try to avoid them. 2. In my opinion, the Bonferroni correction is just wrong. It's too pessimistic. There are better methods though. 3. The choice of alpha is subjective. Why use a precise smart method to adjust a subjective parameter? Just choose another subjective alpha, a smaller one :) But I can change my opinion if I see a good argument.
- 2y ago
- asdasdsddd 2y agoImo, with a/b tests, its really easy to get sucked into the 30 different analysis algos, but the most important thing by far is experiment hygiene
- welder 2y agoAnd knowing beforehand when you won't get enough exposures to reach significance. Not many people have enough traffic to A/B test small effects and reach significance without running the test for multiple years. I don't use CUPED in my tests... how much can it reduce wait times?
- asdasdsddd 2y agoI don't think CUPED is super useful if you just stratify your users properly before the experiment begins.
- e10v_me 2y agoCUPED is easier than stratifying users. Or, probably, you mean post-stratification. Still, CUPED is easier, on my personal opinion :)
- crystal_revenge 2y agoStrictly speaking you don't need to wait for some arbitrary significance threshold. I don't know why so many people treat website A/B tests as similar to carefully, traditional nhst controlled experiments. Website A/B testing is much better thought of as an optimization problem rather than a true hypothesis test. What's really important if you want to improve a website via A/B testing is a constant stream of new hypotheses (i.e. new variants). You can call tests "early" so long as you have new tests lined up it boils don't to a classic exploitation/exploration problem. In fact, in early development rapid iteration often yields superior results to waiting for significance. As a website matures and reaches closer to some theoretical optimal conversion point, then it starts becoming increasing important to wait until you are very certain of an improvement. But if you're just starting A/B testing, more iteration will yield greater success than more certainty.
- etwigg 2y agoCongrats! Let's say I have 5 variants I want to try. Does this package have anything to help with realtime experiment design, where I stop trying the less-promising variants, and focus my experimental budget on the more promising variants?
- e10v_me 2y agoNot at the moment. If you have a specific method in mind, I will gladly look into it.
- welder 2y agoI won't use any library that depends on numpy because of all the install issues in the past. Can't you do these tests with pure Python these days?
- claytonjy 2y agoWhat installation issues have you had with Numpy lately? Python packaging is a mess, but compared to issues with Torch or Nvidia stuff, Numpy has been a cakewalk whether using pip, conda, poetry, rye, etc.
- e10v_me 2y agoYou would need probability distributions anyway. In Python, SciPy is the most mature and popular package with probability distributions. And it depends on NumPy. But I'll gladly consider better alternatives if you propose them.
- 0cf8612b2e1e 2y agoWhat year is this? I have not had problems installing numpy in over a decade. They are a core library that takes its position seriously. If numpy is out of consideration so is the entire scientific Python ecosystem. Python is not a fast language and doing any kind of math heavy algorithm is going to suffer significant performance penalties.
- vermarish 2y agoVery cool! Just curious, would you consider adding more exotic experimental design setups like Latin Square Design to the roadmap?
- e10v_me 2y agoThank you. I will think about it. There are many different things I can add. The idea is to focus on the most needed features first. And the word "exotic" tells for itself ;)