runtest tests whether the observations of x
are serially
independent i.e. whether they occur in a random order, by counting
how many runs there are above and below a threshold. By default, the median
is used as the threshold. A small number of runs indicates positive serial
correlation; a large number indicates negative serial correlation.
runs_test(x, drop = FALSE, split = FALSE, mean = FALSE, threshold = NA)
x
runs_test
returns an object of class "runs_test"
.
An object of class "runs_test"
is a list containing the
following components:
Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric Statistical Procedures, 4th edition. : Chapman & Hall/CRC.
Edgington, E. S. 1961. Probability table for number of runs of signs of first differences in ordered series. Journal of the American Statistical Association 56: 156–159.
Madansky, A. 1988. Prescriptions for Working Statisticians. New York: Springer.
Swed, F. S., and C. Eisenhart. 1943. Tables for testing randomness of grouping in a sequence of alternatives. Annals of Mathematical Statistics 14: 66–87.
reg <- lm(mpg ~ disp, data = mtcars) runs_test(residuals(reg))#> Runs Test #> Total Cases: 32 #> Test Value : -0.9630856 #> Cases < Test Value: 16 #> Cases > Test Value: 16 #> Number of Runs: 11 #> Expected Runs: 17 #> Variance (Runs): 7.741935 #> z Statistic: -2.156386 #> p-value: 0.03105355runs_test(residuals(reg), drop = TRUE)#> Runs Test #> Total Cases: 32 #> Test Value : -0.9630856 #> Cases < Test Value: 16 #> Cases > Test Value: 16 #> Number of Runs: 11 #> Expected Runs: 17 #> Variance (Runs): 7.741935 #> z Statistic: -2.156386 #> p-value: 0.03105355runs_test(residuals(reg), split = TRUE)#> Runs Test #> Total Cases: 32 #> Test Value : -0.9630856 #> Cases < Test Value: 16 #> Cases > Test Value: 16 #> Number of Runs: 11 #> Expected Runs: 17 #> Variance (Runs): 7.741935 #> z Statistic: -2.156386 #> p-value: 0.03105355runs_test(residuals(reg), mean = TRUE)#> Runs Test #> Total Cases: 32 #> Test Value : -1.12757e-16 #> Cases < Test Value: 19 #> Cases > Test Value: 13 #> Number of Runs: 11 #> Expected Runs: 16.4375 #> Variance (Runs): 7.189642 #> z Statistic: -2.027896 #> p-value: 0.04257089runs_test(residuals(reg), threshold = 0)#> Runs Test #> Total Cases: 32 #> Test Value : 0 #> Cases < Test Value: 19 #> Cases > Test Value: 13 #> Number of Runs: 11 #> Expected Runs: 16.4375 #> Variance (Runs): 7.189642 #> z Statistic: -2.027896 #> p-value: 0.04257089