get_ccf | R Documentation |
Calculate the lagged correlation between numeric vectors x and y. Vectors x and y are assumed to be captured at the same resolution and, similarly, successive values in x and y are assumed to be equi-distant. Missing values are allowed in each vector, correlations are calculated based on the complete cases.
get_ccf(x, y, min.overlap = round(0.1 * max(length(x), length(y))))
x |
vector, assumption is that x is longer than y |
y |
vector |
min.overlap |
integer value: what is the minimal number of values between x and y that should be considered? |
This version of the cross correlation function is different from the stats
implementation of ccf
in two ways:
We consider the full region of correlations between vectors x and y as specified by min.overlap rather than just the overlap. The two vectors can be of very different length (e.g. when y is just a snippet recovered from a crime scene and x is from the full length object in the lab).
We do not use a Fourier transformation to calculate cross-correlation. This makes the evaluation slower, but prevents any edge effects.
list with ccf values and lags
library(dplyr)
x <- runif(20)
get_ccf(x, lead(x, 5))
get_ccf(x, lag(x, 5), min.overlap = 3)
x <- runif(100)
get_ccf(x[45:50], x, min.overlap = 6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.