Hypothesis testing
假设检验
Calculate an exact binomial p-value, distinguish error rates from posterior probabilities, and report effects alongside decisions.
hypothesis-testingTen wins out of twelve: unusual under which model?
Two methods are compared in twelve independent trials with no ties. Method A wins ten. Before observing results, you specify a null model in which A has win probability one half on every trial, and a one-sided alternative that A wins more often.
The question is not “what is the probability that the null is true?” It is “if this null model generated the trials, how often would the chosen statistic be at least this favorable to A?” The distinction determines what a p-value can say.
Specify the null, alternative, statistic, and rule
Let be the number of A wins. Under the stated independent Bernoulli null, has a binomial distribution. For observed value , the upper-tail p-value is:
For , this is . We counted outcomes at least as extreme in the prespecified direction, including the observed one. The result concerns the complete sampling model, including independence and the win definition. NIST, statistical tests
A level- procedure limits its probability of rejecting a true null to at most under the null’s assumptions. Here rejecting when the upper-tail p-value is at most 0.05 means rejecting at ten or more wins. Its actual null rejection probability is about 0.01929, below 0.05 because the statistic is discrete. With nine wins, the tail probability is .
Type I error means rejecting a true null. Type II error means failing to reject a false null; its probability depends on the particular alternative and sample size. Power is . These are repeated-sampling properties of a procedure, not posterior probabilities attached to this experiment’s hypothesis.
For a two-sided alternative under this symmetric fair-win null, an exact absolute-deviation statistic gives:
Ten wins then gives . Do not choose the one-sided direction after seeing which method wins. Other discrete null models and definitions of two-sided extremeness can yield different conventions; “double a tail” is not a universal recipe.
Enumerate the rejection probability
This complete program uses exact rational arithmetic for the small fair-win test. It checks both tails and enumerates the procedure’s actual false-positive probability rather than assuming it equals 0.05. It also calculates power when A’s true win probability is 0.75.
from math import comb
from fractions import Fraction
def fair_tail(n, wins, two_sided=False):
if type(n) is not int or type(wins) is not int or n < 1 or not 0 <= wins <= n:
raise ValueError("positive integer trial count and valid wins required")
selected = [k for k in range(n+1)
if (abs(2*k-n) >= abs(2*wins-n) if two_sided else k >= wins)]
return sum((Fraction(comb(n,k),2**n) for k in selected),Fraction(0))
assert fair_tail(12,10) == Fraction(79,4096)
assert fair_tail(12,9) == Fraction(299,4096)
assert fair_tail(12,10,True) == Fraction(158,4096)
assert fair_tail(12,6,True) == 1
assert fair_tail(12,0) == 1
rejection = [k for k in range(13) if fair_tail(12,k) <= Fraction(1,20)]
assert rejection == [10,11,12]
false_positive = sum(Fraction(comb(12,k),2**12) for k in rejection)
assert false_positive == Fraction(79,4096) < Fraction(1,20)
q = Fraction(3,4)
power = sum(comb(12,k)*q**k*(1-q)**(12-k) for k in rejection)
assert Fraction(39,100) < power < Fraction(40,100)
try:
fair_tail(12,13)
except ValueError:
pass
else:
raise AssertionError("impossible win count accepted")
Computing one tail takes binomial terms, ignoring the increasing cost of large-integer arithmetic. Enumerating every possible observation with repeated tail calculations takes terms here. This is a transparent small-sample implementation; production statistical libraries use more efficient and numerically appropriate distribution functions for large samples.
A small p-value does not measure the size of an improvement
The observed win fraction is , an effect estimate for this particular win-based outcome. It ignores the magnitude of wins and losses. A method can win slightly in many trials and fail severely in a few. Report the relevant effect size, uncertainty, trial count, and data-generating conditions alongside the p-value. The ASA’s 2016 statement explicitly distinguishes significance from effect size and rejects interpreting p-values as probabilities that hypotheses are true. ASA statement release, principles 2 and 5
Failing to reject is not proof of equality. A small study can have low power against improvements that matter. Conversely, a large study can detect effects too small to justify a deployment change. Equivalence and noninferiority questions require their own margins and procedures.
Trying many metrics or repeatedly checking results until significance appears changes the error rate unless the procedure accounts for it. Across independent level-0.05 tests whose null rejection probabilities are exactly 0.05, the chance of at least one false rejection is . The assumptions in that illustration matter; dependence and discrete tests change the calculation. Correction, preregistration, or sequential methods must match the actual analysis.
Translate the result without reversing the conditional
- Does mean a 1.929% probability that the null is true? Answer: no. It is a tail probability assuming the null model.
- Does nine wins reject at the specified one-sided 0.05 rule? Answer: no; its p-value is about 0.073.
- Why is the false-positive rate below 0.05 here? Answer: only certain discrete tail probabilities are attainable, and the chosen cutoff is conservative.
- What must be reconsidered if all twelve trials share a strong common disturbance? Answer: independence and the binomial sampling model; twelve recorded outcomes may not supply twelve independent pieces of evidence.
Inference should serve the scientific question
Tests, confidence intervals, Bayesian analyses, and decision models answer related but different questions. Choose an estimand and sampling design first, then a method whose assumptions are defensible. Statistical significance alone does not establish reproducibility, a causal mechanism, practical usefulness, or immunity to selection bias.
Make a prediction, then check
What is the accurate interpretation of p=0.01929?
Learning objectives
- Calculate exact binomial p-values, rejection regions, and actual Type I error rates.
- Distinguish one-sided/two-sided tests, power, effect size, and posterior hypothesis probabilities.
Prerequisites & connections
Explore related knowledge →References
- NIST/SEMATECH e-Handbook — What are statistical tests?
NIST and SEMATECH - ASA release: Statement on Statistical Significance and P-Values
American Statistical Association · 2016
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, re-derivation and recalculation, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Enumerated all fair binary sequences for n=1 through 10 and checked both tails at every observation; exactly recalculated 79/4096, 299/4096, and 158/4096 at n=12.
- Enumerated the rejection region, actual Type I error, and power at win probability 0.75; distinguished p-values, posterior probabilities, effects, and multiple-testing assumptions.
- Compared bilingual arguments, conditions, examples, and exercise answers; structural checks separately compare formulas, code, sections, and references. No independent human peer review.
Source locations checked:
- NIST/SEMATECH e-Handbook — What are statistical tests? · §7.1.3: null/alternative, significance level, Type I/II errors; article avoids interpreting nonrejection as proof
- ASA release: Statement on Statistical Significance and P-Values · 2016-03-07 release, PDF p.2: six principles, especially hypothesis probability and effect-size distinctions
Related topics