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.

1 | ```
rank.test(x)
``` |

`x` |
a numeric vector or univariate time series. |

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:

*H0*: the data series is i.i.d. (not trending)

*H1*: the data series is not i.i.d. (trending)

A list with class "htest" containing the following components:

`statistic` |
the value of the test statistic. |

`p.value` |
the p-value of the test. |

`method` |
a character string indicating what type of test was performed. |

`data.name` |
a character string giving the name of the data. |

`pairs` |
the number of increasing pairs counted in the data series. |

`n` |
the number of points in the data series. |

`mu` |
The expected number of increasing pairs that would be seen in an i.i.d. series. |

`sigma` |
The standard deviation of the number of increasing pairs that would be seen in an i.i.d. 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.

Missing values are not handled.

Points followed by a point having the exact same value are removed from the data series before computing the test statistic.

This test is useful for detecting linear trends in data series.

Andrew Hart and Servet Mart<ed>nez

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`

1 2 3 |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

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.