simple.R contains a set of simple working examples about how to deal with time series.
############### Simple ###############
forcastMean = meanf(myTs, h=10) plot(forcastMean)
forcastNaive = naive(myTs, h=10) plot(forcastNaive)
Seasonal naive : last value from same season (uses frequency which is the nb of observation per periode of time. Ex: frequency=25)
forcastSeasonalNaive = snaive(myTs, h=50) plot(forcastSeasonalNaive)
forcastDrift = rwf(myTs, h=10) plot(forcastDrift)
############### STLF (1990) ###############
STLF : applying a non-seasonal forecasting method to the seasonally adjusted data and re-seasonalizing using the last year of the seasonal component.
forcastSTLF = stlf(myTs, h=50) plot(forcastSTLF)
############### ETS (2008) ###############
forcastSES = ses(myTs, h=10) plot(forcastSES)
forcastHolt = holt(myTs, h=10) plot(forcastHolt)
forcastHw = hw(myTs, h=50) plot(forcastHw)
ETS Exponential smoothing forecasts : custom model (Error, Trend, Seasonal) : "N"=none, "A"=additive, "M"=multiplicative and "Z"=automatically selected.
fitETS = ets(myTs, model="ZAA", damped=FALSE) forcastETS = forecast(fitETS, h=50) plot(forcastETS) accuracy(forcastETS, tail(myTs, 25)) # secound argument is the values to compare
ETS Exponential smoothing forecasts : Box-Cox to stabilize the variance (data show different variation at different levels of the series)
lam = BoxCox.lambda(myTs) # = 1.08781474274726 fitETSBoxCox = ets(myTs, additive=TRUE, lambda=lam) forcastETSBoxCox = forecast(fitETSBoxCox, h=10) plot(forcastETSBoxCox)
############### Arima (2008) ###############
modelArima <- auto.arima(myTs) forcastArima <- forecast(modelArima, h=50) plot(forcastArima)
############### Auto ###############
forcastAuto = forecast(myTs, h=50) plot(forcastAuto) forcastAuto$model # view the selected model
############### Others ###############
forcastCroston = croston(myTs, h=10) plot(forcastCroston)
forcastSplinef = splinef(myTs, h=10) plot(forcastSplinef)
forcastSplinef = thetaf(myTs, h=10) plot(forcastSplinef)
forcastSplinef = dshw(myTs, period1=24, period2=3) plot(forcastSplinef)
############### TimeSeries Datasets examples ############### library(fma) data(package="fma") plot(BoxCox(dowjones,1))