Products & Services Industries Academia Support User Community Company

Learn more about Statistics Toolbox   

runstest - Run test for randomness

Syntax

h = runstest(x)
h = runstest(x,v)
h = runstest(x,'ud')
h = runstest(...,param1,val1,param2,val2,...)
[h,p] = runstest(...)
[h,p,stats] = runstest(...)

Description

h = runstest(x) performs a runs test on the sequence of observations in the vector x. This is a test of the null hypothesis that the values in x come in random order, against the alternative that they do not. The test is based on the number of runs of consecutive values above or below the mean of x. Too few runs indicate a tendency for high and low values to cluster. Too many runs indicate a tendency for high and low values to alternate. The test returns the logical value h = 1 if it rejects the null hypothesis at the 5% significance level, and h = 0 if it cannot. The test treats NaN values in x as missing values, and ignores them.

runstest uses a test statistic which is approximately normally distributed when the null hypothesis is true. It is the difference between the number of runs and its mean, divided by its standard deviation.

h = runstest(x,v) performs the test using runs above or below the value v. Values exactly equal to v are discarded.

h = runstest(x,'ud') performs a test for the number of runs up or down. This also tests the hypothesis that the values in x come in random order. Too few runs indicate a trend. Too many runs indicate an oscillation. Values exactly equal to the preceding value are discarded.

h = runstest(...,param1,val1,param2,val2,...) specifies additional parameters and their values. Valid parameter/value pairs are the following:

[h,p] = runstest(...) returns the p-value of the test. The output p is computed from either the test statistic or the exact distribution of the number of runs, depending on the value of the 'method' parameter.

[h,p,stats] = runstest(...) returns a structure stats with the following fields:

Examples

x = randn(40,1);
[h,p] = runstest(x,median(x))
h =
     0
p =
    0.6286

See Also

signrank, signtest

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS