- Moving Average
- Single Exponential Smoothing - Uses single smoothing factor
- Double Exponential Smoothing - Uses two constants and is better at handling trends
- Triple Exponential Smoothing - Smoothing factor, trend, seasonal factors considered
- ARIMA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Create Dataset | |
#Generate sample data of 100 records with mean = 850 and standard deviation = 900 | |
myvector <- rnorm(1000, 850, 900) | |
myvector | |
#Split it into timeseries weekly data for 104 weeks | |
myts = ts(myvector, start=c(2014,1),end=c(2016,1),frequency=104) | |
myts | |
#Plot Data | |
plot(myts) | |
#Apply moving average | |
sm = ma(myts, order=4)#4 week average | |
plot(sm) | |
#Plotting with Single Exponential | |
fit = HoltWinters(myts,beta = FALSE, gamma = FALSE) | |
plot(fit) | |
#Plotting with Double Exponential | |
fit = HoltWinters(myts, gamma = FALSE) | |
plot(fit) | |
#triple exponential | |
fit = HoltWinters(myts) | |
#Additive triple exponential | |
fit1 = HoltWinters(myts, seasonal = "multiplicative") | |
#Multiplicative triple exponential | |
fit2 = HoltWinters(myts, seasonal = "additive") | |
#ARIMA | |
arimafit = arima(myts, order = c(0,0,0)) | |
summary(arimafit) | |
plot(myts, xlim=c(2014,2016),lw=2,col="blue") | |
lines(predict(arimafit,n.ahead=50)$pred,lw=2,col="red") | |
#Auto Regression | |
arfit = ar(myts) | |
summary(arfit) | |
pred = predict(arfit,n.ahead=30) | |
plot(myts,type="l",xlim=c(2014,2016),ylim=c(100,2200),xlab="weeks",ylab="forecast") | |
lines(pred$pred,col="red") | |
No comments:
Post a Comment