The liquor store sales data are in the second column of the array called liqsales.data in which the first column is the month of the year. We will first fit additive and multiplicative seasonal models to the entire data to see the difference in the fits. Then we will use the data up to December 2003 to fit the multiplicative model and make forecasts for the coming year (2004). We will once again use Holt–Winters function given in stats package. In all cases we set all parameters to 0.2.
- y.ts<- ts(liqsales.data[,2], start = c(1992,1), freq = 12)
- liq.hw.add<-HoltWinters(y.ts,alpha=0.2,beta=0.2,gamma=0.2,
- seasonal="additive")
- plot(y.ts,type="p", pch=16,cex=.5,xlab='Date',ylab='Sales',
- main="Additive Model")
- lines(liq.hw.add$fitted[,1])
- liq.hw.mult<-HoltWinters(y.ts,alpha=0.2,beta=0.2,gamma=0.2,
- seasonal="multiplicative")
- plot(y.ts,type="p", pch=16,cex=.5,xlab='Date',ylab='Sales',
- main="Multiplicative Model")
- lines(liq.hw.mult$fitted[,1])
- y1<-liqsales.data[1:144,]
- y1.ts<-ts(y1[,2], start = c(1992,1), freq = 12)
- liq.hw1<-HoltWinters(y1.ts,alpha=0.2,beta=0.2,gamma=0.2,
- seasonal="multiplicative")
- y2<-liqsales.data[145:156,]
- y2.ts<-ts(y2[,2],start=c(2004,1),freq=12)
- y2.forecast<-predict(liq.hw1, n.ahead=12, prediction.interval =
- TRUE)
- plot(y1.ts,type="p", pch=16,cex=.5,xlab='Date',ylab='Sales',
- xlim=c(1992,2005))
- points(y2.ts)
- lines(y2.forecast[,1])
- lines(y2.forecast[,2])
- lines(y2.forecast[,3])


雷达卡


京公网安备 11010802022788号







