Learn R Programming

snpar (version 1.0)

runs.test: Runs Test for Randomness

Description

Perform the runs test for randomness of a numeric sequence.

Usage

runs.test(x, exact = FALSE, alternative = c("two.sided", "less", "greater"))

Arguments

x
a numeric vector of data values.
exact
TRUE or FALSE (default) indicating whether an exact p-value should be computed. See 'Details' for the meaning of TRUE.
alternative
indicates the alternative hypothesis and must be one of "two.sided" (default), "less", or "greater". See 'Details' for the meanings of the possible values.

Value

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.

Warning

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.

Details

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.

References

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.

Examples

Run this code
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)

Run the code above in your browser using DataLab