AI Wiki中文/EN

Statistical power

统计功效

Plan an exact test and distinguish nominal size, actual size and alternative-specific power.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

A test can miss a real improvement

A fixed test controls how often it falsely rejects a null model. That does not tell you how often it detects a particular real change. Statistical power asks the second question before the future data are observed.

Suppose the null success rate is 0.5 and the scientifically relevant alternative is 0.8. Ten trials may be enough to observe an encouraging-looking rate, yet the exact test can still have low probability of rejecting. Planning requires the rejection rule, sample size and alternative—not just the familiar label “5% significance.”

Read p-values and hypothesis testing first. Our example is a prespecified one-sided binomial test; it is not a universal sample-size recommendation.

Power is a probability under an alternative

For a fixed rejection region R, define:

size=Pr⁡θ0(D∈R),power(θ1)=Pr⁡θ1(D∈R),β(θ1)=1−power(θ1).\mathrm{size}=\Pr_{\theta_0}(D\in R),\qquad \mathrm{power}(\theta_1)=\Pr_{\theta_1}(D\in R),\qquad \beta(\theta_1)=1-\mathrm{power}(\theta_1).

The first is the false-rejection probability at the simple null. The second is the chance of rejection at a specified alternative; β is the corresponding Type II error probability. Power is a function of the alternative, not one fixed property of a dataset. The NIST testing reference explains significance, critical regions and power. For composite nulls, size is usually defined as the supremum over the null parameter set; here the null is fixed.

Design the rejection region before evaluating power

Let K count successes in n independent common-probability Bernoulli trials. Under a planned larger-rate test, reject when K≥c. Choose the smallest cutoff whose null upper tail does not exceed α:

c=min⁡{r∈{0,…,n+1}:∑k=rn(nk)p0k(1−p0)n−k≤α}.c=\min\left\{r\in\{0,\ldots,n+1\}:\sum_{k=r}^{n}\binom nk p_0^k(1-p_0)^{n-k}\le\alpha\right\}.

The cutoff n+1 denotes a never-reject rule. Empty sums are zero. Discrete data can make the actual size strictly smaller than α. The NIST Binomial reference gives the probability model used in these sums.

Now hold that cutoff fixed and evaluate its probability at the alternative:

power(p1)=∑k=cn(nk)p1k(1−p1)n−k.\mathrm{power}(p_1)=\sum_{k=c}^{n}\binom nk p_1^k(1-p_1)^{n-k}.

For n=10, p₀=1/2 and α=0.05, c=9. Actual size is 11/1024, while power at p₁=4/5 is 3670016/9765625, about 0.3758. Thus the test misses this alternative roughly 62.4% of the time under the stated model. A low-power failure to reject does not establish that the rates are the same.

Sample size interacts with discreteness

Increasing n generally makes more information available, but the power of this particular nonrandomized threshold design need not increase at every integer n. The critical count jumps to keep size below α. In the computed table, power at n=18 is higher than at n=20, even though twenty trials contain more observations.

We search the candidate sizes directly rather than assuming monotonicity for binary search. The first n from 1 through 80 meeting 80% power is a result for p₀=0.5, p₁=0.8, this tail direction and this exact size rule. Changing any of those choices changes the design.

Compute size and power from exact tails

Run the complete Python 3.12 standard-library program. It accepts 1–200 trials, rational probabilities in [0,1] and a rational α strictly between zero and one. A cumulative upper-tail array includes both “always reject” and “never reject” endpoints. Probability zero and one are handled by the binomial formula’s integer-power convention.

from fractions import Fraction as F
from math import comb


def tails(n,p):
    if type(n) is not int or not 1 <= n <= 200:
        raise ValueError('integer trial count in [1,200] required')
    if type(p) not in (int,F) or not 0 <= p <= 1:
        raise ValueError('rational probability in [0,1] required')
    p=F(p)
    mass=[F(comb(n,k))*p**k*(1-p)**(n-k) for k in range(n+1)]
    assert sum(mass)==1
    tail=[F(0)]*(n+2)
    for k in range(n,-1,-1):tail[k]=tail[k+1]+mass[k]
    return tail


def design(n,p0,p1,alpha=F(1,20)):
    null=tails(n,p0);alternative=tails(n,p1)
    if type(alpha) not in (int,F) or not 0 < alpha < 1:
        raise ValueError('rational alpha in (0,1) required')
    critical=next(k for k in range(n+2) if null[k]<=alpha)
    return critical,null[critical],alternative[critical],1-alternative[critical]


