4.2 Notes on TSA in R and Matlab

If you use R the command below will install all the packages we will use during the entire course on you private computer. This might take too long on a university PC, just install the packages you need for an assignment each session.

install.packages(c("devtools", "rio", "plyr", "dplyr", "tidyr", "Matrix", 
                   "ggplot2", "lattice", "latticeExtra", "grid", "gridExtra", "rgl",
                   "fractal",  "nonlinearTseries",  "crqa", 
                   "signal", "sapa", "ifultools", "pracma", 
                   "nlme", "lme4", "lmerTest", "minpack.lm",
                   "igrpah","qgrap","graphicalVAR","bootGraph","IsingSampler","IsingFit"),
                 dependencies = TRUE)

There is also a function library you need to source, the most recent version is on Github, use the devtools library to source the latest online version, or just follow the link, save as an .R file from your browser and open it in R and source it.

library(devtools)
source_url("https://raw.githubusercontent.com/FredHasselman/DCS/master/functionLib/nlRtsa_SOURCE.R")

4.2.1 Importing data in R

If you have package rio installed in R, you can load the data directly into the local environment.

  1. Follow the link, e.g. for series.sav.
  2. On the Github page, find a button marked Download (or Raw for textfiles).
  3. Copy the url associated with the Download button on Github (right-clik).
  4. The copied path should contain the word ‘raw’ somewhere in the url.
  5. Call import(url):
series <- import("https://github.com/FredHasselman/DCS/raw/master/assignmentData/BasicTSA_arma/series.sav")

You can use the function arima(), acf() and pacf() in R (Matlab has functions that go by slightly different names, check the Matlab Help pages).

There are many extensions to these linear models, check the CRAN Task View on Time Series Analysis to learn more (e.g. about package zoo and forecast).

| jump to solution |