4 Cross-Recurrence Analysis

4.1 Categorical Cross-RQA and the Diagonal Recurrence Profile

In 2008 there was some commotion about a speech held by Barack Obama in Milwaukee (news item). According to the media the speech was very similar to a speech held the gouverneur of Massachusetts (Deval Patrick) some years earlier. Here are some fragments of the speeches,

Obama (2008):

Don’t tell me words don’t matter. “I have a dream.” Just words? “We hold these truths to be self-evident, that all men are created equal.” Just words? “We have nothing to fear but fear itself”—just words? Just speeches?

Patrick (2006):

“We hold these truths to be self-evident, that all men are created equal.” Just words—just words! “We have nothing to fear but fear itself.” Just words! “Ask not what your country can do for you, ask what you can do for your country.” Just words! “I have a dream.” Just words!

# Load the speeches as timeseries
library(casnet)
obama2008 <- strsplit(x = "dont tell me words dont matter I have a dream just words we hold these truths to be selfevident that all men are created equal just words We have nothing to fear but fear itself just words just speeches", split = " ")[[1]]

patrick2006 <- strsplit(x = "we hold these truths to be selfevident that all men are created equal just words just words we have nothing to fear but fear itself just words ask not what your country can do for you ask what you can do for your country just words I have a dream just words", split = " ")[[1]]

uniqueID <- as.numeric_discrete(c(obama2008,patrick2006))

speeches <- as.data.frame(ts_trimfill(x=uniqueID[1:length(obama2008)], y=uniqueID[(length(obama2008)+1):length(uniqueID)]))
colnames(speeches) <- c("Obama","Patrick")

Questions

  • Plot both time series.

  • Because both fragments weren’t of equal size, one series is “filled” at the end with the value 0
    • Do you think this has an effect on the CRQA measures?
    • What & why?
  • Perform a categorical CRQA:
    • First create a cross recurrence matrix using function rp().
    • Look at the manual page what the values mean, look at last the categorical RQA assignment for the values of emLag, emDim and emRad
    • Get recurrence measures using crqa_rp() (ignore the warning),
    • Plot the recurrence plot using rp_plot()
    • Also look at the diagonal recurrence profile using crqa_diagProfile()
  • What is your opinion about the similarity of these speeches?

Answers

  • Adding a value which occurs in just 1 series (whether it is -2, or 0), but not the other makes sure that value will not be recurring in a Cross Recurrence Plot.
# Plot the speech series
plot(ts(speeches))

# Cross recurrence matrix
RM <- rp(y1 = as.numeric(speeches$Obama), y2 = as.numeric(speeches$Patrick), emDim = 1, emLag = 1, emRad = 0)
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
# Measures
crqa_out <- crqa_rp(RM)
## Warning in max(freqvec_vl, na.rm = TRUE): no non-missing arguments to max;
## returning -Inf
## Warning in max(freqvec_hl, na.rm = TRUE): no non-missing arguments to max;
## returning -Inf
# Plot
rp_plot(RM, plotDimensions = TRUE, plotMeasures = TRUE)
## Warning in max(freqvec_vl, na.rm = TRUE): no non-missing arguments to max;
## returning -Inf

## Warning in max(freqvec_vl, na.rm = TRUE): no non-missing arguments to max;
## returning -Inf

# Diagonal profile
drp <- crqa_diagProfile(RM, diagWin = 40,doShuffle = FALSE, doPlot = FALSE)
## 
## Profile 1
plot(drp$Diagonal,drp$RR,type="l")

4.2 Continuous CRQA and the Diagonal Profile

Questions

  • Create two sinewave variables for CRQA analysis and use the \(x\) and \(y\) coordinates of the circletracing data:
library(rio)
y1 <- sin(1:500*2*pi/67)
y2 <- sin(.01*(1:500*2*pi/67)^2)

# Here are the circle trace data
xy <- import("https://raw.githubusercontent.com/FredHasselman/The-Complex-Systems-Approach-Book/master/assignments/assignment_data/RQA_circletrace/mouse_circle_xy.csv") 

