Cross correlatation for time series with weights?


April 2019


121 time


Part 1: Previously I was using the ccf function in R to compute cross correlations between two timeseries ts_1 and ts_2. Now, I want to compute the crosscorrelation, but I have a vector of weights which is the same length as ts_1 and ts_2. From what I understand, the built-in ccf function I was using in does not have an argument for weights. Does another function/package have these capabilities?

Part 2: On a more conceptual note, I understand that Pearsons crosscorrelation cannot exceed 1 (or rather the absolute value of the crosscorrelation value). However, does this also hold true for weighted cross correlation? If so, what does this mean/how do I interpret this?

Thank you in advance for your help!

1 answers


You can use wcc function from ptw package for calculation of cross-correlations. E.g. please the code below putting more weight on the tail of the series:

wcc(gaschrom[1,], gaschrom[2,], trwdth = 20, wghts = rep(seq_along(gaschrom[1, ])))


[1] 0.9997758

The wcc is a suitable measure for the similarity of two patterns when features may be shifted. Identical patterns lead to a wcc value of 1.

This mean that however they are identical however shifted on time axis the weighted crosscorrelation will give you 1 (perfectly correlated).