15.2 Runs Test

Michael Sullivan

2023-08-30

install.packages('randtests')

library(randtests)

The runs test in the randtests package requires a numeric vector. If your data is non-numeric (as in Example 3 from Section 15.2), convert the non-numeric data to numeric data. For example, let -1 represent males and 1 represent females.

data <- c(-1, -1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1)

Now that the data is entered, use the runs.test function. Always set the threshold to 0 in this test. The default threshold value used is the sample median which gives the special case of this test by determining values above or below the median.

runs.test(data, threshold=0)

##
##  Runs Test
##
## data:  data
## statistic = 0.20292, runs = 8, n1 = 5, n2 = 10, n = 15, p-value =
## 0.8392
## alternative hypothesis: nonrandomness