Simple exponential smoothing
ses() 函式會使用「簡單指數平滑(simple exponential smoothing,SES)」來產生預測。參數會以最小平方法估計。你只需要指定時間序列與預測範圍;預設的預測時間是 h = 10 年。
> args(ses)
function (y, h = 10, ...)
> fc <- ses(oildata, h = 5)
> summary(fc)
你也會首次搭配使用 summary() 與 fitted(),以及 autolayer()。autolayer() 類似 autoplot(),但它是在既有圖上新增一個「圖層」,而不是建立新圖。
在這裡,你會把這些函式套用到 marathon:1897–2016 年波士頓馬拉松年度冠軍成績。資料已提供在你的工作環境中。
本練習屬於課程
R 的時間序列預測
練習說明
- 使用
ses()函式預測接下來 10 年的冠軍成績。 - 使用
summary()函式檢視模型參數與其他資訊。 - 使用
autoplot()函式繪製預測圖。 - 使用
fitted()與autolayer(),把訓練資料的一步預測(也就是擬合值)加到圖上。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Use ses() to forecast the next 10 years of winning times
fc <- ___(___, h = ___)
# Use summary() to see the model parameters
___
# Use autoplot() to plot the forecasts
___
# Add the one-step forecasts for the training data to the plot
autoplot(___) + autolayer(fitted(___))