Test for a trend in a data series by comparing the number of increasing pairs in the series with the number expected in an i.i.d. series.
rank.test(x)
A list with class "htest" containing the following components:
the value of the test statistic.
the p-value of the test.
a character string indicating what type of test was performed.
a character string giving the name of the data.
the number of increasing pairs counted in the data series.
the number of points in the data series.
The expected number of increasing pairs that would be seen in an i.i.d. series.
The standard deviation of the number of increasing pairs that would be seen in an i.i.d. series.
a numeric vector or univariate time series.
If the spgs shared object was successfully compiled with support for a 64-bit unsigned integer type, then the following line should yield the value 0:
rank.test(1:92683)$pairs-2^32-55607
if not, then the package is only using 32-bit integer arithmetic for computing
the rank test statistic and this will restrict rank.test
to analysing
series whose length is at most 92682. In this case, attempting to apply
rank.test
to a series longer than 92682 will result in a warning about an
integer overflow having occurred and the results of the test should not
be trusted.
Andrew Hart and Servet Martínez
Perform a test for trend based on the number of increasing ordered pairs in a data series. Consider pairs of the form (x(i), x(j)), where i<j. An increasing pair is any such pair for which x_i<x_j. This function counts the number of increasing pairs in the data, standardises it to have mean 0 and variance 1 and asymptotically tests it against a standard normal distribution. the test statistic is:
R = (pairs-mu)/sigma, where
pairs is the number of increasing pairs in the data,
mu = n*(n-1)/4,
sigma = sqrt(n*(n-1)*(2*n+5)/72) and
n is the number of data points in the series.
The test is set up as follows:
\(H_0\): the data series is i.i.d. (not trending)
\(H_1\): the data series is not i.i.d. (trending)
Brockwell, Peter J., Davis, Richard A. (2002) Introduction to Time Series and Forecasting. Springer Texts in Statistics, Springer-Verlag, New York.
diffsign.test
, turningpoint.test
, lb.test
,
markov.test
, diid.test
#Generate an IID standard normal sequence
n <- rnorm(1000)
rank.test(n)
Run the code above in your browser using DataLab