The US CPI data are in the second column of the array called cpi.data in which the first column is the month of the year. For this case we use the firstsmooth function twice to obtain the double exponential smoothing as
- cpi.smooth1<-firstsmooth(y=cpi.data[,2],lambda=0.3)cpi.smooth2<-firstsmooth(y=cpi.smooth1,lambda=0.3)cpi.hat<-2*cpi.smooth1-cpi.smooth2 #Equation 4.23plot(cpi.data[,2],type="p", pch=16,cex=.5,xlab='Date',ylab='CPI',xaxt='n')axis(1, seq(1,120,24), cpi.data[seq(1,120,24),1])lines(cpi.hat)
Note that the fitted values are obtained using Eq. (4.23). Also the corresponding command using Holt–Winters function is
- HoltWinters(cpi.data[,2],alpha=0.3, beta=0.3, gamma=FALSE)


雷达卡

京公网安备 11010802022788号







