Cross-correlations of two time series are computed up to a specific lag in seconds maxlag. Cross-correlation is done within segment of the time series. The size of segments segment can be chosen in seconds. Aggregation is then performed by transforming correlations to Fisher's Z, computing mean Z in each segment, then across all segments of the time series. Segment shuffling is used to create surrogate time series, on which the same computations are run. This provides effect sizes ES. SUSY provides these different synchrony measures for each twin time series: mean Z and ES of mean Z; mean absolute_Z and ES of mean absolute_Z.

susy(x, segment, Hz, maxlag=3L, permutation=FALSE,
  restrict.surrogates=FALSE, surrogates.total=500)

Arguments

x

A data.frame of numeric columns.

segment

Integer, size in seconds. Must not be smaller than 2 * maxlag, must not be larger than half the the time series (nrow(x)/2).

Hz

Integer, frames per second (sampling rate).

maxlag

Integer, maximum lag for ccf in seconds. Default 3 seconds.

permutation

Logical, default FALSE requires x to have even number of columns which are processed in pairs (1-2, 3-4, etc.). When permutation is TRUE then function computes all pairs combinations between columns provided in x (n*(n-1)/2 pairs).

restrict.surrogates

Logical, default FALSE. Restrict the number of surrogates or not.

surrogates.total

Numeric, the number of generated surrogates, default 500. Ignored when restrict.surrogates is FALSE (default).

Details

Segments are non-overlapping, and the number of segments that fit into the time series may have a remainder (usually a few seconds at the end of the time series), which is not considered.

Value

Object of class susy is returned. Each cross correlation pair is an element in resulting object.

Examples

n = 1000
data = data.frame(
  var1 = runif(n, 300, 330),
  var2 = runif(n, 300, 330),
  var3 = runif(n, 300, 330)
)

## use only first two columns
res = susy(data[, 1:2], segment=30L, Hz=15L)
length(res)
#> [1] 1
names(res)
#> [1] "var1-var2"

## use all columns and permutation
res = susy(data, segment=30L, Hz=15L, permutation=TRUE)
length(res)
#> [1] 3
names(res)
#> [1] "var1-var2" "var1-var3" "var2-var3"

## print susy
res
#>   Var1 Var2 n(data)          Z   Z-Pseudo      SD(Z) SD(Z-Pseudo) n(lags)
#> 1 var1 var2    1000 0.03758952 0.03770472 0.01861221   0.02042318      91
#> 2 var1 var3    1000 0.03696976 0.03575643 0.01828249   0.01606544      91
#> 3 var2 var3    1000 0.03733517 0.03230638 0.02024827   0.01530296      91
#>   %>Pseudo n(Segmente)           ES   Z(lead1)   Z(lead2)   ES(lead1)
#> 1 54.94505           2 -0.005640414 0.03572566 0.03921177 -0.11041235
#> 2 52.74725           2  0.075523795 0.03866898 0.03587751  0.37263081
#> 3 56.04396           2  0.328615680 0.03413593 0.04110862  0.01192364
#>     ES(lead2) meanZ(in-phase) meanZ(anti-phase) Anzahl(in-phase)
#> 1  0.08394342      0.02472946       -0.03072505               48
#> 2 -0.20402957      0.02680690       -0.02738285               48
#> 3  0.65536922      0.02149852       -0.02794795               45
#>   Anzahl(anti-phase)     Z(noAbs) Z(Pseudo-noAbs) %>Pseudo(noAbs)   ES(noAbs)
#> 1                 43 -0.001474322    0.0003783743        51.64835 -0.05365739
#> 2                 43  0.001200755   -0.0004637993        52.74725  0.05756395
#> 3                 46 -0.003496403    0.0033187441        45.05495 -0.23845956
print(res, legacy=TRUE)
#> Var1 Var2 n(data) Z Z-Pseudo SD(Z) SD(Z-Pseudo) n(lags) %>Pseudo n(Segmente) ES Z(lead1) Z(lead2) ES(lead1) ES(lead2) meanZ(in-phase) meanZ(anti-phase) Anzahl(in-phase) Anzahl(anti-phase) Z(noAbs) Z(Pseudo-noAbs) %>Pseudo(noAbs) ES(noAbs) 
#> var1 var2 1000 0.03758952 0.03770472 0.01861221 0.02042318 91 54.94505 2 -0.005640414 0.03572566 0.03921177 -0.1104124 0.08394342 0.02472946 -0.03072505 48 43 -0.001474322 0.0003783743 51.64835 -0.05365739 
#> var1 var3 1000 0.03696976 0.03575643 0.01828249 0.01606544 91 52.74725 2 0.0755238 0.03866898 0.03587751 0.3726308 -0.2040296 0.0268069 -0.02738285 48 43 0.001200755 -0.0004637993 52.74725 0.05756395 
#> var2 var3 1000 0.03733517 0.03230638 0.02024827 0.01530296 91 56.04396 2 0.3286157 0.03413593 0.04110862 0.01192364 0.6553692 0.02149852 -0.02794795 45 46 -0.003496403 0.003318744 45.05495 -0.2384596 

## plot susy
plot(res)
plot(res, type=1:2)