## F.2 Phase Space Reconstruction of the Predator-Prey system

Get some iterations from the Predator-Prey system.

# Parameters
N  <- 2048
a  <- d <- 1
b  <- c <- 2
R0 <- F0 <- 0.1
R  <- as.numeric(c(R0, rep(NA,N-1)))
F  <- as.numeric(c(F0, rep(NA,N-1)))

# Time constant
delta <- 0.01

# Numerical integration of the logistic differential equation
l_ply(seq_along(R), function(t){
R[[t+1]] <<- (a - b * F[t]) * R[t] * delta + R[t]
F[[t+1]] <<- (c * R[t] - d) * F[t] * delta + F[t]
})

Let’s plot the results.

dygraph(data.frame(time=1:2049,Rabbits=R,Foxes=F), main = "Predator-Prey System") %>%
dyHighlight(highlightCircleSize = 5, hideOnMouseOut = FALSE) %>%
dyOptions(colors = RColorBrewer::brewer.pal(3, "Set2"),  drawGrid = FALSE) %>%
dyLegend(showZeroValues = TRUE)
xyplot(R ~ F, pch = 16)

### Embedding Lag

Determine the embedding lag for optimal reconstruction. Use average mutual information of Rabbits or Foxes as the criterion for selecting a delay.

lagR <- timeLag(R, method = "mutual", plot.data = TRUE)

### False Nearest Neighbours

Determine how many points in the state space turn out to be neigbours if embedding dimension $$n$$ is added to the state space $$R(t), R(t + \tau), \ldots, R(t + n*\tau)$$.

(fnnR <- FNN(R, tlag = lagR))
False Nearest Neighbors for R
-----------------------------
Series points              : 2049
Embedding dimension(s)     : 1 2 3 4 5
Time lag                   : 334
Oribital lag               : 1
Neighbor tolerance (rtol)  : 10
Attractor tolerance (atol) : 2
Test results (%):
E=1  E=2  E=3 E=4 E=5
rtol     86.3 29.5 9.76   0   0
atol     10.0  0.0 0.00   0   0
combined 86.3 29.5 9.76   0   0
plotRP.fnn(fnnR)

### Plot the reconstructed phase space

Objects of the class embedSeries generated by embedSeries() have a special plot function:

(lRR <- embedSeries(R,dimension = 2, tlag = lagR))
Embedding matrix for R
----------------------
Number of points       : 1715
Embedding dimension(s) : 1 2
Time lag               : 334 
plot(lRR, pch=".", col = "black", type = "l")