Performs an approximate Cox-Stuart or Difference-Sign trend test.
trend.test(x, method = c("cox.stuart", "diff.sign"), plot = FALSE)
a numeric vector or univariate time series.
test method. The default is
method = "cox.stuart".
a logical value indicating to display the plot of data.
The default is
A list with class "
htest" containing the following components:
- a character string giving the names of the data.
- the type of test applied.
- a character string describing the alternative hypothesis.
- the p-value for the test.
- the value of the test statistic with a name describing it.
Cox-Stuart or Difference-Sign test is used to test whether the data have a
increasing or decreasing trend. They are useful to detect the linear or nonlinear trend.
The Cox-Stuart test is constructed as follows.
For the given data $x,...,x[t]$, one can divide them into two sequences with
equal number of observations cutted in the midpoint and then take the paired difference,
i.e., $D = x[i] - x[i+c], i = 1, ..., floor(n/2)$, where $c$ is the index of
midpoint. Let $S$ be the number of positive or negative values in $D$. Under the
null hypothesis that data have no trend, for large $n$ = length(x), $S$ is
approximately distributed as $N(n/2,n/4)$, such that one can immediately obtain
the p value. The exact Cox-Stuart trend test can be seen in
The Difference-Sign test is constructed as the similar way as Cox-Stuart test. We first
let $D = x[i] - x[i - 1]$ for $i = 2, ..., n$ and then
count the number of positive or negative values in $D$, defined as $S$.
Under the null hypothesis, $S$ is approximately distributed as
$N((n-1)/2,(n+1)/12)$. Thus, p-value can be calculated based on the null distribution.
D.R. Cox and A. Stuart (1955). Some quick sign tests for trend in location
and dispersion. Biometrika, Vol. 42, pp. 80-95.
P.J. Brockwell, R.A. Davis, Time Series: Theory and Methods, second ed.,
Springer, New York, 1991. (p. 37)
x <- rnorm(100)
trend.test(x,plot = TRUE) # no trend
x <- 5*(1:100)/100
x <- x + arima.sim(list(order = c(1,0,0),ar = 0.4),n = 100)
trend.test(x,plot = TRUE) # increasing trend