Learn R Programming

ffaframework (version 0.1.1)

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.

See Also

plot_runs_test(), eda_sens_trend()

Examples

Run this code
data <- rnorm(n = 100, mean = 100, sd = 10)
years <- seq(from = 1901, to = 2000)
sens_trend <- eda_sens_trend(data, years)
eda_runs_test(sens_trend$residuals, years)

Run the code above in your browser using DataLab