runs: Runs test

View source: R/runs.R

runsR Documentation

Runs test

Description

Test the independence of a sequence of random variables by checking whether there are too many or too few runs above (or below) the median.

Usage

runs(x,k=0)

Arguments

x

time series

k

the value above or below which runs are counted; default is zero, so data is assumed to have zero median

Details

The runs test examines the data in sequence to look for patterns that would give evidence against independence. Runs above or below k are counted. A small number of runs would indicate that neighboring values are positively dependent and tend to hang together over time. On the other hand, too many runs would indicate that the data oscillate back and forth across their median of zero. Then neighboring residuals are negatively dependent. So either too few or too many runs lead us to reject independence. When applied to residuals, the runs test is useful for model diagnostics.

Value

pvalue

p-value of the test

observed.runs

observed number of runs

expected.runs

expected number of runs

n1

number of data less than or equal to k

n2

number of data above k

Author(s)

Kung-Sik Chan

Examples

data(tempdub)
month.=season(tempdub) # the period sign is included to make the printout from
# the following command clearer.
model3=lm(tempdub~month.) # intercept is automatically included so one month (Jan) is dropped
summary(model3)
runs(rstudent(model3))

TSA documentation built on July 5, 2022, 5:05 p.m.