Runs Test for Randomness
Perform the runs test for randomness of a numeric sequence.
runs.test(x, exact = FALSE, alternative = c("two.sided", "less", "greater"))
x |
a numeric vector of data values. |
exact |
|
alternative |
indicates the alternative hypothesis and must be one of |
Runs test examines the randomness of a numeric sequence x by studying the frequency of runs R. Generally, every numeric sequence can be transformed into dichotomous (binary) data defined as 0 and 1 by comparing each element of the sequence to its median (default threshold). Given m 0 and n 1, the runs R is defined as a series of similar responses and has a statistical distribution. See Wald, A. and Wolfowitz, J. (1940) for more details of this distribution. Based on the known distribution, the exact p-value can be computed for the data with small sample size. When the sample size is large, one can use the normal approximation (argument exact = TRUE
) with mean 2mn/(m + n) +1 and variance 2mn(2mn - m - n)/((m + n)^2*(m + n - 1)). The null of randomness is tested against the "under-mixing" trend and "over-mixing" trend by using alternative "less"
and "greater"
. Missing values have been removed.
A list with class "htest" containing the following components:
data.name |
a character string giving the names of the data. |
method |
the type of test applied. |
alternative |
a character string describing the alternative hypothesis. |
statistic |
the value of the test statistic with a name describing it. |
p.value |
the p-value for the test. |
When the runs R is large, the exact p-value cannot be computed as the combination in the distribution function of R will be infinity. Please use argument "exact = F"
or "exact = FALSE"
in this case.
Debin Qiu <debinqiu@uga.edu>
Wald, A. and Wolfowitz, J. (1940). On a test whether two samples are from the same population. Ann. Math Statist. 11, 147-162.
Wu, X. and Zhao, B. (2013). Nonparametric Statistics (Fourth Edition ed). China Statistics Press. pp. 40-42.
x <- rnorm(100) runs.test(x) y <- c(12.85, 13.29, 12.41, 15.21, 14.23, 13.56) runs.test(y, exact = TRUE)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.