abstats

package
v1.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package abstats is the A/B test's decision rule, shared by the sending engine (which decides) and the report (which explains the decision), so the two can't disagree (review AN-1).

A variant wins only when every variant reached the minimum sample and the leader's lead over the runner-up is significant: a two-sided two-proportion z-test at the chosen confidence (95% unless the campaign says otherwise). Otherwise there is no clear winner, and the rest of the audience gets the default variant.

Index

Constants

View Source
const (
	DefaultMinSample  = 500
	DefaultConfidence = 0.95
)

Defaults of the rule (contract C14: campaigns.ab_test.min_sample and confidence).

View Source
const (
	// Winner: the leader won.
	Winner = "winner"
	// NotSignificant: the lead could be chance.
	NotSignificant = "not_significant"
	// TooSmall: a variant didn't reach the minimum sample.
	TooSmall = "too_small"
	// Manual: a person picked the variant.
	Manual = "manual"
)

Outcomes of a decision.

View Source
const NormalDF = 1000

NormalDF is the degrees of freedom above which WelchT reads its p-value from the normal distribution instead of Student's t: the two differ by less than 0.0005 there, and the holdout group's samples are thousands.

Variables

This section is empty.

Functions

func Rate

func Rate(n, d int64) (float64, bool)

Rate is n/d in percent; ok is false without a base.

func WelchT

func WelchT(meanA, varA float64, nA int64, meanB, varB float64, nB int64) (diff, t, p float64, ok bool)

WelchT is Welch's two-sample t-test (unequal variances) of mean B against mean A, from each sample's mean, unbiased variance (n − 1 in the denominator) and size, as scipy.stats.ttest_ind(b, a, equal_var=False) computes it. It returns the difference meanB − meanA, t and the two-sided p-value: Student's t with the Welch–Satterthwaite degrees of freedom, through the regularised incomplete beta function, or the normal distribution when they pass NormalDF. ok is false when a sample has fewer than two values or neither has any variance (nothing to test).

func ZTest

func ZTest(x1, n1, x2, n2 int64) (lift, z, p float64, ok bool)

ZTest is a two-proportion z-test of x1/n1 against x2/n2. It returns the difference p2 - p1 in percentage points, z and the two-sided p-value. ok is false when either sample is empty or the pooled proportion is 0 or 1 (no variance, nothing to test).

Types

type Result

type Result struct {
	// Leader has the best rate, RunnerUp the best of the rest (ties go to
	// the earlier variant).
	Leader, RunnerUp string
	// Tested: the z-test could run (both had results and the rates
	// weren't all 0% or all 100%).
	Tested bool
	// Lift is the leader's lead in percentage points; P the two-sided
	// p-value; Confidence is 1 - P in percent.
	Lift, Z, P, Confidence float64
	// Enough: every variant reached the minimum sample.
	Enough bool
	// Outcome is Winner, NotSignificant or TooSmall.
	Outcome string
}

Result is the rule applied to the variants.

func Decide

func Decide(r Rule, vs []Variant) Result

Decide applies the rule to the variants (at least two).

type Rule

type Rule struct {
	MinSample  int64
	Confidence float64
}

Rule is what a winner needs.

func (Rule) Normalized

func (r Rule) Normalized() Rule

Normalized fills in the defaults.

type Variant

type Variant struct {
	Key         string
	Eligible    int64
	Conversions int64
}

Variant is one variant's result on the test's metric: the recipients whose result could be measured and how many of them converted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL