get_ccf: Cross correlation function between two vectors

View source: R/align.R

get_ccfR Documentation

Cross correlation function between two vectors

Description

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.

Usage

get_ccf(x, y, min.overlap = round(0.1 * max(length(x), length(y))))

Arguments

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?

Details

This version of the cross correlation function is different from the stats implementation of ccf in two ways:

  1. 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).

  2. We do not use a Fourier transformation to calculate cross-correlation. This makes the evaluation slower, but prevents any edge effects.

Value

list with ccf values and lags

Examples

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)

heike/bulletxtrctr documentation built on Feb. 15, 2025, 6:33 p.m.