Skip to content

Equivalence (TOST) or non-inferiority test

stats_equivalence_test

Tests equivalence or non-inferiority on a difference of means or a ratio of geometric means.

Runs
On the server
Level
Checked against a reference: statsmodels 0.15.0 and SciPy 1.18.1 on typed data, NIST StRD AtmWtAg's residual SD and F, and Lakens 2017's printed example
Ask your assistant

What it is

Tests equivalence (two one-sided t tests) or non-inferiority on a difference of means or a ratio of geometric means. Use when stated margins decide whether a new method, batch or formulation is close enough to a reference: two-sample (Student or Welch), paired or one-sample, from values or summaries. Not for testing whether two groups differ: use `stats_compare_groups`. Refuses two-sample and paired margins not either side of no difference, under 3 values per group, and log ratios from summaries. A measurement's unit is required, never assumed: any unit of the kit's table, returned in its canonical spelling; a unit group takes one unit, never converted.

Field: Statistics and design.

What it does

You give

  • hypothesis (required): Equivalence: both margins, two one-sided tests; non-inferiority: one margin.
  • design (required): Independent groups, pairs (their differences) or one sample against the margins.
  • scale (required): A difference of means, in the data's unit, or a log-ratio of geometric means (natural logs of positive values).
  • input (required): Raw values, or a summary: n, mean and SD per group or of the paired differences.
  • alpha (required): Each test's one-sided significance level; the interval is 1 − 2α. Must be above 0 and below 0.5.
  • better: Non-inferiority only: which direction of difference is better; never inferred. Optional.

and 10 more, listed below

No request is recorded for this tool.

Limits

  • Research statistics and experimental-design arithmetic on the data, margins, prevalence and settings you supply.
  • Not for diagnosis or treatment decisions and not a regulatory analysis.
  • It does not choose a design, a margin, a cut-off or a sample size for you.
  • Margins are yours.
  • A 2 × 2 crossover bioequivalence analysis is not covered.
  • Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.

