eda_runs_test: Wald–Wolfowitz Runs Test for Randomness
Description
Applies the Wald–Wolfowitz runs test to a numeric vector in order to assess
whether it behaves as a random sequence. The test statistic and p-value
is computed using the number of runs (sequences of values above or below the
median). Under the null hypothesis, the data is random. The runs test can be
used to assess whether the residuals of a nonstationary model are random,
indicating the suitability of the assumed nonstationary structure (e.g., linear).
Usage
eda_runs_test(values, years, alpha = 0.05)
Value
A list containing the test results, including:
values: The values argument.
years: The years argument.
alpha: The significance level as specified in the alpha argument.
null_hypothesis: A string describing the null hypothesis.
alternative_hypothesis: A string describing the alternative hypothesis.
n: The length of the input vector after removing the median.
runs: The number of runs in the transformed sequence of residuals.
statistic: The runs test statistic, computed using runs and n.
p_value: The p-value derived from the normally distributed test statistic.
reject: If TRUE, the null hypothesis was rejected at significance alpha.
Arguments
values
A numeric vector of values to check for randomness.
years
Numeric vector of observation years corresponding to data.
Must be the same length as data and strictly increasing.
alpha
Numeric scalar in \([0.01, 0.1]\). The significance
level for confidence intervals or hypothesis tests. Default is 0.05.
References
Wald, A. and Wolfowitz, J. (1940). On a test whether two samples are from the
same population. Annals of Mathematical Statistics, 11(2), 147–162.