4. Tests for randomness Below only a few out of many frequently used tests are briefly described. See [BD93, §9.4] for more details. 4.1. Five tests for IID sequence. We shall describe five tests implemented in MATLAB m-file trand. Even though the tests are not primarily designed for residuals, they are often used as a secondary criterion for this purpose as well. x = [xi, . . . , x„] . . . finite sample path of time series {Xt}. All tests are constructed under the null hypothesis: Ho:{Xt}~IID(ß,a2) Each of the five testing statistics T(x) described below is asymptotically normal: T ~ AsN(0,1), which means that their distribution is close to the normal one N(0, 1) for large sample size. Thus quantiles of normal distribution are applicable for testing if n is sufficiently large: We reject Ho at significance level a (by default usually a = 0.05 ) if |T(a;)| > ui_a/2 where u1_a/2 is the (1 — j)-quantile of normal distribution N(0,1) («0.975 k 1.96 for the default a = 0.05). Thus the risk of rejecting the hypothesis with data which are IID is very small: 100a%. For smaller sample sizes exact quantiles of the appropriate statistics should be used instead of Ui_a/2- They can be found in specialized Statistical Tables, or suitable approximate formulas may be used. However for users of trand these implementation details are not important. 39 Be careful when using the tests: some of them are not appropriately sensitive to a certain type of randomness violation: for example the tests No. 1 and 2 show often nearly no response to oscillatory deterministic component violating white noise. The best method is to draw conclusion not from an individual test, but from all of them as a whole: if none of the tests rejects randomness, you can believe Ho to be true. 4.1.1. The Difference-Sign Test. Ax := [x2 — x\, . . . , x„ — x„-i] . . . differenced series m ... the number of nonzero differences in Ax k < m ... the number of positive differences (observation of random variable K) If Ho is valid then it holds E(/0 = y, a(K] m + 2 12 T(x) E(fe) a(k) 4.1.2. A Test Based on Turning Points. Ax, m ... as of 4.1.1 Sx ... length m subvector of all nonzero differences in Ax r < m — 1 ... the number of turning points in x, i.e. the number of neighbor entries in Sx having opposite sign (observation of random variable R) If Ho is valid then it holds E(R) 2(ra ■ a(R) 16(m + l) 9ČT ■29 T(x) E(r) a(r) 4.1.3. A Test Based on Kendall Coefficient. the number of pairs (xs, xt) such that xs < x t for s < t Kendall coefficient (observation of ran- 1,1]) n(n — 1) dorn variable T with values in the range If Ho is valid then it holds E(T) = 0, 30 In the case of a short sample n < 30 exact critical values rs(a) related to the exact distribution of T should be used: jP(|iP| > rs(a)) < a. Then \p\ ^ f s [a) => Ho is rejected at level a 4.1.5. Median Test, x ... median of x, alias mid value in the sequence yi < j/2 < • • • < y„ as of 4.1.4 m := card M- = card M where M~ := {j'| ajj < í} and M+ := {j | xj > x} s ... number of groups of adjoining elements x3 which fall completely either to M~ or to M , ignoring all x3 equal to median x (observation of random variable S) NOTE: It may sometimes happen that M~ and M do not have exactly the same cardinality (several mid values being equal to median). In such a case we change some of the mid values by a small quantity to balance the cardinality of both sets. If Ho is valid then it holds T(x) = s-(m + l) for n > loo y/m(m- I)/(2m - 1) In the case of a short sample n < 100 again exact critical values of S found in specialized Statistical Tables should be used. The testing procedure is then similar to that of 4.1.4. 4.2. Three Tests for White Noise. We shall describe three tests which test data for being sample from white noise. In contrast with the tests of section 4.1, these tests are suitable also for testing residuals from fitted models. The tests are based on sample autocorrelation or partial autocorrelation function: x = [xi, . . . , xn] . . . finite sample path of time series {Xt} P K = [pi i • • • i Pk] ■ ■ ■ sample autocorrelation function from x StK = [Si, . . . , Sk] ■ ■ ■ sample partial autocorr. function from pK All tests are constructed under the null hypothesis: 42 H0 :{Xt}~ WN(0,a2) 4.2.1. The Portmanteau test. Either of the following statistics may be used, the latter being recommended by some authors as more suitable for tests on residuals: K k=l 1 ' t-^ n - k k=l For n —> oo, K —> oo, K fíä y/n, both Q and Q* have asymptotic Chi-square distribution x {K — P) with K — P degrees of freedom where P is the number of parameters in the model (P = 0 for observed data). Q(or Q ) > Xi-a(Ä' — P) =^ Ho is rejected at level a These statistics are implemented in MATLAB m-files acf, NAGacf and NAGcheck (output parameter stat). Function acf computes Q for observed data and Q* for residuals along with the corresponding (1 — a)-quantile. Analogically NAGacf is using the statistic Q and NAGcheck the statistic Q*, the latter returning p-value instead of the quantile. 4.2.2. Test based on the sample autocorrelation function. For moo the random vector pK is asymptotically A'-variate normal pK ~ AsNk(Px, V) for stationary time series fulfilling certain natural conditions ([BD93, Sec.7.2]). If the series is a white noise then V = —Ik and therefore p(l), . . . , p(K) are approximately independent and identically distributed normal random variables with zero means and variance l/n. On this basis the following asymptotic test can be applied: |p(/i)| > «i-a/2-7= f°r some h > 0 =>• Ho is rejected at level a 43 where Ui_a/2 is the (1 — j)-quantile of normal distribution N(0, 1) («0.975 ~ 1.96 for the default a = 0.05). The bounds ±1.96/^/0 are plotted by dotted line in Figures 3.7.1, 3.7.2 and 3.7.3 allowing for visual testing. A value p(h) lying outside these bounds suggests possible inconsistency of the residuals with the fitted model (or doubts on white noise assumption about observed data). However it is essential to bear in mind that approximately 5 percent of the values of p(h) can be expected to fall outside the bounds even if the fitted model is correct (or white noise hypothesis is true). 4.2.3. Test based on sample partial autocorrelation function. The procedure is the same as in 4.2.2 except that a(h) is used instead of p(h).