R forecasting

For this example, we will forecast the Fraser River levels given the data from  https://datamarket.com/data/set/22nm/fraser-river-at-hope-1913-1990#!ds=22nm&display=line . I was not able to find a suitable source so I extracted the data by hand from the site into a local file.

We will be using the R forecast package. You have to add this package to your setup (as described at the start of this chapter).

The R script we will be using is as follows:

library(forecast)
fraser <- scan("fraser.txt")
plot(fraser)
fraser.ts <- ts(fraser, frequency=12, start=c(1913,3))
fraser.stl = stl(fraser.ts, s.window="periodic")
monthplot(fraser.stl)
seasonplot(fraser.ts)

The output of interest in this example are the three plots: simple plot, monthly, ...

Get Learning Jupyter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.