synchrony.measures: synchrony.measures

Description Usage Arguments Details Value See Also Examples

View source: R/synchrony.R

Description

A set of measures for synchrony of (oscillating) trajectories.

Usage

1
synchrony.measures(x, y, window.size, method.clip, robust.decomp = TRUE)

Arguments

x, y

a numerical vector

window.size

integer, size of the window used to compute rolling mean. The latter is also used to get the trend component in the classical decomposition.

method.clip

one of c("rollmean","decomposition"). If "rollmean" clipping is performed on x directly by comparing it to its rolling mean. If "decomposition", x is decomposed via classical decomposition (see ?classical.decomposition) and its seasonal component is clipped according to its sign.

robust.decomp

logical, whether classical decomposition should be performed in a robust way. Default to TRUE.

Details

Clipping method is robust to trends in the data, while correlations are not. See example. The clipping method aims at identifying ascending and descending phase in signals and to see if these phases align between two signals. Clipping transforms the signal in a binary signal (0 or 1). An overlap of these clipped signals is then returned. Rescaled between -1 (total asynchrony) and 1 (total synchrony) for consistence with correlations.

Value

A list of 4: $pearson: Pearson's correlation coefficient $spearman: Spearman's rank-based correlation coefficient $kendall: Kendall's rank-based correlation coefficient $overlap.clip: Overlap of clipped trajectories. Clipping performed according to method.clip.

See Also

cor, classical.decomposition

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Two phase-shifted sinusoids
x <- sin(seq(0, 20, 0.5))
y <- sin(seq(2, 22, 0.5))
# Number of points per oscillations
period <- get.period(x)
# Rollmean method
x.roll <- rollex(x, period)
y.roll <- rollex(y, period)
x.clip <- ifelse(x >= x.roll, 1, -1)
y.clip <- ifelse(y >= y.roll, 1, -1)
# Visualize
par(mfrow=c(2,1))
plot(x, type = "b", main = "Raw trajectory and rolling mean")
lines(x.roll, lty = "dashed", col = "darkgreen", lwd = 2)
lines(x.clip, type = "s", col = "blue")
plot(y, type = "b")
lines(y.roll, lty = "dashed", col = "darkgreen", lwd = 2)
lines(y.clip, type = "s", col = "red")
synchrony.measures(x, y, period, "rollmean")

# With linear trend
x <- sin(seq(0, 20, 0.5))
y <- sin(seq(2, 22, 0.5))
trend <- seq(0,3,length.out=length(x))
x <- x + trend
y <- y + trend
# Rollmean method
x.roll <- rollex(x, period)
y.roll <- rollex(y, period)
x.clip <- ifelse(x >= x.roll, 3, 0)
y.clip <- ifelse(y >= y.roll, 3, 0)
# Visualize
par(mfrow=c(2,1))
plot(x, type = "b", main = "Raw trajectory and rolling mean,
with linear trend")
lines(x.roll, lty = "dashed", col = "darkgreen", lwd = 2)
lines(x.clip, type = "s", col = "blue")
plot(y, type = "b")
lines(y.roll, lty = "dashed", col = "darkgreen", lwd = 2)
lines(y.clip, type = "s", col = "red")
synchrony.measures(x, y, period, "rollmean")

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