\begin{center} \today \end{center}

library(knitr)
if (packageVersion('knitr') < '1.20.14') {
  remotes::install_github('yihui/knitr')
}
library(dplyr)
library(gifski)
# library(here)
opts_chunk$set(echo = TRUE, message = TRUE, warnings = TRUE)
load_all()

Background

Converting sockeye-sim-edm.rnw to .Rmd, using newer (hopefully easier) way of doing animations. This can be a template for then analysing any time-series vector.

First-difference the data and plot in various ways

N <- simple_ts
T <- length(N)
tvec <- 1:T     # corresponding time steps
round(N, 3)

Now to first-difference the data: \begin{equation} x_t = N_{t+1} - N_t \end{equation} for $t=1, ..., T-1$; writing it this way means that x[1] is $x_1$ (so it doesn't start with $x_2$ which would get confusing).

x = N[-1] - N[-length(N)]             # x = first-differences
n = length(x)

I don't think you need to standardise the values for a univariate time series, but you do for multiple time series to get all variables on the same scale.

Now create data fram with extra columns to represent the lagged variables.

Nx.lags = data.frame("Nt" = N)
Nx.lags = tbl_df(Nx.lags)
Nx.lags = mutate(Nx.lags,
                 "Ntmin1" = c(NA, Nt[-T]),
                 "Xt" = c(Nt[-1] - Nt[-T], NA),
                 "Xtmin1" = c(NA, Xt[-T]),
                 "Xtmin2" = c(NA, NA, Xt[-c(T-1, T)]),
                 )
Nx.lags

Now plot the data in various lagged ways using animation.

late.col <- "red"  # The default
late.num <- 10     # The default
fig.cap.1 =
  paste("Before doing EDM, this shows the data in various ways: time series of $N_t$ and $x_t$, plus phase plots of $N_t$ vs $N_{t-1}$, $x_t$ vs $x_{t-1}$ (as used for $E=2$) and $x_t$ vs $x_{t-1}$ vs $x_{t-2}$ (as used for $E=3$). The last ", late.num, " points are in ", late.col, ", with the final one as a star. In the $x_t$ time series, the values of $x_t$ are also plotted in a vertical line (with $t<0$) which is the one-dimensional equivalent of a phase plot for $E=1$.")
plotPanelMovie.X(Nx.lags)

Figure @ref(fig:animate.lagged.data)......

To plot a rotatable 3d plot in a graphics window then run the R code in chunk rotatable.

# Run this in console to get rotatable 3d plot of lagged data
#  Note: different axes to plot3dmovie. Updated to use Nx.lags
rgl::plot3d(x[-c(1, 2)], x[-c(1, n)], x[-c(n-1, n)],
            xlab = "x(t)",
            ylab = "x(t-1)",
            zlab = "x(t-2)")


andrew-edwards/EDMsimulate documentation built on Oct. 25, 2023, 2:43 p.m.