Skip to main content

A/B 테스트 통계적 검정에 필요한 결과를 제공하는 라이브러리

Project description

ab-stats

ab-stats is a Python library that computes the statistics you need for A/B tests. It runs a two-sample proportion z-test for rate (proportion) differences and Welch's t-test for mean differences between control and treatment groups, and returns p-value, confidence intervals, uplift (relative change), and minimum sample size (MSS) in a pandas DataFrame.

Documentation

Installation

Dependencies

ab-stats depends on:

  • NumPy (>= 1.20)
  • Pandas (>= 1.3)
  • SciPy (>= 1.7)

Python 3.8 or newer is required.

User installation

Install from PyPI with pip:

pip install ab-stats

or with conda:

conda install -c conda-forge ab-stats

Quick start

1. Proportion (rate) difference — proportions_ztest

Pass sample sizes and success counts for control and treatment; the function runs a two-sample proportion z-test and returns uplift, confidence intervals, and minimum sample size. MSS is the sample size required for the given α and β under the assumption that the observed effect is true; it is computed post hoc and should be used as a reference only.

from ab_stats import proportions_ztest

# Control: 101 successes out of 998; Treatment: 122 successes out of 1001
df = proportions_ztest(
    control_n=998,
    control_success=101,
    treatment_n=1001,
    treatment_success=122,
    alpha=0.05,
    power=0.8,
)
print(df)

Output:

metric_formula metric_value delta_relative delta_absolute p_value CI_relative CI_absolute MSS statistic
122/1001 0.1219 20.45 0.0207 0.14162 [5.12%, 35.78%] [-0.0069, 0.0483] 152.3% (657) 1.47

2. Mean difference — ttest_ind_welch

Pass lists of values for control and treatment; the function computes means, variances, and sample sizes internally and runs Welch's t-test.

from ab_stats import ttest_ind_welch

# Example: observation lists for control and treatment
control = [10.1, 9.8, 11.2, 10.5, 9.9, 10.8, 10.3, 11.0, 9.7, 10.4, 9.8, 10.1]  # n=12
treatment = [12.0, 11.5, 12.8, 11.9, 12.2, 12.5, 11.7, 12.1, 12.3, 11.8]  # n=10

df = ttest_ind_welch(control, treatment, alpha=0.05, power=0.8)
print(df)

Output:

metric_formula metric_value delta_relative delta_absolute p_value CI_relative CI_absolute MSS statistic df
120/10 12.03 17.14 1.76 0.00273 [8.21%, 26.07%] [0.65, 2.87] 45.2% (221) 3.45 18.52

3. Using with Pandas

Results are returned as a pandas DataFrame, so you can merge with other columns or filter as usual.

import pandas as pd
from ab_stats import proportions_ztest, ttest_ind_welch

# Proportion test
result_prop = proportions_ztest(1000, 100, 1000, 120)
# Use result_prop["p_value"], result_prop["CI_relative"], etc.

# Mean test (lists → means, variances, n are computed inside the function)
control_vals = [1.0, 2.0, 3.0, 4.0, 5.0]
treatment_vals = [2.0, 3.0, 4.0, 5.0, 6.0]
result_ttest = ttest_ind_welch(control_vals, treatment_vals)
# Use result_ttest["metric_value"], result_ttest["df"], etc.

License

MIT License. See LICENSE for details.

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

ab_stats-0.1.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

ab_stats-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file ab_stats-0.1.1.tar.gz.

File metadata

  • Download URL: ab_stats-0.1.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for ab_stats-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bb1554770880321fe7cf4e71a88ce23585329c72848a035dd3e1ecce0a5f51ed
MD5 0baf65f71787a1f31df260fe0d58811f
BLAKE2b-256 863a8f1385bf0079e4563ce2f88b2752e8550a5b85f0e2439d12eafec26f2108

See more details on using hashes here.

File details

Details for the file ab_stats-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ab_stats-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for ab_stats-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c18dbe7b5477719cbc4465a9e83e237aa64bd78d842eaef3391be4731414ef91
MD5 27eb8dfd34efa890117b119fcb049c26
BLAKE2b-256 efeeec4f958321ed3df9357c2440c7f9cdac571f9d0aa6b79457bc6c4293f656

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