It will not answer when

  • equivalence with the lower margin not below the upper.
  • two-sample and paired designs: equivalence margins that do not lie either side of no difference (0, or a ratio of 1); a one-sample test takes bounds on the mean in the data's unit.
  • fewer than 3 values in a group, or 3 pairs (the rule the suite's t tests hold).
  • a group, or the differences, with no spread beyond rounding (max − min within 2·n·ε·M, M the largest magnitude among the values; from summaries, an SD of zero): t is undefined.
Every input, with its units16 inputs
  • hypothesis (required): Equivalence: both margins, two one-sided tests; non-inferiority: one margin.
  • design (required): Independent groups, pairs (their differences) or one sample against the margins.
  • scale (required): A difference of means, in the data's unit, or a log-ratio of geometric means (natural logs of positive values).
  • input (required): Raw values, or a summary: n, mean and SD per group or of the paired differences.
  • alpha (required): Each test's one-sided significance level; the interval is 1 − 2α. Must be above 0 and below 0.5.
  • better: Non-inferiority only: which direction of difference is better; never inferred. Optional.
  • variance: Two-sample only: pooled (Student) or Welch–Satterthwaite df. Optional.
  • spread: Summary only: the sample SD, never a standard error. Optional.
  • groups: Two-sample: the two groups. Optional.
  • a: Paired: the first of each pair. Optional.
  • b: Paired: the second of each pair, in a's order. Optional.
  • values: One-sample values. Optional.
  • differences: Paired summary of the within-pair differences. Optional.
  • difference: Which difference: two-sample 'B - A' by group names, paired 'b - a' or 'a - b'; '/' for '-' on log-ratio. Leading and trailing white space is removed before the pattern is checked. Optional.
  • margins: Equivalence: lower below upper, either side of no difference (two-sample, paired) or bounds on the mean (one-sample); the data's unit, or ratios (unit 1) for log-ratio. Optional.
  • margin: Non-inferiority: the margin, in the data's unit or a ratio (unit 1) for log-ratio. Unit group margin (absolute). Optional.
Every refusal, with its code9 refusals
CodeWhen
MARGINS_ORDERequivalence with the lower margin not below the upper.
MARGINS_NOT_STRADDLINGtwo-sample and paired designs: equivalence margins that do not lie either side of no difference (0, or a ratio of 1); a one-sample test takes bounds on the mean in the data's unit.
SAMPLE_TOO_SMALLfewer than 3 values in a group, or 3 pairs (the rule the suite's t tests hold).
ZERO_VARIANCEa group, or the differences, with no spread beyond rounding (max − min within 2·n·ε·M, M the largest magnitude among the values; from summaries, an SD of zero): t is undefined.
NONPOSITIVE_VALUESa value at or below 0 on the log-ratio scale.
LOG_SUMMARY_NOT_ON_LOGSany log-ratio analysis from summaries; this version has no input for summaries of the logs.
PAIRED_NEEDS_DIFFERENCESa paired analysis from the two groups' own summaries, which do not give the SD of the differences.
MARGIN_SIDEtwo-sample and paired designs: a non-inferiority margin on the wrong side of no difference for the stated direction of benefit, or at it: better 'higher' needs a margin below 0 (a ratio below 1) and better 'lower' one above 0 (a ratio above 1), so a margin of exactly 0 (or 1) is refused (F-6).
PAIRS_UNEQUALpaired values a and b of different lengths.

The calculation

The method's equations, constants and worked example.

Equivalence by two one-sided t tests, or non-inferiority by one, on a difference of means or a ratio of geometric meansstats-equivalence@2.0.1

Equation 1

d = mean, SE = s/√n, df = n − 1 (paired: on the within-pair differences)

one-sample: Lakens' t_L = (M − μ − Δ_L)/(SD/√N) is the test of the mean against the bound θ_L = μ + Δ_L, so the margins are bounds on the mean in the data's unit

SymbolMeaning
destimate (in the caller's unit), as-given
ssample SD (n − 1) (in the caller's unit), as-given
nvalues or pairs
M, SD, NLakens' sample mean, SD and size: d, s and n here, as-given
μLakens' reference value; with μ = 0 the bound θ_L is the margin itself, as-given
Δ_LLakens' lower equivalence bound relative to μ, as-given

Source 1.

Equation 2

d=M2−M1
sp2=((n1−1)s12+(n2−1)s22)/(n1+n2−2)
SE=sp√(1/n1+1/n2)
df=n1+n2−2
SymbolMeaning
Mgroup mean (in the caller's unit); M₂ the named second group, M₁ the named first, as-given
s_ppooled SD (in the caller's unit), as-given
n₁, n₂sizes of the first and second groups
s₁, s₂sample SDs (n − 1) of the first and second groups, as-given

Source 1.

Equation 3

SE=√(s12/n1+s22/n2)

df = (s₁²/n₁ + s₂²/n₂)² / ((s₁²/n₁)²/(n₁ − 1) + (s₂²/n₂)²/(n₂ − 1))

SymbolMeaning
dfWelch–Satterthwaite degrees of freedom
n₁, n₂sizes of the first and second groups
s₁, s₂sample SDs (n − 1) of the first and second groups, as-given

Source 1.

Equation 4

through the shared tost routine: t_L = (d − θ_L)/SE, p_L = P(T_df ≥ t_L)

t_U = (d − θ_U)/SE, p_U = P(T_df ≤ t_U). Equivalence: p = max(p_L, p_U), shown when p < α. Non-inferiority: better 'higher' tests the lower margin alone (side 'lower', H1: d > θ_L), better 'lower' the upper margin alone (side 'upper', H1: d < θ_U), shown when its p < α. Interval d ± t(1 − α, df)·SE at 1 − 2α. The reply's tests[].side is 'lower' or 'upper'

conclusion is 'shown' or 'not shown'

SymbolMeaning
θ_L, θ_Ulower and upper margins on the analysis scale (in the caller's unit), as-given
SEstandard error (in the caller's unit), as-given
T_dfStudent's t on df degrees of freedom
t(1 − α, df)the 1 − α quantile of Student's t on df degrees of freedom
αone-sided significance level

Source 1.

Equation 5

on the log-ratio scale every value is replaced by its natural log, the margins r by ln r

the estimate and interval limits are reported as exp of the analysis scale (a ratio of geometric means)

SymbolMeaning
rratio margin

Source 1.

Conventions

  • hypothesis = equivalence: Two one-sided t tests against both margins; p = the larger one-sided p; shown when p < α, which is the (1 − 2α) interval lying inside the margins.
  • hypothesis = non-inferiority: One one-sided t test against the one margin, on the side the stated direction of benefit gives; shown when its p < α.
  • design = two-sample: Two independent groups: d = mean of the named second minus the named first, with Student's pooled or Welch's SE and df. The reply's n lists the group sizes in that order, [the named first, the named second], so for "A - B" it is [n of B, n of A] (F-6).
  • design = paired: Pairs: d = mean of the within-pair differences, SE = s_d/√n, df = n − 1.
  • design = one-sample: One sample: d = its mean, tested against margins in the data's unit; SE = s/√n, df = n − 1.
  • scale = difference: A difference of means, in the data's unit; margins in the data's unit.
  • scale = log-ratio: A ratio of geometric means (unit 1): the analysis on natural logs of positive values, margins as ratios; the SE on the log scale (ln(1)).

A definition, not a model: the equation states what the quantity means. A different convention gives a different number.

Worked example

Worked example: one case of stats-equivalence@2.0.1, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

Inputs

  • hypothesis = equivalence
  • design = two-sample
  • scale = difference
  • input = summary
  • spread = sd
  • margins.lower = -0.384
  • margins.upper = 0.384
  • alpha = 0.05
  • groups[0].name = A
  • groups[0].n = 89
  • groups[0].mean = 5.22
  • groups[0].sd = 0.83
  • groups[1].name = B
  • groups[1].n = 95
  • groups[1].mean = 5.25
  • groups[1].sd = 0.95
  • variance = pooled
  • difference = B - A

Steps

  1. d = 0.03, from groups[0].mean, groups[1].mean; by equation 2; gives estimate.
  2. sp = 0.89399154, from groups[0].sd, groups[1].sd, groups[0].n, groups[1].n; by equation 2.
  3. se = 0.131882, from sp, groups[0].n, groups[1].n; by equation 2; gives standardError.
  4. df = 182, from groups[0].n, groups[1].n; by equation 2; gives df.

The working, as the case writes it:

printed inputs reproduce t_L = 3.1392 (printed 3.14) and t_U = -2.6842, where the source prints -2.69: the method gives -2.684, outside the printed value's rounding, so the printed t_U is a source anomaly

rounding of the inputs moves t by up to 0.0939 and p by up to 0.00116

Answer

estimate = 0.03

standardError = 0.131882

df = 182

Where these values came from: the source's own worked example, Lakens 2017, section 'Equivalence Tests for Differences Between Two Independent Means', the organic-food example: t_L = 3.14, t_U = -2.69, df 182, p .001 and .004; Lakens 2017, the organic-food example (printed values).

At build the tool returned this answer within the tolerance the file states: t absolute 0.099 and p absolute 0.0017, the effect of rounding the printed means and SDs (±0.005) plus half the printed digit; other values relative 1e-9 against SciPy and statsmodels; df, statuses and codes exact. Source anomaly: the printed t_U (-2.69) is -2.684 from the printed inputs.

Sources

  1. Lakens D. Equivalence tests: a practical primer for t tests, correlations, and meta-analyses. Soc Psychol Personal Sci 2017;8(4):355-362 (CC BY 4.0)

    Used for: Equivalence by two one-sided t tests, or non-inferiority by one, on a difference of means or a ratio of geometric means. At: section the one-sample and dependent-means equations (t_L = (M − mu − Δ_L)/(SD/√N); the paired form on the differences); section equations 1 and 2; section equations 3 and 4; section equations 1 and 2 and the one-sided tests of each bound; the conclusion rule and the interval are the shared tost record's; section the TOST equations applied to the analysis scale; the log transform is the builder's construction, checked against statsmodels on logs.

    Read in full, 10 November 2026

How it is checked

Level

Checked against a reference.

Checked against

An outside program, statsmodels; NIST StRD AtmWtAg; SciPy, statsmodels 0.15.0; StRD (data content 2003); scipy 1.18.1; certified values, statsmodels; NIST StRD AtmWtAg; SciPy, statsmodels 0.15.0; StRD (data content 2003); scipy 1.18.1; the source's own worked example, Lakens 2017 worked example; SciPy for the bound, Soc Psychol Personal Sci 8:355-362; scipy 1.18.1; a reference program this project wrote itself, second implementation (Python 3.13; NumPy, SciPy distribution functions and mpmath only), 2026-11-14, double precision; t tails from SciPy 1.18.1; the interval's t quantile from SciPy's isf at alpha 1e-9 and from mpmath at 60 digits at alpha 0.4999999; not an outside program.

Cases

No case set is linked to this version.

Not checked

Schuirmann 1987 and the FDA's 2001 guidance are not read; log-ratio analyses from summaries (of the logs or not) are not offered in 1.0.0; standardised (Cohen's d) margins are not offered, because they depend on the observed SD; the interval's coverage is not simulated; one-sample from summaries is not offered; crossover designs are pharmacokinetics' tool, through the same shared routine; the margins and α are the caller's.

Changes to its methods0 changes

No change is logged for these method versions.