Appendix


A Setting-up R

R can be downloaded and installed here:https://www.rstudio.com/ or from any CRAN (the Comprehensive R Archive Network) mirrors at https://cran.rstudio.com/.

Code RStudio is entered into the console or into the script editor. We recommend to enter the code in the console, but once you have written code that works and does what you want, put it in the script editor. RStudio will automatically save the contents of the editor when you quit RStudio, and will automatically load it when you re-open.

RStudio comes with a number of pre-installed packages They are stored on a repository called CRAN (the Comprehensive R Archive Network): https://cran.r-project.org/. Packages contributed to CRAN have gone through certain checks to ensure they are stable. Libraries from CRAN need to be installed first using install.packages('package_name') before they can be loaded using library(). To have its functions accessible, a library must be loaded even if already installed.

R packages are also often constantly updated on CRAN or GitHub, so you may want to update them once in a while: update.packages(ask = FALSE)

Although it is not required, the RStudio IDE can make a lot of things much easier when you work on R-related projects. The RStudio IDE can be downloaded from link.

The data used in the exercises are on Github and can be downloaded at http://laurentlsantos.github.io/forecasting/ To ensure the file paths work correctly, first change your working directory to the location where you saved the data using setwd().

This book was built with:

## - Session info ----------------------------------------------------------
##  setting  value                       
##  version  R version 3.6.0 (2019-04-26)
##  os       Windows 10 x64              
##  system   x86_64, mingw32             
##  ui       RTerm                       
##  language (EN)                        
##  collate  English_United Kingdom.1252 
##  ctype    English_United Kingdom.1252 
##  tz       Europe/London               
##  date     2019-09-09                  
## 
## - Packages --------------------------------------------------------------
##  package      * version  date       lib source        
##  askpass        1.1      2019-01-13 [1] CRAN (R 3.6.0)
##  assertthat     0.2.1    2019-03-21 [1] CRAN (R 3.6.0)
##  backports      1.1.4    2019-04-10 [1] CRAN (R 3.6.0)
##  base64enc      0.1-3    2015-07-28 [1] CRAN (R 3.6.0)
##  BH             1.69.0-1 2019-01-07 [1] CRAN (R 3.6.0)
##  broom          0.5.2    2019-04-07 [1] CRAN (R 3.6.0)
##  callr          3.2.0    2019-03-15 [1] CRAN (R 3.6.0)
##  cellranger     1.1.0    2016-07-27 [1] CRAN (R 3.6.0)
##  cli            1.1.0    2019-03-19 [1] CRAN (R 3.6.0)
##  clipr          0.6.0    2019-04-15 [1] CRAN (R 3.6.0)
##  colorspace     1.4-1    2019-03-18 [1] CRAN (R 3.6.0)
##  crayon         1.3.4    2017-09-16 [1] CRAN (R 3.6.0)
##  curl           3.3      2019-01-10 [1] CRAN (R 3.6.0)
##  DBI            1.0.0    2018-05-02 [1] CRAN (R 3.6.0)
##  dbplyr         1.4.1    2019-06-05 [1] CRAN (R 3.6.0)
##  digest         0.6.19   2019-05-20 [1] CRAN (R 3.6.0)
##  dplyr        * 0.8.3    2019-07-04 [1] CRAN (R 3.6.1)
##  ellipsis       0.1.0    2019-02-19 [1] CRAN (R 3.6.0)
##  evaluate       0.14     2019-05-28 [1] CRAN (R 3.6.0)
##  fansi          0.4.0    2018-10-05 [1] CRAN (R 3.6.0)
##  forcats        0.4.0    2019-02-17 [1] CRAN (R 3.6.0)
##  fs             1.3.1    2019-05-06 [1] CRAN (R 3.6.0)
##  generics       0.0.2    2018-11-29 [1] CRAN (R 3.6.0)
##  ggplot2      * 3.1.1    2019-04-07 [1] CRAN (R 3.6.0)
##  glue           1.3.1    2019-03-12 [1] CRAN (R 3.6.0)
##  gtable         0.3.0    2019-03-25 [1] CRAN (R 3.6.0)
##  haven          2.1.0    2019-02-19 [1] CRAN (R 3.6.0)
##  highr          0.8      2019-03-20 [1] CRAN (R 3.6.0)
##  hms            0.4.2    2018-03-10 [1] CRAN (R 3.6.0)
##  htmltools      0.3.6    2017-04-28 [1] CRAN (R 3.6.0)
##  httr           1.4.0    2018-12-11 [1] CRAN (R 3.6.0)
##  jsonlite       1.6      2018-12-07 [1] CRAN (R 3.6.0)
##  knitr        * 1.23     2019-05-18 [1] CRAN (R 3.6.0)
##  labeling       0.3      2014-08-23 [1] CRAN (R 3.6.0)
##  lattice      * 0.20-38  2018-11-04 [1] CRAN (R 3.6.0)
##  lazyeval       0.2.2    2019-03-15 [1] CRAN (R 3.6.0)
##  lubridate      1.7.4    2018-04-11 [1] CRAN (R 3.6.0)
##  magrittr       1.5      2014-11-22 [1] CRAN (R 3.6.0)
##  markdown       1.1      2019-08-07 [1] CRAN (R 3.6.1)
##  MASS         * 7.3-51.4 2019-03-31 [2] CRAN (R 3.6.0)
##  Matrix         1.2-17   2019-03-22 [1] CRAN (R 3.6.1)
##  mgcv           1.8-28   2019-03-21 [2] CRAN (R 3.6.0)
##  mime           0.6      2018-10-05 [1] CRAN (R 3.6.0)
##  modelr         0.1.4    2019-02-18 [1] CRAN (R 3.6.0)
##  munsell        0.5.0    2018-06-12 [1] CRAN (R 3.6.0)
##  nlme         * 3.1-139  2019-04-09 [2] CRAN (R 3.6.0)
##  openssl        1.4      2019-05-31 [1] CRAN (R 3.6.0)
##  pillar         1.4.2    2019-06-29 [1] CRAN (R 3.6.1)
##  pkgconfig      2.0.2    2018-08-16 [1] CRAN (R 3.6.0)
##  plogr          0.2.0    2018-03-25 [1] CRAN (R 3.6.0)
##  plyr           1.8.4    2016-06-08 [1] CRAN (R 3.6.0)
##  prettyunits    1.0.2    2015-07-13 [1] CRAN (R 3.6.0)
##  processx       3.3.1    2019-05-08 [1] CRAN (R 3.6.0)
##  progress       1.2.2    2019-05-16 [1] CRAN (R 3.6.0)
##  ps             1.3.0    2018-12-21 [1] CRAN (R 3.6.0)
##  purrr          0.3.2    2019-03-15 [1] CRAN (R 3.6.0)
##  R6             2.4.0    2019-02-14 [1] CRAN (R 3.6.0)
##  RColorBrewer   1.1-2    2014-12-07 [1] CRAN (R 3.6.0)
##  Rcpp           1.0.1    2019-03-17 [1] CRAN (R 3.6.0)
##  readr          1.3.1    2018-12-21 [1] CRAN (R 3.6.0)
##  readxl       * 1.3.1    2019-03-13 [1] CRAN (R 3.6.1)
##  rematch        1.0.1    2016-04-21 [1] CRAN (R 3.6.0)
##  reprex         0.3.0    2019-05-16 [1] CRAN (R 3.6.0)
##  reshape2       1.4.3    2017-12-11 [1] CRAN (R 3.6.0)
##  rlang          0.4.0    2019-06-25 [1] CRAN (R 3.6.0)
##  rmarkdown      1.14     2019-07-12 [1] CRAN (R 3.6.1)
##  rstudioapi     0.10     2019-03-19 [1] CRAN (R 3.6.0)
##  rvest          0.3.4    2019-05-15 [1] CRAN (R 3.6.0)
##  scales       * 1.0.0    2018-08-09 [1] CRAN (R 3.6.0)
##  selectr        0.4-1    2018-04-06 [1] CRAN (R 3.6.0)
##  stringi        1.4.3    2019-03-12 [1] CRAN (R 3.6.0)
##  stringr        1.4.0    2019-02-10 [1] CRAN (R 3.6.0)
##  sys            3.2      2019-04-23 [1] CRAN (R 3.6.0)
##  tibble         2.1.3    2019-06-06 [1] CRAN (R 3.6.0)
##  tidyr          0.8.3    2019-03-01 [1] CRAN (R 3.6.0)
##  tidyselect     0.2.5    2018-10-11 [1] CRAN (R 3.6.0)
##  tidyverse      1.2.1    2017-11-14 [1] CRAN (R 3.6.0)
##  tinytex        0.13     2019-05-14 [1] CRAN (R 3.6.0)
##  utf8           1.1.4    2018-05-24 [1] CRAN (R 3.6.0)
##  vctrs          0.1.0    2018-11-29 [1] CRAN (R 3.6.0)
##  viridisLite    0.3.0    2018-02-01 [1] CRAN (R 3.6.0)
##  whisker        0.3-2    2013-04-28 [1] CRAN (R 3.6.0)
##  withr          2.1.2    2018-03-15 [1] CRAN (R 3.6.0)
##  xfun           0.7      2019-05-14 [1] CRAN (R 3.6.0)
##  xml2           1.2.0    2018-01-24 [1] CRAN (R 3.6.0)
##  yaml           2.2.0    2018-07-25 [1] CRAN (R 3.6.0)
##  zeallot        0.1.0    2018-01-28 [1] CRAN (R 3.6.0)
## 
## [1] C:/Users/Laurent/Documents/R/win-library/3.6
## [2] C:/Program Files/R/R-3.6.0/library

B Data set

  • dates: The dates of data collection. The first column is the date and the second column is the time of day, from 1 (6am) to 180 (9pm). This is the order in which the data appear in UJT.

  • LCAPAdj: The adjacency matrix, where 1 indicates two links are adjacent. Note that the network is not fully connected as some links have been removed due to poor data quality.

  • LCAPShp: A shapefile of the data, which can be quickly visualised usin gplot(LCAPSh) . This shapefile contains all links (1402) so you may want to extract/identify those links for which you have data. The IDs correspond to the LCAP_ID field in LCAPShp@data.

  • tts.xls: The adjusted weighted adjacency matrix.

  • UJT: The data matrix, with one road link per column. The column names are the road link IDs.