官术网_书友最值得收藏!

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, and computed seasonal.

When this is entered into a Notebook, we will get a familiar layout:

The simple plot (using the R plot command) is like the one that's shown in the following screenshot. There is no apparent organization or structure:

The monthly plot (using the monthplot command) is like what's shown in the following screenshot. River flows appear to be very consistent within a month:

Finally, the seasonalplot shows, quite dramatically, what we have been trying to forecast, that is, definite seasonality to the river flows:

主站蜘蛛池模板: 巫山县| 建昌县| 正阳县| 庄浪县| 马公市| 象山县| 龙岩市| 沛县| 九江市| 西峡县| 宁都县| 通江县| 贵港市| 新野县| 义乌市| 综艺| 积石山| 岳池县| 建始县| 太和县| 河北区| 巧家县| 上高县| 耿马| 铅山县| 西畴县| 历史| 息烽县| 普兰店市| 罗平县| 扶余县| 新兴县| 宁陕县| 深泽县| 香港 | 二连浩特市| 依安县| 渭南市| 汉川市| 黄平县| 澳门|