randomizeBE (version 0.3-5)

runs.pvalue: 2-sided p-value of the runs test

Description

The function calculates the 2-sided p-value of the Wald-Wolfowitz runs test after dichotomizing the input vector

Usage

runs.pvalue(y, pmethod = c("exact", "normal", "cc"))

Value

Numeric p-value of the 2-sided test.

Arguments

y

Numeric vector of data values.

pmethod

A character string describing the method for the p-value calculation of the runs test.

"exact" chooses the calculation via exact distribution of the # of runs.
"normal" denotes the normal approximation like the function(s) runs.test() of the packages tseries or lawstat.
"cc" chooses the continuity correction to the large sample approximation like in the statistical software SPSS.

Author

D. Labes
adapted from runs.test() package lawstat
Authors: Wallace Hui, Yulia R. Gel, Joseph L. Gastwirth, Weiwen Miao
and from runs.test() package tseries
Author: A. Trapletti

Details

This function calculates the 2-sided p-value of the runs.test.
The large sample approximations are an adaption from the codes for runs.test() found in the R-packages lawstat and tseries.
The aim of this own was to avoid the heavy footprint of both packages for this small package.

The user can choose the application of a continuity correction to the normal approximation like a SAS implementation http://support.sas.com/kb/33/092.html uses or like SPSS if n<50.

The exact distribution of runs and the p-value based on it are described in the manual of SPSS "Exact tests" to be found f.i. http://www.sussex.ac.uk/its/pdfs/SPSS_Exact_Tests_21.pdf.
If pmethod="exact" is chosen and n>30 and n1>12 and n2>12 (see pruns.exact) the continuity corrected version of the normal approximation is used to save time and memory.

See Also

pruns.exact

Examples

Run this code
# alternating sequence 1,2,1,2 ...
# maybe seen as numeric representation of 'TR','RT' ...
# and is used in that way here in this package
x <- rep(c(1, 2), 6)
runs.pvalue(x, pmethod="normal")
# should give 0.002464631
# exact p-value
runs.pvalue(x, pmethod="exact")
# should give 0.004329004
# 
# same for 3 numbers (numeric representation of 3 sequences)
x <- rep(c(1, 2, 3),4)
runs.pvalue(x, pmethod="normal")
# should give 0.2502128
# i.e. is seen as compatible with a random sequence!
# exact p-value, default i.e. must not given exolicitely
runs.pvalue(x)
# should give 0.3212121
# i.e. is seen even more as compatible with a random sequence!

Run the code above in your browser using DataLab