Skip to main content

No project description provided

Project description

Python mSPRT Package:

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:

  1. Calculating mixture variance

$$ \tau^2 = \sigma^2 \frac{\Phi(-b)}{\frac{1}{b}\phi(b)-\Phi(-b)} $$

  1. Calculating test statistic for normal distribution

$$ \tilde{\Lambda}_n = \sqrt{\frac{2\sigma^2}{V_n + n\tau^2}}\exp\left(\frac{n^2\tau^2(\bar{Y}_n - \bar{X}_n-\theta_0)^2}{4\sigma^2(2\sigma^2+n\tau^2)}\right). $$

  1. Calculating test statistic for Bernoulli distribution

$$ \tilde{\Lambda}_n = \sqrt{\frac{V_n}{V_n + n\tau^2}}\exp{\left(\frac{n^2\tau^2(\bar{Y}_n - \bar{X}_n-\theta_0)^2}{2V_n(V_n+n\tau^2)}\right)} $$

Installation:

The mSPRT package can be easily installed using pip:

pip install msprt

Pre-requisite

Python >=3.10;<3.13

Dependencies:

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

How to Use:

First, import the mSPRT package:

import numpy as np
from msprt import msprt

Then, prepare the two sample lists that you want to compare.

np.random.seed(42)
n = 500
x = np.random.normal(0, 1, n)
y = np.random.normal(0.2, 1, n)

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)
print(result)

If you want to use a Bernoulli distribution, specify it as such:

result = msprt(x=x, y=y, theta=0.5, distribution='bernoulli')
print(result)

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.

Contact:

If you find any problems with the implementation, you can leave the ticket on Github.

mSPRT GitHub Page

License:

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.

References (real heroes)

  1. 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
  2. The R and C++ implementations of the paper are available in the GitHub repository maintained by Erik Stenberg: GitHub Repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msprt-0.1.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

msprt-0.1.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file msprt-0.1.2.tar.gz.

File metadata

  • Download URL: msprt-0.1.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.12 Darwin/22.2.0

File hashes

Hashes for msprt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a930722f36b5c5c59f709bdb2dc70566c744e321b287ec29783d35a8edbe3801
MD5 401ed1962ca0974af3f028e0b922e757
BLAKE2b-256 649fe0105f4431346f3bb325c7a491a920b77034b517770335f6b52aa1753e3d

See more details on using hashes here.

File details

Details for the file msprt-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: msprt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.12 Darwin/22.2.0

File hashes

Hashes for msprt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 da44eeab1b284cddca12cde0a31f8ff6b2278de8984b061de1cda9691bd41c95
MD5 8ef3c7b0f89c4daf657c38ef729b7203
BLAKE2b-256 84813970557440bf1859a5d041487f03b8da1500823cdacf11d40911bfffbc75

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page