Tutorials › VEE Mathematical Statistics › Median Ties and Symbol Assignment in Runs Tests

VEE Mathematical Statistics · Rank-Based and Distribution-Free Tests · Tutorial 875 of 880

Median Ties and Symbol Assignment in Runs Tests

Learn to choose and report a median-tie rule, then calculate how that choice changes the binary sequence and its runs statistic.

Intermediate 12 min read

What You'll Learn

  • Define the binary symbols and runs statistic when some observations equal the chosen median.
  • Compare omitting tied observations with assigning them consistently to one side.
  • Explain when random tie assignment is defensible and what it changes.
  • Calculate the observed runs and conditional mean and variance under each coding rule.
  • Identify tie-handling choices that can invalidate or distort a runs-test conclusion.

Why Median Ties Need an Explicit Rule

A runs test for numeric data first converts each observation into one of two symbols according to whether it falls below or above a chosen median. The runs statistic is then calculated from that binary sequence. An observation exactly equal to the median has neither of those properties, so it cannot be coded without a stated rule. This matters: dropping tied observations, putting all ties on one side, or assigning them at random can produce different sequences and different numbers of runs.

The chosen rule should be set before interpreting the result and reported with the statistic. A runs test is a test of the ordering of the resulting symbols, conditional on their counts; it is not a procedure for making tied measurements distinct. In the examples below, each numeric sequence is hypothetical, no interest or mortality model is involved, and the null model is that the observed categories occur in a random order.

Definition: Choose a reference median \(m\). An observation \(x_i\) is above the median if \(x_i>m\), below the median if \(x_i<m\), and tied if \(x_i=m\). A run is a maximal consecutive block of identical symbols in the coded sequence. The runs statistic \(R\) is the number of such blocks.

For a sample median, an odd-sized sample uses its middle ordered observation. For an even-sized sample, the usual sample median is the average of the two middle ordered observations; that average need not be an observed value. Thus, an even-sized sample can have no observations equal to its median, even when some of its measurements are tied with one another. If the reference is an externally specified benchmark instead, use that benchmark and state it.

Three Defensible Ways to Handle Ties

RuleHow to code tiesWhat the runs statistic describes
Omit tiesDelete tied observations, then retain the order of the remaining symbols.The order of the observations strictly above and below the median. Observations on either side of a deleted tie become adjacent.
Assign all ties to one sideUse a fixed rule such as “at or above” versus “below,” or “above” versus “at or below.”The order of the two categories defined by that particular cutoff rule.
Randomly assign tiesUse an independent random choice for each tied observation, according to a stated procedure.The order of a randomized binary coding, not solely the order of strict above-median and below-median observations.

Omitting ties is often a clear choice when the question is specifically whether the strictly above- and below-median observations are randomly ordered. Deletion can join two observations that were not adjacent in the original sequence, so the resulting \(R\) refers to the reduced sequence. It also reduces the sample size. If deletion leaves only one category, there is no informative two-category runs test.

Assigning ties consistently is also defensible when the rule is fixed without regard to the order of the observations. For example, “at or above \(m\)” versus “below \(m\)” defines two categories using the measurement and the same threshold for every observation. It is not equivalent to omitting ties: it changes both the category counts and potentially the sequence of runs. Random assignment can be used when a protocol specifically calls for it, but the randomization method should be stated, and the resulting test incorporates that extra random choice.

Runs Calculations After a Coding Rule Is Fixed

Once a rule has produced a binary sequence, let \(n_+\) and \(n_-\) be the counts of its two symbols, and let \(n=n_++n_-\). Under the null model that all orderings of these symbols with these counts are equally likely, and when both counts are positive, the conditional mean and variance of \(R\) are:

$$ E[R]=1+\frac{2n_+n_-}{n} $$
$$ \operatorname{Var}(R)= \frac{2n_+n_-\left(2n_+n_- - n\right)} {n^2(n-1)} $$

