run_randtests.RdRuns a suite of nonparametric randomness tests from the randtests
package.
run_randtests(x, alter = "two.sided", na_rm = TRUE, alpha = 0.05)A numeric vector containing the sequence to test for randomness.
Alternative hypothesis. One of "two.sided",
"less", "greater", "left.sided", or
"right.sided". The values "less" and "greater" are
mapped internally to "left.sided" and "right.sided",
respectively.
Logical. If TRUE, missing values are removed before
testing. If FALSE, the function throws an error when x
contains missing values.
Significance level used to determine the Reject_H0
column. Default is 0.05.
A data.frame with one row per randomness test and the following
columns:
Short name of the randomness test.
Method name returned by the underlying randtests
function.
Alternative hypothesis used in the test.
Number of non-missing observations tested.
Observed test statistic.
Name of the test statistic, when available.
Expected value of the statistic under the null hypothesis, when available.
Variance of the statistic under the null hypothesis, when available.
Raw p-value returned by the test.
Error message if the test failed; otherwise NA.
Logical value indicating whether the null hypothesis is
rejected at level alpha using the raw p-value.
The overall null hypothesis is that the input sequence is randomly ordered, independent, and has no systematic trend or non-random structure. Each test evaluates this null hypothesis from a different perspective, such as runs, ranks, signs of differences, turning points, or monotonic trend.
The null hypothesis for the full battery is:
$$H_0: the sequence is randomly ordered, independent, and contains no systematic pattern.$$
The tests included are:
Tests whether the observations are randomly ordered, with no serial dependence or trend.
Tests whether there is no monotonic trend in the sequence.
Tests whether successive differences show no systematic upward or downward tendency.
Tests whether the sequence is randomly ordered around a reference point, typically the median.
Tests whether the number of local peaks and valleys is consistent with randomness.
Tests whether the ordering of the observations is random, with no trend.
The Reject_H0 column indicates whether each test rejects its null
hypothesis at the chosen alpha level using the raw p-value returned by
that test.
library(randngen)
n <- 10000
seed <- 12345
lcg_digits <- lcg(n=n, seed=seed)
run_randtests(lcg_digits)
#> Test Method Alternative N Statistic
#> 1 Bartels Rank Bartels Ratio Test two.sided 10000 -0.9519354
#> 2 Cox Stuart Cox Stuart test two.sided 10000 2491.0000000
#> 3 Difference Sign Difference Sign Test two.sided 10000 0.3290732
#> 4 Runs Test Runs Test two.sided 10000 1.0600530
#> 5 Turning Point Turning Point Test two.sided 10000 -1.9291642
#> 6 Rank Test Mann-Kendall Rank Test two.sided 10000 0.2980996
#> Statistic_Name Expected_Mu Variance P_Value Error Reject_H0
#> 1 statistic 2.0 3.999440e-04 0.34112974 <NA> FALSE
#> 2 statistic NA NA 0.81001047 <NA> FALSE
#> 3 statistic 4999.5 8.334167e+02 0.74210036 <NA> FALSE
#> 4 statistic 5001.0 2.499750e+03 0.28912048 <NA> FALSE
#> 5 statistic NA NA 0.05371048 <NA> FALSE
#> 6 statistic 24997500.0 2.778194e+10 0.76562711 <NA> FALSE