dcor_serial_test: Test Serial Dependence Using Distance Covariance or Distance...

View source: R/dcor_serial_test.R

dcor_serial_testR Documentation

Test Serial Dependence Using Distance Covariance or Distance Correlation

Description

Test whether a univariate time series exhibits serial dependence using a portmanteau-type test based on lagwise distance covariance or distance correlation statistics.

Usage

dcor_serial_test(
  x,
  transform = c("none", "bowl", "biloop"),
  measure = c("dcov", "dcor"),
  type = c("FP", "BP"),
  kernel = "bartlett",
  B = 499L,
  lags = NULL,
  seed = NULL,
  block_size = NULL,
  ...
)

Arguments

x

A numeric vector, or a one-column numeric matrix, containing a univariate time series.

transform

Character string indicating whether the data should be transformed before computing the lagwise dependence measure. One of "none", "bowl", or "biloop".

measure

Character string specifying the lagwise dependence measure. Either "dcov" for distance covariance or "dcor" for distance correlation. The default is "dcov".

type

Character string specifying the portmanteau statistic. Either "BP" for a Box–Pierce type statistic or "FP" for the kernel-weighted Fokianos-Pitsillou statistic.

kernel

Character string specifying the kernel used when type = "FP". Currently only "bartlett" is implemented.

B

Number of permutation resamples used to approximate the null distribution.

lags

Integer vector of lags to include in the test statistic. If NULL, the default is 1:floor(n^(2/5)). In case of subject knowledge it is recommended not to use the default but a vector of the form 1:m, where m is the largest meaningful lag of interest strictly smaller than the length of the time series.

seed

Optional random seed.

block_size

Either NULL or one positive integer. If NULL, the standard full computation is used for the lagwise distance covariance or distance correlation values. If positive, the blockwise computation is used with that block size.

...

Additional arguments passed to bowl_transform() or biloop_transform() when transform is not "none".

Details

For each lag k, the procedure computes a dependence measure D_k between X_t and X_{t+k}. The measure is either distance covariance or distance correlation.

If type = "BP", the test statistic is

T_{BP} = n \sum_{k \in \mathcal{L}} D_k^2.

If type = "FP", the test statistic is

T_{FP} = \sum_{k \in \mathcal{L}} (n-k) K^2(k/m) D_k^2,

where K is a kernel function and m is the number of selected lags. Currently, the Bartlett kernel is used:

K(z) = \begin{cases} 1 - |z|, & |z| \le 1 \\ 0, & \text{otherwise} \end{cases}

Hence, for type = "FP", lags larger than m and the largest lag of 1:m get weight zero. A warning is given if selected lags other than the largest lag of 1:m do not contribute to the test statistic.

The null distribution is approximated by random permutations of the observed series. This targets the null hypothesis of serial independence. The procedure is simple and broadly applicable, but it is computationally more intensive than classical autocorrelation-based tests.

The procedure assumes that the time series is completely observed. Missing observations should therefore be handled before applying the test.

In practical applications, a larger number of permutation resamples is recommended to obtain stable and reliable p-values. The default B = 499 is intended for exploratory use, whereas values such as B = 2000 or larger are recommended for reporting final results.

If transform = "bowl" or transform = "biloop", the series is first transformed and the distance correlation is then computed on the transformed data. By default, scaling is enabled for these transformations, unless the user explicitly supplies do_scale = FALSE.

Robust scaling can be supplied through the location and scale arguments. For example, for univariate data one may use the sample median together with robustbase::Qn.

Value

An object of classes "sdt" and "htest".

References

Fokianos, K. and Pitsillou, M (2017). Consistent testing for pairwise dependence in time series. Technometrics, 59(2), 262–270 doi:10.1080/00401706.2016.1156024

Székely, G. J., Rizzo, M. L., and Bakirov, N. K. (2007). Measuring and testing dependence by correlation of distances. Annals of Statistics, 35(6), 2769–2794. doi:10.1214/009053607000000505.

Székely, G. J. and Rizzo, M. L. (2009). Brownian distance covariance. Annals of Applied Statistics, 3(4), 1236–1265. doi:10.1214/09-AOAS312.

Examples

x <- rnorm(200)
dcor_serial_test(x, B = 99)

y <- as.numeric(arima.sim(list(ar = 0.6), n = 200))

dcor_serial_test(y, B = 99)
dcor_serial_test(y, B = 99, measure = "dcor")
dcor_serial_test(y, B = 99, type = "FP")
dcor_serial_test(y, B = 99, transform = "biloop")


# robust scaling example
if (requireNamespace("robustbase", quietly = TRUE)) {
  ymat <- matrix(y, ncol = 1)
  loc <- apply(ymat, 2, stats::median)
  sc <- apply(ymat, 2, robustbase::Qn)

  dcor_serial_test(
    y,
    transform = "bowl",
    B = 99,
    location = loc,
    scale = sc
  )
}

dcor_serial_test(y, B = 99, block_size = 64L)



dcorBSS documentation built on Nov. 10, 2026, 5:07 p.m.