These formulas use the counts after tie handling, not the original sample size. If all observations have the same symbol, \(R=1\) with probability 1, so the two-category formulas do not give a useful test. If the counts are small, an exact runs distribution is generally preferable to a normal approximation; the coding rule does not remove that usual consideration.

Justification of the mean: In a random ordering with fixed counts, \(R\) equals one plus the number of adjacent pairs that change symbol. For any one of the \(n-1\) adjacent positions, the probability of a change is $$ \frac{n_+}{n}\frac{n_-}{n-1} +\frac{n_-}{n}\frac{n_+}{n-1} =\frac{2n_+n_-}{n(n-1)}. $$ Adding the expected changes over the \(n-1\) positions gives \(E[R]=1+(n-1)\frac{2n_+n_-}{n(n-1)}=1+\frac{2n_+n_-}{n}\). This argument applies after coding, conditional on the resulting symbol counts.

Worked Example: One Sequence, Three Tie Rules

A hypothetical sensor reports the ordered readings \(8,5,10,5,2,9,5,1,7\). Use the sample median and calculate \(R\) after (a) omitting ties, (b) assigning ties to the above-or-equal category, and (c) assigning ties to the below-or-equal category. For each coding, also calculate the conditional mean of \(R\).

Method and median. The sorted readings are \(1,2,5,5,5,7,8,9,10\), so the middle reading and sample median are \(m=5\). The original sequence has ties at positions 2, 4, and 7.

(a) Omit ties. The retained readings are \(8,10,2,9,1,7\), giving the symbols \(+,+,-,+,-,+\). Counting blocks gives \(R=5\): the runs are \(++\), \(-\), \(+\), \(-\), and \(+\). Thus \(n_+=4\), \(n_-=2\), and \(n=6\). The conditional mean is \(E[R]=1+2(4)(2)/6=1+16/6=11/3\), or about \(3.6667\).

(b) Assign ties above. Code \(x_i\geq5\) as \(+\), and \(x_i<5\) as \(-\). The full sequence becomes \(+,+,+,+,-,+,+,-,+\). Its runs are \(++++\), \(-\), \(++\), \(-\), and \(+\), so \(R=5\). Here \(n_+=7\), \(n_-=2\), and \(n=9\), giving \(E[R]=1+2(7)(2)/9=37/9\), or about \(4.1111\).

(c) Assign ties below. Code \(x_i>5\) as \(+\), and \(x_i\leq5\) as \(-\). The sequence is \(+,-,+,-,-,+,-,-,+\). Its runs are \(+\), \(-\), \(+\), \(--\), \(+\), \(--\), and \(+\), so \(R=7\). Now \(n_+=4\), \(n_-=5\), and \(n=9\), giving \(E[R]=1+2(4)(5)/9=49/9\), or about \(5.4444\).

Check. The reported run counts are 5, 5, and 7, respectively, and the conditional means use the counts for each rule. The statistic is not determined by the numeric readings alone until the tie rule is specified. A common mistake would be to remove the ties in every case and then use the original sample size of 9; the correction is to form the sequence required by the chosen rule and use its actual \(n\).

What Happens When Ties Are Randomly Assigned?

Random assignment is not the same as placing every tie on the same side. To illustrate, suppose each tied observation is independently assigned either symbol with probability \(1/2\), using a fair random choice. The realized sequence and its counts depend on those choices. The usual conditional runs formulas apply to the realized binary sequence under the random-order null, but a different set of random tie assignments could produce a different \(R\). Consequently, report the tie-assignment procedure and, if relevant, the randomization used.

Worked Example: A Random Assignment Can Change the Observed Runs

A hypothetical ordered batch has readings \(3,5,4,5,8,5,2,7,5,9,6\). Its sample median is \(5\). Omit no readings. Suppose a pre-specified independent random tie-breaking procedure produces \(+\) at tied positions 2 and 6, and \(-\) at tied positions 4 and 9. Code all non-tied readings by their strict relation to 5. Find the sequence, \(R\), and the conditional mean and variance.

