Method · Statistics Library

Sign test (one median, or paired data)

The sign test asks whether the median of one numeric variable (or of paired differences) equals a hypothesized value m₀ by counting how many values fall above and how many below it; under H₀ each value is a fair coin toss, so the p-value is the exact binomial one.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

If the true median were m₀ (the value you are testing), half of all values would lie above it and half below. The sign test counts the values above and below m₀ and asks how unusual that split would be for a fair coin tossed once per value.

Values exactly equal to m₀ have no sign (neither above nor below), so the test leaves them out. With paired data (before and after on the same row) the test works on the differences, first minus second: above means the first measurement was higher in that pair.

A small p-value means a split this lopsided would rarely happen if the median were m₀. If you chose a direction before looking (Alternative set to greater or less), the p-value counts only splits lopsided in that direction: a split with more values below m₀ is no evidence for 'greater'. A large p-value means there is no clear evidence that the median differs from m₀; it does not show that the median equals m₀. The interval for the median gives the medians that remain compatible with the data.

The interval's level is shown exactly, for example 95.47% rather than 95%. The interval runs between two of your own sorted values, so only certain levels are possible, and the card shows the level its interval really has: usually a little above the level you asked for. With five or fewer values no interval reaches 95%, and the card shows the widest one, from the smallest to the largest value, with its lower level (93.75% for five values).

The sign test uses only whether each value is above or below m₀, not how far. The Wilcoxon signed-rank test also uses how far, so it finds a difference more easily when the values are roughly symmetric about their middle. When the values are clearly lopsided, the two tests answer different questions, and the sign test is the one about the median: on penguin body mass against 4,000 g the sign test gives p = .744 and the Wilcoxon test p = .0005.

Practitioner explanation

KernelStats counts S, the values above m₀, out of n values not equal to m₀ and reports the exact binomial p-value of binom.test(S, n, 0.5) (two-sided: R's rule, which with probability 1/2 is twice the smaller tail, capped at 1; greater: P(Bin(n, 1/2) ≥ S); less: P(Bin(n, 1/2) ≤ S)). The estimate is the sample median of all values, with the distribution-free order-statistic interval [x_(k), x_(N−k+1)], k = qbinom(α/2, N, 1/2); its achieved coverage 1 − 2·P(Bin(N, 1/2) ≤ k − 1) is shown, and is at least the requested level whenever an order-statistic interval can reach it (at 95% two-sided, N ≥ 6). With N ≤ 5 at 95% the card shows [x_(1), x_(N)] at its true level 1 − 2(1/2)^N (93.75% for N = 5) rather than an infinite interval. One-sided tests get one-sided bounds with k = qbinom(α, N, 1/2) and coverage 1 − P(Bin(N, 1/2) ≤ k − 1), the upper bound as the mirror image of the lower one. The coverage is exact for a continuous measurement; with many tied values (body mass recorded to the nearest 25 g, for example) it is approximate.

The test assumes only independence and that each value can be ordered against m₀: no normal shape and no symmetry, which is why it has less power than the Wilcoxon signed-rank test when the differences are symmetric. When they are not, the two tests answer different questions: the Wilcoxon test is about the pseudomedian (the Hodges-Lehmann center), which skew pulls toward the long tail. On penguin body mass (right-skewed: mean 4,202 g, median 4,050 g) against 4,000 g, the sign test gives p = .744 and the Wilcoxon signed-rank test on the same card gives p = .0005. The card shows the Wilcoxon and t-test results under Alternative Tests. Validated against binom.test and DescTools::SignTest in R 4.5.3 (DescTools prints a one-sided upper bound one order statistic lower, whose true coverage is below its stated level; KernelStats does not follow that).

When to use it

Consider it when

Testing a median against a value, or whether paired measurements tend to go up or down, when the values are clearly skewed, only ordered (better / same / worse), or when the most assumption-free answer is wanted.

Use caution when

When the differences are roughly symmetric (the Wilcoxon signed-rank test uses their sizes and has more power), when the mean is the question (use the one-sample or paired t-test), or with five or fewer values (no two-sided result can reach p < .05).

Formulas and symbols

Exact binomial p-value (greater)

p=∑s=Sn(ns)(12)np = \sum_{s=S}^{n} \binom{n}{s} \left(\tfrac{1}{2}\right)^{n}

S the number of values above m₀, n the number of values above or below m₀ (ties with m₀ left out). This is the one-sided p for 'greater'; for 'less' the sum runs from 0 to S; two-sided, it is twice the smaller of the two tails, capped at 1.

Order-statistic interval for the median

[x(k), x(N−k+1)],coverage 1−2P(Bin(N,12)≤k−1)\left[x_{(k)},\ x_{(N-k+1)}\right],\quad \text{coverage } 1 - 2P\left(\mathrm{Bin}(N, \tfrac12) \le k - 1\right)

x_(k) the k-th smallest of all N values, k = qbinom(α/2, N, 1/2); the coverage shown is the interval's achieved level, at least 1 − α whenever N is large enough (N ≥ 6 at 95%).

Alternatives

  • Wilcoxon Signed-Rank Test (Wilcoxon Signed-Rank Test). The values or differences are roughly symmetric about their center: it also uses how big they are and so has more power. On clearly lopsided values it no longer tests the median, so keep the sign test there.
  • One-Sample t-Test (One-Sample t-Test) or Paired t-Test (Paired t-Test). The question is about the mean and the values are roughly normal or numerous.

Worked example

Scenario

Penguin body mass (342 birds with a value), m₀ = 4000 g, two-sided, α = 0.05.

Result

172 above, 165 below, 5 equal to 4000 (left out); S = 172 of n = 337, exact binomial p = 0.7438; median 4050 g, 95.47% interval 3900 to 4200 g.

Interpretation

No clear evidence that the median body mass differs from 4000 g; medians from 3900 to 4200 g remain compatible with the data.

Dataset: penguins.csv

Common misconceptions

Misconception

Values equal to the hypothesized median count as half above and half below.

Correction

They carry no sign and are left out of the test, which then rests on fewer values. They still count for the median and its interval.

Misconception

A non-significant sign test shows that the median equals m₀.

Correction

It shows no clear evidence of a difference. Every median inside the interval remains compatible with the data, and with few values the test has little power.

Misconception

The Wilcoxon signed-rank test is a more powerful sign test, so it is the better choice whenever both can be run.

Correction

It is more powerful only when the values are roughly symmetric about their middle. On skewed values it tests a different center, so the two can disagree: on penguin body mass against 4,000 g the sign test gives p = .744 and the Wilcoxon test p = .0005, because the long upper tail pulls the Wilcoxon's center above the median. For the median of skewed values, read the sign test.

Read more: Misconception: the Mann-Whitney/Wilcoxon test always compares medians

References

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §7.1.4 What are nonparametric tests?, NIST/SEMATECH (2012).