dacor_large: Distance autocorrelation with optional blockwise computation

View source: R/dacor_large.R

dacor_largeR Documentation

Distance autocorrelation with optional blockwise computation

Description

Computes lag-lag distance autocorrelation for the rows of x. If block_size = NULL, the standard full pairwise-distance computation is used. If block_size is a positive integer, a blockwise algorithm is used that avoids allocating the full (n-lag) \times (n-lag) distance matrices.

Usage

dacor_large(x, lag = 1L, block_size = NULL)

Arguments

x

A numeric vector or numeric matrix. Rows are observations ordered in time.

lag

A positive integer smaller than nrow(x). The default is 1L.

block_size

Either NULL or one positive integer. If NULL, the standard full computation is used. If positive, the blockwise computation is used with that block size.

Details

Vectors are treated as one-column matrices.

Distance autocorrelation is computed as the distance correlation between x[1:(n-lag), ] and x[(1+lag):n, ].

If block_size = NULL, the required pairwise distances are computed using the standard full computation.

If block_size is a positive integer, the effective sample of size n - lag is partitioned into consecutive blocks of size at most block_size, and distances are accumulated block by block. Only one block pair is stored at a time, which can substantially reduce memory usage.

The block size does not need to divide n - lag. If n - lag is not a multiple of block_size, the final block is simply smaller.

The blockwise algorithm mainly reduces memory usage; the computational complexity remains of order O((n-lag)^2).

Value

A numeric scalar giving the distance autocorrelation at lag lag.

References

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.

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.

Examples

set.seed(1)
n <- 100
x <- matrix(rnorm(n * 2), n, 2)

r1 <- dacor_large(x, lag = 1L)
r2 <- dacor_large(x, lag = 1L, block_size = 32L)

r1
r2
all.equal(r1, r2, tolerance = 1e-10)


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