7.3 Practice Problems

Problem 7.1. A machine produces items recorded as conforming (\(+\)) or not (\(-\)) in the order \[+\ +\ -\ +\ -\ -\ -\ +\ +\ +\ -\ +\ -\ -\ +\ +\ -\ -\ +\ + .\] Count \(n_1\), \(n_2\) and \(R\). Compute \(E(R)\) and \(\operatorname {var}(R)\) and test for randomness at the \(5\%\) level.

Show solution

Solution. There are \(n_1 = 11\) symbols \(+\) and \(n_2 = 9\) symbols \(-\), so \(N = 20\). Reading the sequence and marking each change of symbol gives the runs \[\{++\}\{-\}\{+\}\{---\}\{+++\}\{-\}\{+\}\{--\}\{++\}\{--\}\{++\},\] so \(R = 11\). Under \(H_0\), \[E(R) = \dfrac {2(11)(9)}{20} + 1 = 10.9,\qquad \operatorname {var}(R) = \dfrac {2(11)(9)\big (2(11)(9) - 20\big )}{20^{2}(19)} = \dfrac {198 \times 178}{7600} = 4.6374,\] so the standard deviation is \(2.1535\) and \[Z = \dfrac {11 - 10.9}{2.1535} = 0.046 .\] Since \(\left |Z\right | = 0.046 < 1.96\) we do not reject \(H_0\): there is no evidence against randomness.

The sequence looks patterned to the eye — there are visible clusters of three \(+\) and three \(-\) — and it is almost exactly what randomness predicts. That is the point of computing \(R\) rather than trusting the impression.

Problem 7.2. Explain why the runs test must be two-sided, giving a concrete sequence that has far too few runs and one that has far too many, each with \(n_1 = n_2 = 6\).

Show solution

Solution. With \(n_1 = n_2 = 6\) and \(N = 12\), \[E(R) = \dfrac {2(6)(6)}{12} + 1 = 7,\qquad \operatorname {var}(R) = \dfrac {2(6)(6)\big (72 - 12\big )}{12^{2}(11)} = 2.7273,\] so the standard deviation is \(1.6514\).

Too few runs. The sequence \(+\,+\,+\,+\,+\,+\,-\,-\,-\,-\,-\,-\) has \(R = 2\), giving \[Z = \dfrac {2 - 7}{1.6514} = -3.028 .\]

Too many runs. The sequence \(+\,-\,+\,-\,+\,-\,+\,-\,+\,-\,+\,-\) has \(R = 12\), giving \[Z = \dfrac {12 - 7}{1.6514} = +3.028 .\]

Both reject at the \(5\%\) level, and by the same margin. The first is a series that remembers its previous value — positive serial correlation — and the second one that systematically contradicts it. A one-sided test would catch one of these and be blind to the other, and both are failures of randomness.

Problem 7.3. Two samples of sizes \(12\) and \(15\) give, respectively, \(9\) and \(4\) observations above the pooled median. Construct the \(2\times 2\) table and carry out the median test. Would Kruskal–Wallis on the same data be more or less powerful, and why?

Show solution

Solution. Of the \(12\) observations in the first sample, \(9\) exceed the pooled median and \(3\) do not; of the \(15\) in the second, \(4\) exceed it and \(11\) do not. \[\begin {array}{l|cc|c} & \text {sample 1} & \text {sample 2} & \text {total}\\\hline \text {above } M & 9 & 4 & 13\\ \text {at or below } M & 3 & 11 & 14\\\hline \text {total} & 12 & 15 & 27 \end {array}\] For a \(2\times 2\) table, \[\chi ^{2} = \dfrac {N(ad - bc)^{2}}{(a+b)(c+d)(a+c)(b+d)} = \dfrac {27\big (9(11) - 3(4)\big )^{2}}{13 \times 14 \times 12 \times 15} = 6.238 .\] Against \(\chi ^{2}_{0.05,1} = 3.841\) we reject: the medians differ.

Kruskal–Wallis on the same data would be more powerful. The median test reduces every observation to a single bit — above the median or not — and discards the rest. Kruskal–Wallis keeps the full ordering, so it can distinguish a sample that sits just above the median from one far above it, and the median test cannot. Use the median test only when the data will not support ranking: censored values, or measurements recorded merely as “high” and “low”.

Problem 7.4. A series of \(60\) observations is to be tested for trend by Mann–Kendall. Describe how you would use the runs test first, and say what you would do differently depending on its outcome.

Show solution

Solution. Reduce the \(60\) observations to symbols by comparing each with the sample median, count the runs \(R\), and test as above with \(n_1 \approx n_2 \approx 30\).

If randomness is not rejected, the independence assumption behind Mann–Kendall is tenable and the ordinary test may be used as it stands.

If there are too few runs, the series is positively serially correlated: consecutive observations resemble one another, the series carries less independent information than its length suggests, and uncorrected Mann–Kendall will reject too often. Apply the Hamed–Rao variance inflation — with the factor clipped at \(1\).

If there are too many runs, the correlation is negative. The true variance of \(S\) is then smaller than the formula gives, so the uncorrected test is conservative and will simply miss some real trends. The clipped correction leaves it unchanged, which is the honest outcome: it is better to under-claim than to manufacture a trend.

One caution. A trend itself will produce clustering — early values below the median, late values above — so a runs test on the raw series may reject randomness because of the trend rather than because of serial correlation. Run it on the residuals after removing the Theil–Sen slope, which is exactly what Hamed–Rao does before computing its autocorrelations.

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.