Method. Sorting the observations gives \(2,3,4,5,5,5,5,6,7,8,9\), confirming the median \(m=5\). The non-tied readings at positions 1, 3, 5, 7, 8, 10, and 11 code as \(-,-,+,-,+,+,+\), respectively. Applying the stated tie choices gives the complete sequence \(-,+,-,-,+,+,-,+,-,+,+\).

Count the runs. The blocks are \(-\), \(+\), \(--\), \(++\), \(-\), \(+\), \(-\), and \(++\). Therefore \(R=8\). There are six plus signs and five minus signs, so \(n_+=6\), \(n_-=5\), and \(n=11\).

Calculate the conditional moments. \(E[R]=1+2(6)(5)/11=71/11\), or about \(6.4545\). The variance is \[ \operatorname{Var}(R)=\frac{2(6)(5)\{2(6)(5)-11\}}{11^2(10)} =\frac{60(49)}{1210} =\frac{294}{121}, \] or about \(2.4298\).

Check and limitation. The sequence contains 11 symbols and eight blocks, and the symbol counts sum to 11. These calculations describe the realized random coding. A different set of tie-breaking choices could change the sequence, counts, and runs statistic; randomization does not establish that the original tied readings were genuinely above or below the median.

Common Mistakes and Reporting

  • Leaving ties uncoded. A sequence containing a third symbol is not the ordinary two-symbol runs sequence. State whether ties are deleted, assigned, or randomized before counting runs.
  • Using the wrong denominator. After omitting ties, calculate \(n\), \(n_+\), and \(n_-\) from the retained observations. Do not put the original sample size into the conditional formulas.
  • Forgetting that deletion joins neighbors. If a tied observation is deleted, the symbols on its two sides become adjacent in the reduced sequence. Count runs in that reduced sequence, not in the original sequence with gaps.
  • Choosing a rule after inspecting the runs. Selecting whichever tie rule produces the preferred conclusion undermines the test. Use a rule fixed in advance, or present the alternatives as a sensitivity analysis without choosing among them based on the result.
  • Confusing a threshold convention with random assignment. “At or above” is a consistent classification rule; independent random tie-breaking adds a random step. They produce different data codings and should not be described interchangeably.

A concise report identifies the reference median, the tie rule, the resulting \(n_+\) and \(n_-\), and the observed \(R\). If conclusions differ under reasonable tie rules, that sensitivity is part of the result: the evidence about ordering depends on how median ties are treated. This is especially important for rounded or discrete measurements, where many observations can equal the median.

Key takeaway: Ties at the chosen median have no automatic binary symbol. Fix and report a defensible rule, construct the corresponding sequence, and calculate the runs statistic and its reference quantities from that coded sequence.

Check Your Understanding

For each problem, state the tie rule used before counting runs.

  1. A sample is \(2,4,4,6,4,8,1\), and the reference is its sample median. Omit ties. What is the reduced symbol sequence and its number of runs? (Answer: \(--+\), \(R=2\).)
  2. A sequence is \(5,7,7,9,7,10,6,11,7\), with sample median 7. Code \(x_i\geq7\) as \(+\) and \(x_i<7\) as \(-\). Give \(R\), \(n_+\), and \(n_-\). (Answer: \(R=4\), \(n_+=7\), \(n_-=2\).)
  3. The sequence is \(4,6,5,6,8,3,6,9\), with specified reference median \(m=6\). Omit ties and give the reduced sequence and \(R\). (Answer: \(--+-+\), \(R=4\).)
  4. After a stated tie rule, a sequence has \(n_+=4\) and \(n_-=3\). Calculate the conditional mean and variance of \(R\). (Answer: \(E[R]=31/7\approx4.4286\), \(\operatorname{Var}(R)=68/49\approx1.3878\).)
  5. For the sequence \(3,5,4,5,8,5,2,7,5,9,6\), the median is 5. A random tie rule gives \(+\) at positions 2 and 6 and \(-\) at positions 4 and 9. Find the observed \(R\) and conditional mean. (Answer: \(R=8\), \(E[R]=71/11\approx6.4545\).)
Clinical Biostats