if __name__ == '__main__':
    for n in [10,16,18,20,40]:
        critical,size,power,beta=design(n,F(1,2),F(4,5))
        print('n='+str(n),'reject at K>='+str(critical),
              'actual size='+format(float(size),'.6f'),'power='+format(float(power),'.6f'))
    first=next(n for n in range(1,81) if design(n,F(1,2),F(4,5))[2]>=F(4,5))
    print('first n in 1..80 reaching power 0.8:',first)

Output:

n=10 reject at K>=9 actual size=0.010742 power=0.375810
n=16 reject at K>=12 actual size=0.038406 power=0.798245
n=18 reject at K>=13 actual size=0.048126 power=0.867084
n=20 reject at K>=15 actual size=0.020695 power=0.804208
n=40 reject at K>=26 actual size=0.040345 power=0.992084
first n in 1..80 reaching power 0.8: 18

The probabilities are exact fractions internally; decimals are only display values. Each fixed-n calculation builds two sets of n+1 masses and accumulates tails in O(n) arithmetic, excluding binomial-coefficient and rational bit cost. Searching many sample sizes repeats this work and explicitly inspects each candidate.

The example evaluates a theoretical design. It does not measure an actual deployed system’s success rate, and it does not claim that 18 observations are sufficient under different dependence, heterogeneity or effect assumptions.

Planning assumptions can dominate the answer

Choosing an unrealistically large alternative effect can make the required sample size look attractive. Use an effect that matters for the actual question, explore plausible alternatives, and account for observation variability and design. Correlated trials or clustered sampling do not supply the same information as independent trials.

Power is not 1 minus the observed p-value. Computing “observed power” by plugging the observed effect back into a design calculation does not add independent evidence about that result. Effect estimates and uncertainty intervals are more informative descriptions of what the data showed.

Testing multiple outcomes, changing the stopping rule or switching sides after seeing data changes error control. The original fixed-n power calculation then describes a different procedure. Sequential designs require their own joint treatment of power and false-rejection probability.

A nonsignificant result is not an equivalence conclusion. If the goal is to rule out meaningful differences, specify an equivalence margin and an appropriate design rather than treating failure to reject a point null as proof of sameness.

Keep the procedure fixed across probabilities

  1. Under which model is power calculated: the null or a specified alternative?

Answer 1: The alternative. The rejection region is chosen using the testing rule, then its probability is evaluated under the alternative of interest.

  1. For n=10 in this design, why is actual size not exactly 0.05?

Answer 2: Binomial tails are discrete. The allowed rejection region starts at nine, giving size 11/1024 rather than the nominal threshold.

  1. Why does this code scan all candidate sizes instead of assuming power increases at every n?

Answer 3: Integer cutoff changes can cause local power decreases for this nonrandomized rule. The table’s n=18 and n=20 values demonstrate that effect.

  1. Does failing to reject with low power prove that the two rates are equal?

Answer 4: No. The procedure may often miss the relevant alternative. Equality or equivalence requires a different claim and suitable evidence.

Treat sample-size planning as a model-based calculation

NIST supplies the definitions and binomial model. Exact enumeration here separates nominal α, actual size, power and Type II error, making the design assumptions inspectable.

For a project, draw power curves over several alternative rates for a fixed planned n. Then compare one-sided and explicitly defined two-sided designs at comparable error control. Record those choices before observing the test dataset.

Make a prediction, then check

Is power equal to one minus the observed p-value?

Choose one answer

Learning objectives

  • Compute exact test size and power under declared hypotheses.
  • Plan sample size without assuming discrete power is monotone.

Prerequisites & connections

Explore related knowledge →

References

  1. NIST/SEMATECH e-Handbook — Quantitative Techniques: hypothesis tests and power
    NIST and SEMATECH
  2. NIST/SEMATECH e-Handbook — Binomial Distribution
    NIST and SEMATECH

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: primary-source locations, explicit assumptions, derivations, exact/literal and numerical checks, and bilingual review; not independent human or second-agent peer review.

  • Single-agent authored technical review: primary-source locations, explicit domains and assumptions, derivations, literal/exact probability or numerical reference cases, bilingual examples and exercises. Not independent human or second-agent review.
  • Four focused tests passed on CPython3.12.4; NumPy1.26.4 actually executed for the Fourier chapter. Exact rational probability/stencil checks are distinguished from floating-point calculations and observed Monte Carlo output. Both languages render three equations, six anchors and four answers; final repository checks recorded separately.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.