Description Usage Arguments Details Value Author(s) Examples

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.

1 | ```
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

1 2 3 4 5 6 |

```
Attaching package: 'TSA'
The following objects are masked from 'package:stats':
acf, arima
The following object is masked from 'package:utils':
tar
Call:
lm(formula = tempdub ~ month.)
Residuals:
Min 1Q Median 3Q Max
-8.2750 -2.2479 0.1125 1.8896 9.8250
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 16.608 0.987 16.828 < 2e-16 ***
month.February 4.042 1.396 2.896 0.00443 **
month.March 15.867 1.396 11.368 < 2e-16 ***
month.April 29.917 1.396 21.434 < 2e-16 ***
month.May 41.483 1.396 29.721 < 2e-16 ***
month.June 50.892 1.396 36.461 < 2e-16 ***
month.July 55.108 1.396 39.482 < 2e-16 ***
month.August 52.725 1.396 37.775 < 2e-16 ***
month.September 44.417 1.396 31.822 < 2e-16 ***
month.October 34.367 1.396 24.622 < 2e-16 ***
month.November 20.042 1.396 14.359 < 2e-16 ***
month.December 7.033 1.396 5.039 1.51e-06 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.419 on 132 degrees of freedom
Multiple R-squared: 0.9712, Adjusted R-squared: 0.9688
F-statistic: 405.1 on 11 and 132 DF, p-value: < 2.2e-16
$pvalue
[1] 0.216
$observed.runs
[1] 65
$expected.runs
[1] 72.875
$n1
[1] 69
$n2
[1] 75
$k
[1] 0
```

TSA documentation built on July 2, 2018, 1:04 a.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.