1 Create time series
2 Seasonal decomposition
3 exponential model
4 ARIMA Model
5 Automatic prediction
The first step : Create time series
use ts() Function converts a number vector into a time series , In the form of
ts(vector,start=,end=,frequency=),frequency=(1=annual,4=quartly,12=monthly,etc)
Part two : Seasonal decomposition
If the time series tends to increase , Seasonality , And irregular components , You can use the stl() function , If the multiple effects of time series can be used log(ts)
# Seasonal decomposition fit=stl(ts,s.window="period") plot(fit) # Add diagram monthplot(ts)
library(forest) seasonplt(ts)
Step three : exponential model
# Simple exponential smoothing model fit=HoltWinters(ts,beta=F,gamma=F) # have models level and trend
fit=HoltWinters(ts,beta=F)# have models levels,trend and seasonal compontents
fit=HoltWinters(ts)#predict accuracy library(forecast) accuracy(fit) #predict
next three future values library(forecast) forecast(fit,3) plot(forecast(fit,3))
Technology
Daily Recommendation