runs | R Documentation |
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.
runs(x,k=0)
x |
time series |
k |
the value above or below which runs are counted; default is zero, so data is assumed to have zero median |
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.
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 |
Kung-Sik Chan
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.