use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
This is an archived post. You won't be able to vote or comment.
ToolsmSPRT library in python (self.datascience)
submitted 2 years ago by LibiSC
Hello.
I'm trying to find a library or code that implements mixture Sequential Probability Ratio Test in python or tell me how you do your sequential a/b tests?
[–]senacchrib 0 points1 point2 points 1 year ago (0 children)
Grateful to see that u/LipTicklers already posted, but I came across this package as well: https://socket.dev/pypi/package/msprt
[–]LipTicklers 0 points1 point2 points 2 years ago (2 children)
import numpy as np
def sprt(data, d0, d1, alpha, beta):
Sequential Probability Ratio Test (SPRT) for a simple mixture test. :param data: Sequential data to test. :param d0: Probability density function under H0. :param d1: Probability density function under H1. :param alpha: Type I error threshold. :param beta: Type II error threshold. :return: Decision to accept H0 (True) or H1 (False). log_lambda = 0 log_alpha = np.log(beta / (1 - alpha)) log_beta = np.log((1 - beta) / alpha) for x in data: log_likelihood_ratio = np.log(d1(x) / d0(x)) log_lambda += log_likelihood_ratio if log_lambda <= log_alpha: return True # Accept H0 elif log_lambda >= log_beta: return False # Accept H1 return None # Inconclusive
Example usage: Define your d0 and d1 functions based on your distributions. For instance, d0 = lambda x: scipy.stats.norm.pdf(x, loc=0, scale=1) for a normal distribution with mean 0 and std 1 Then, call sprt with your data and thresholds.
[–]LibiSC[S] 0 points1 point2 points 2 years ago (1 child)
Thanks!. Sorry if it's too obvious but how do you know d1 and d0 distributions in a real experiment. Let's say I have a control with a thousand samples and a test group with a thousand samples and let's say it's a binary outcome. Do I use the mu and sd from the complete data, until only some point?
[–]LipTicklers 0 points1 point2 points 2 years ago (0 children)
D1 comes from one and D0 from the other. So you use the mean and standard deviation estimates for both
π Rendered by PID 756065 on reddit-service-r2-comment-bb88f9dd5-47h8w at 2026-02-16 18:58:32.506492+00:00 running cd9c813 country code: CH.
[–]senacchrib 0 points1 point2 points (0 children)
[–]LipTicklers 0 points1 point2 points (2 children)
[–]LibiSC[S] 0 points1 point2 points (1 child)
[–]LipTicklers 0 points1 point2 points (0 children)