## 8.1 Assignment: CRQA and Diagonal Profile

1. Create two variables for CRQA analysis, or use the $$x$$ and $$y$$ coordinates we roecorded during the lecture:
y1 <- sin(1:900*2*pi/67)
y2 <- sin(.01*(1:900*2*pi/67)^2)

# Here are the circle trace data
xy <- import("https://raw.githubusercontent.com/FredHasselman/DCS/master/assignmentData/RQA_circletrace/mouse_circle_xy.csv")

y1 <- xy$x y2 <- xy$y
1. 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.

2. Find an embedding delay (using mutual information) and an embedding dimension (if you calculate an embedding dimension using package fractal for each signal seperately, as a rule of thumb use the highest embedding dimension you find in further analyses).

# General settings for crqa()
par0 <- list(rescale = 0,
normalize = 0,
mindiagline = 2,
minvertline = 2,
tw = 0,
whiteline = FALSE,
recpt = FALSE,
side = "both",
checkl = list(do = FALSE, thrshd = 3, datatype = "categorical",pad = TRUE)
)

# Settings for optimizeParam()
par <- list(lgM =  20, steps = seq(1, 6, 1),
normalize = par0$normalize, rescale = par0$rescale,
mindiagline = par0$mindiagline, minvertline = par0$minvertline,
tw = par0$tw, whiteline = par0$whiteline,
recpt = par0\$recpt,
fnnpercent = 10, typeami = "mindip")
1. We can now create a cross recurrence matrix. Fill in the values you decided on. You can choose a radius automatically, look in the crqa manual.
• Get the optimal parameters using a radius which will give us 2%-5% recurrent points.

Note: There is no rescaling of data, the sines were created in the same range. You can plot a matrix using image(). You could also check package nonlinearTseries. If you sourced the nlRtsa library, use plotRP.crqa()

(ans <- optimizeParam(ts1 = y1, ts2 = y2, par = par, min.rec = 2, max.rec = 5))
1. Run the CRQA and produce a plot of the recurrence matrix.

2. 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 determisnistic sine waves?
1. Examine the synchronisation under the diagonal LOS. Look in the manual of crqa or Coco & Dale (2014).
• To get the diagonal profile from the recurrence plot, use spdiags().
• Make a plot of the diagonal profile. How far is the peak in RR removed from 0 (Line of Synchronisation)?
1. Perform the same steps with a shuffled version (or use surrogate analysis!) of the data of timeseries $$y1$$. You can use the embedding parameters you found earlier.

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 the min.rec and max.rec settings of optimizeParam for each surrogate.