Learn R Programming

lawstat (version 3.2)

runs.test: Runs Test for Randomness

Description

This function performs the runs test for randomness. Users can choose whether to plot the correlation graph or not, and whether to test against two-sided, negative or positive correlation. NAs from the data are omitted.

Usage

runs.test(y, plot.it = FALSE, alternative = c("two.sided", 
          "positive.correlated", "negative.correlated"))

Arguments

y

a numeric vector of data values.

plot.it

logical flag. If 'TRUE', then the graph will be plotted. If 'FALSE', then it is not plotted.

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "negative.correlated" or "positive.correlated".

Value

A list with the following components.

statistic

the value of the standardized Runs statistic.

p.value

the p-value for the test.

data.name

a character string giving the names of the data.

alternative

a character string describing the alternative hypothesis.

Details

On the graph observations which are less than the sample median are represented by letter "A" in red color, and observations which are greater or equal to the sample median are represented by letter "B" in blue color.

References

Mendenhall, W (1982), Statistics for Management and Economics, 4th Ed., 801-807, Duxbury Press, Boston.

See Also

bartels.test

Examples

Run this code
# NOT RUN {
##Simulate 100 observations from an autoregressive model 
## of the first order (AR(1))
y = arima.sim(n = 100, list(ar = c(0.5)))

##Test y for randomness
runs.test(y)

## Sample Output
##
##        Runs Test - Two sided
## data: y
## Standardized Runs Statistic = -2.8142, p-value = 0.004889
# }

Run the code above in your browser using DataLab