This package provides a Python implementation for calculating the Mixture Sequential Probability Ratio Test (mSPRT).
mSPRT is a statistical hypothesis test that can be used to decide if a observed data supports one of two hypotheses, based on a sequence of independent and identically distributed observations.
Main functionalities:
- Calculating mixture variance
- Calculating test statistic for normal distribution
- Calculating test statistic for Bernoulli distribution
The mSPRT package can be easily installed using pip:
pip install msprt
Python >=3.10;<3.13
The mSPRT package depends on the following Python libraries:
- Numpy
- Scipy
- Matplotlib
These dependencies can also be easily installed using pip:
pip install numpy scipy matplotlib
First, import the mSPRT package:
from msprt import msprt
Then, prepare the two sample lists that you want to compare.
x = [0.1, 0.2, 0.3, 0.5, 0.7, 0.9]
y = [0.2, 0.1, 0.4, 0.6, 0.7, 0.8]
Next, call the msprt
object with observation lists, along with the parameters for the mSPRT test, such as the alpha
and the theta
values (by default it assumes you are using a normal distribution and alpha is set to 0.05).
result = msprt(x=x, y=y, sigma=1.0)
If you want to use a Bernoulli distribution, specify it as such:
result = msprt(x=x, y=y, theta=0.5, distribution='bernoulli')
To plot the results, use the plot
method:
result.plot()
For detailed information about each parameter, please refer to the comments in the source code.
If you find any problems with the implementation, you can leave the ticket on Github.
This project is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. See the LICENSE
file for more information.
- Johari, R., Pekelis, L., & Walsh, D. J. (2019). Always Valid Inference: Bringing Sequential Analysis to A/B Testing. arXiv:1512.04922 [math.ST]. Link to the paper
- The R and C++ implementations of the paper are available in the GitHub repository maintained by Erik Stenberg: GitHub Repository.