dacov_large: Distance autocovariance with optional blockwise computation

View source: R/dacor_large.R

dacov_largeR Documentation

Distance autocovariance with optional blockwise computation

Description

Computes lag-lag distance autocovariance 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

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

dacov2_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

dacov_large() returns the distance autocovariance and dacov2_large() returns the corresponding squared distance autocovariance.

Vectors are treated as one-column matrices.

The functions compare the segment x[1:(n-lag), ] with the lagged segment x[(1+lag):n, ] using distance covariance.

If block_size = NULL, all pairwise distances for these two segments are computed in the usual way.

If block_size is a positive integer, the same quantity is computed block by block. The effective sample size is n - lag, and the corresponding rows are split into consecutive blocks of size at most block_size. Distances are accumulated over all block pairs, so only one block pair needs to be stored at a time.

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

For dacov_large(), a numeric scalar giving the distance autocovariance at lag lag.

For dacov2_large(), a numeric scalar giving the squared distance autocovariance 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)

v1 <- dacov2_large(x, lag = 1L)
v2 <- dacov2_large(x, lag = 1L, block_size = 32L)

v1
v2
all.equal(v1, v2, tolerance = 1e-10)

a1 <- dacov_large(x, lag = 2L)
a2 <- dacov_large(x, lag = 2L, block_size = 32L)

a1
a2
all.equal(a1, a2, tolerance = 1e-10)


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