circle_x <- xy$x[1:500]
circle_y <- xy$y[1:500]
  • You have just created two sine(-like) waves. We’ll examine if and how they are coupled in a shared phase space.
    • As a first step plot them.
    • Also plot the cirlce trace state space
  • Find a common embedding delay and an embedding dimension (if you calculate an embedding dimension for each signal separately, as a rule of thumb use the highest embedding dimension you find in further analyses).

  • We can now create an unthresholded cross recurrence matrix.
    • use function rp()
    • Fill in the values you decided on for embedding delay and embedding dimension
  • Run the CRQA using crqa_cl() using th time series as input, or crqa_rp() using a thresholded matrix as input.
    • You can find a radius automatically, look in the casnet manual for function crqa_radius().
    • Most functions, like rp_plot() will call crqa_radius() if no radius is provided in the argume t emRad.
    • Request a radius which will give us about 5% recurrent points (default setting).
    • You can create a thresholded matrix by calling function di2bi(),
  • Produce a plot of the recurrence matrix using rp_plot(). Look at the manual pages.

  • Can you understand what is going on?
    • For the simulated data: Explain the the lack of recurrent points at the beginning of the time series.
    • For the circle trace: How could one see these are not deterministic sine waves?
  • Examine the synchronisation under the diagonal LOS. Look in the manual of crqa_diagProfile(). More elaborate explanation can be found in Coco & Dale (2014).
    • To get the diagonal profile from a recurrence matrix crqa_diagProfile(RM, winDiag = , ...). Where winDiag is will indicate the window size -winDiag ... 0 ... +winDiag.
    • How far is the peak in RR removed from 0 (Line of Synchronisation)?
  • To check whether the patterns are real by conducting a Cross-RQA with a shuffled/surrogate version of e.g. time series \(y2\).
    • Function crqa_diagProfile() can do a shuffled analysis, check the manual pages.
    • Use Nshuffle = 1 (or wait a long time)

NOTE: If you generate surrogate timeseries, make sure the RR is the same for all surrogates. Try to keep the RR in the same range by using.

Answers

  • You have just created two sine(-like) waves. We’ll examine if and how they are coupled in a shared phase space.
    • As a first step plot them.
    • Also plot the cirlce trace state space
library(rio)
y1 <- sin(1:1000*2*pi/67)
y2 <- sin(.01*(1:1000*2*pi/67)^2)

# Here are the circle trace data
xy <- import("https://raw.githubusercontent.com/FredHasselman/The-Complex-Systems-Approach-Book/master/assignments/assignment_data/RQA_circletrace/mouse_circle_xy.csv") 

circle_x <- xy$x[1:1000]
circle_y <- xy$y[1:1000]

# Time series
plot(cbind(ts(y1),ts(y2)))

plot(cbind(ts(circle_x),ts(circle_y)))

# State space
plot(y1,y2,type="l", pty="s",main = "Sine waves")

plot(circle_x,circle_y,type="l", pty="s",main = "Mouse Circle Trace")

  • Find a common embedding delay and an embedding dimension (if you calculate an embedding dimension for each signal separately, as a rule of thumb use the highest embedding dimension you find in further analyses).
params_y1 <- crqa_parameters(y1)

params_y2 <- crqa_parameters(y2)

The diagnostic plot of the sine wave y1 looks a bit odd. This is due to the fact that mutual information will discretize the time series, and the sine will fill all bins with the same values, because it is perfectly repeating itself. We’ll use emDim = 2 and lag = 1

emLag <- 1
emDim <- 2

RM <- rp(y1=y1, y2=y2,emDim = emDim, emLag = emLag)

# Unthresholded Matrix
rp_plot(RM, plotDimensions = TRUE)

# Thresholded Matrix, based on 5% RR
emRad <- crqa_radius(RM = RM, targetValue = .05)$Radius
RP <- di2bi(RM, emRad = emRad)
rp_plot(RP, plotDimensions = TRUE)

# The diagonal profile
drp <- crqa_diagProfile(RP, diagWin = 50, doPlot = FALSE)

# Compare CRQA with one randomly shuffled series
drpRND <- crqa_diagProfile(RP, diagWin = 50, doShuffle = TRUE, y1 = y1, y2 = y2, Nshuffle = 19, doPlot = FALSE)
params_cx <- crqa_parameters(circle_x)

params_cy <- crqa_parameters(circle_y)

The circle trace data can be embedded in 3 dimensions. This is not so strange, even though the circle was drawn in 2 dimensions, there are also speed/acceleration and accuracy constraints.

emLag <- median(params_cx$optimLag, params_cy$optimLag)
emDim <- max(params_cx$optimDim, params_cy$optimDim)

RM <- rp(y1=circle_x, y2=circle_y,emDim = emDim, emLag = emLag)

# Unthresholded Matrix
rp_plot(RM, plotDimensions = TRUE)

# Thresholded Matrix, based on 5% RR
emRad <- crqa_radius(RM = RM, targetValue = .05)$Radius
RP <- di2bi(RM, emRad = emRad)
rp_plot(RP, plotDimensions = TRUE)

# The diagonal profile
drp <- crqa_diagProfile(RP, diagWin = 100, doPlot = FALSE)

4.2.1 RQA of circle-tracing data

The data from the c ircle trracing experiment are available below, scrtuinise those data, compare the mouse to the centre of pressure.

library(rio)
series <- rio::import("https://github.com/complexity-methods/CSA-assignments/raw/master/assignment_data/BasicTSA_arma/series.xlsx")