Skip to main content

sequential-testing

Collection of sequential testing methods for A/B tests.

Python library for Sequential testing methods for A/B tests. Currently supporting:

  • Sequential Probability Ratio Test (SPRT)
  • Mixture Sequential Probability Ratio Test (mSPRT)

Installation

pip install sequential-testing

Usage

SPRT

normal distribution

import numpy as np
from sequential-testing  import SPRTNormal
seed = 7
random_normal = np.random.default_rng(seed)

sample_size = 500
samples_x = random_normal.normal(loc=0.5, scale=1, size=sample_size)
samples_y = random_normal.normal(loc=0.58, scale=1, size=sample_size)


sprt_normal = SPRTNormal(alpha=0.05, beta=0.2, sigma=1, h0=0., h1=0.05 )
sprt_normal.fit(x_values=samples_x, y_values=samples_y)
sprt_normal.plot()

SPRT Normal example

we can inspect the LLR value and step when the null hiphotesis got rejected or accepted

print(sprt_normal.h0_rejected)  # return a list of tuples (LLR, step)
print(sprt_normal.h0_acepted)

binomial distribution

import numpy as np
from sequential-testing  import SPRTBinomial

x_values = [1,0,1,0,1,0,1,0,1,1] * 20  # conv rate = 0.6
random.shuffle(x_values)

a = SPRTBinomial(method="fixed",alpha=0.05, beta=0.2, h0=0.5, h1=0.55)
a.fit(x_values)
a.plot()

SPRT Binomial example

we can inspect the LLR value and step when the null hiphotesis got rejected or accepted

print(sprt_normal.h0_rejected)  # return a list of tuples (LLR, step)
print(sprt_normal.h0_acepted)

mSPRT

normal distribution

import numpy as np
from sequential-testing  import MSPRTNormal

seed = 9
random_normal = np.random.default_rng(seed)

sample_size = 2000
samples_x = random_normal.normal(loc=0.1, scale=1, size=sample_size)
samples_y = random_normal.normal(loc=.13, scale=1, size=sample_size)


msprt_normal = MSPRTNormal(
    alpha=0.05,
    beta=0.2,
    sigma=1,
    tau=None, # if None then tau gets calculated
    h0=0.1,
    m=sample_size,
)
msprt_normal.fit(x_values=samples_x, y_values=samples_y)
msprt_normal.plot()

mSPRT Normal example

we can inspect the LLR value and step when the null hiphotesis got rejected or accepted

print(sprt_normal.h0_rejected)  # return a list of tuples (LLR, step)
print(sprt_normal.lr) # return the list of Likehood Ratio values

License

MIT License

Download files

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

Source Distribution

sequential_testing-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

sequential_testing-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file sequential_testing-0.1.0.tar.gz.

File metadata

  • Download URL: sequential_testing-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.10 Linux/6.17.9-76061709-generic

File hashes

Hashes for sequential_testing-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0f5a5e9479fb570ffe45184cd1d70d5123fbb5f92c79d1bd35c5374173b45e11
MD5 5b0d52462b6035033cabd2b82f3b8ba6
BLAKE2b-256 9671938e42c0bbde807793a2c69955b4aa38bc4089322e89a0dd473401600aef

See more details on using hashes here.

File details

Details for the file sequential_testing-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sequential_testing-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.10 Linux/6.17.9-76061709-generic

File hashes

Hashes for sequential_testing-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e3ffce9e8b0031ad3bdee1af9a65d272c0264c692dc6c7525ceb7a41f57113e
MD5 78812853f472b281d9b86a7bbd106a55
BLAKE2b-256 80415d205ee2910663d496edd4d0b20f7dc180e9cbd8b8203054a7c154c768e3

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page