tsTau: Kendall's Tau with Serial Dependence

Description Usage Arguments Details Value References See Also Examples

View source: R/tsTau.R

Description

Use Kendall's Tau to test for a significant trend in a time series, while accounting for potential serial dependence.

Usage

1
tsTau(x, y, tauOnly = FALSE, ...)

Arguments

x

numeric vector of times (dates, step number, etc)

y

numeric vector of value to be inspected for a trend

tauOnly

Logical, if TRUE (FALSE is default) only the Kendall's Tau is returned

...

arguments passed to cor

Details

The general approach has 3 components: estimate the linear trend, estimate the serial dependence, then estimate Kendall's Tau.

The simplest way to do this is to estimate and remove the linear trend from the data, model and remove first order autocorrelation, add the trend back into the AR residuals, then fit Kendall's Tau to the Trend+Residuals series. This is the approach described in the studies in the references section, and is implemented in the zyp package.

This function improves upon the above approach by fitting the linear trend and the serial dependence at the same time, and by considering more complex models of serial dependence (specifically, up to ARMA(2,2) models). The fitting of the ARMA model is done using the forecast::auto.arima function; if one already knows the order of the ARMA model, an equivalent result could be achieved through arima. The key to this type of model is that it is fit as a regression with ARMA residuals (see the Hyndman 2004 reference below for more details, or or this chapter in the free online text). The order of the model is limited to second order autoregressive (AR(2) component) and second order moving average (MA(2) component). Differencing, drift, and seasonality are not considered. This is partially done for speed, and partially to protect against the model soaking up too much of any nonlinear trend (because the trend we're explicitly modeling is linear, but Kendall's Tau wouldn't be needed if that was the actual trend was linear!).

Kendall::Kendall is used. The variance of the numerator in Kendall's Tau is more complex when there are ties, and changes the p-value. cor(..., method="kendall") does not make the correction.

Value

If tauOnly is TRUE, returns a length-1 numeric vector with name "tau" that is Kendall's Tau. Otherwise, returns a length 8 list:

b the slope of the linear trend, as estimated alongisde the ARMA model
bp P-value associated with the linear trend
tau Kendall's Tau
S score
varS variance of score
tauZ Z statistic associated with Kendall's Tau (either S/sqrt(varS) or qnorm(taup/2))
taup p-value of tau
adjusted character indicating whether S or Z (z score) or P (p-value) had to be adjusted to match p-value reported by Kendall::Kendall

References

Yue, S., and C. Y. Wang. 2002. Applicability of prewhitening to eliminate the influence of serial correlation on the Mann-Kendall test. Water resources research 38:4-1-4-7.

Yue, S., and C. Wang. 2004. The Mann-Kendall Test Modified by Effective Sample Size to Detect Trend in Serially Correlated Hydrological Series. Water Resources Management 18:201-218.

Hyndman, R. J., and G. Athanasopoulos. 2014. Forecasting: principles and practice: OTexts.

See Also

post_trend

Examples

1
2
3
4
5
6
n <- 10
x <- 1:n
slope <- 0.5
ar_coeff <- 0.85
y <- slope*x+arima.sim(model=list(ar=c(ar_coeff)), n=n)
tsTau(x, y)

rBatt/trawlDiversity documentation built on Aug. 14, 2021, 1:01 p.m.