trend.test: Trend Test

View source: R/trendtest.R

trend.testR Documentation

Trend Test

Description

Performs an approximate Cox-Stuart or Difference-Sign trend test.

Usage

trend.test(x, method = c("cox.stuart", "diff.sign"), plot = FALSE)

Arguments

x

a numeric vector or univariate time series.

method

test method. The default is method = "cox.stuart".

plot

a logical value indicating to display the plot of data. The default is FALSE.

Details

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[1],...,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 cs.test of snpar package.

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.

Value

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

data.name

a character string giving the names of the data.

method

the type of test applied.

alternative

a character string describing the alternative hypothesis.

p.value

the p-value for the test.

statistic

the value of the test statistic with a name describing it.

Note

Missing values are removed.

Author(s)

Debin Qiu

References

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)

Examples

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

aTSA documentation built on May 29, 2024, 8:50 a.m.