max_cc: max.cc

Description Usage Arguments Value Examples

View source: R/synchrony.R

Description

Get maximal cross-correlation between 2 numerical vectors. Only 1st position is returned.

Usage

1
max_cc(x, y, use.circular = TRUE, plot = FALSE, ...)

Arguments

x,

y numerical vector

use.circular

logical, whether to use circular cross-correlation.

plot

logical. If TRUE, plots the cross-correlation histogram.

...

additional parameters for the cross-correlation if use.circular is FALSE. Of particular interest is lag.max. See ?ccf.

Value

A list of 2. $corr contains the maximum of correlation and $lag the lag at which it was reached.

Examples

1
2
3
4
5
6
7
8
9
# 2 identical signals, shifted by a lag 3
pattern <- c(0.25, 0.5, 0.75, 1)
x <- rep(pattern, 10)
y <- c(x[4:length(x)],x[1:3])
par(mfrow=c(3,1))
plot(x, type = "h", main = "x", ylim = c(-0.2,1.2))
plot(y, type = "h", main = "y", ylim = c(-0.2,1.2))
# With circular cc, correlation is strictly 1
max_cc(x, y, use.circular = T, plot = T)

majpark21/TSexploreR documentation built on Oct. 16, 2019, 2:46 p.m.