Skip to contents

Performs a nonparametric runs test to evaluate whether a sequence of residuals is randomly distributed around a reference mean. The function also computes three–sigma control limits used to identify potential residual outliers.

Usage

do_runs_test(x, type = NULL, mixing = "two.sided")

Arguments

x

Numeric vector of residuals.

type

Character string specifying the assumed mean of the residuals. If "resid" (default), the residual mean is assumed to be zero. Otherwise, the empirical mean of x is used.

mixing

Character string specifying the alternative hypothesis for the runs test:

  • "two.sided" – tests for both positive and negative autocorrelation (default).

  • "less" – left-tailed test detecting positive autocorrelation.

Value

A list containing:

  • sig3lim – Numeric vector of length two giving the lower and upper three–sigma control limits for the residuals.

  • p.runs – P-value from the runs test for randomness.

A small p-value (e.g., < 0.05) indicates evidence that the residual sequence is not random and may exhibit autocorrelation or other systematic patterns.

Details

This implementation is adapted from diagnostics used in Stock Synthesis (SS3). The runs test evaluates whether residuals exhibit non-random structure (e.g., positive or negative autocorrelation).