# Fix seed for reproduceable simulations.
set.seed(123)
# Simulate autoregressive time series of length n with linear trend 1+2*t,
# where t is a regular sequence on the interval (0,1].
n <- 100
t <- c(1:n)/n
U <- 1+2*t + arima.sim(n=n, list(order = c(2,0,0), ar = c(-0.7, -0.1)))
# Test for linear trend with output of all results.
## Not run:
# wavk.test(U, factor.length = "adaptive.selection", H0="linear", out=TRUE, B=1000)
# ## End(Not run)
# Sample output:
##
## Trend test by Wang, Akritas and Van Keilegom
##
##data: U
##WAVK test statistic = 0.8562, adaptively selected window = 4, p-value = 0.356
##alternative hypothesis: presence of a nonlinear trend
##sample estimates:
##$linear_trend_coefficients
##(Intercept) t
## 0.9917251 2.0224272
##
##$AR_coefficients
## phi_1 phi_2
##-0.6814546 -0.2404422
##
##$all_considered_windows
## Window WAVK-statistic p-value
## 4 0.8561654 0.356
## 5 0.8620023 0.320
## 7 0.8691870 0.288
## 10 0.6837790 0.306
# Test H0 of absence of a trend using asymptotic distribution of statistic.
wavk.test(U, method="asympt")
# Sample output:
##
## Trend test by Wang, Akritas and Van Keilegom
##
##data: U
##WAVK test statistic = 18.4712, user-defined window = 10, p-value < 2.2e-16
##alternative hypothesis: presence of a trend
Run the code above in your browser using DataLab