R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-pc-linux-gnu (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > x <- c(42.33600 + ,42.14710 + ,40.25640 + ,39.18980 + ,39.13170 + ,38.15070 + ,38.27070 + ,39.13350 + ,40.12190 + ,41.28450 + ,42.57490 + ,43.90190 + ,43.18350 + ,43.61880 + ,44.76240 + ,45.19720 + ,44.38810 + ,43.55520 + ,43.56780 + ,44.21350 + ,45.14510 + ,45.80790 + ,42.32820 + ,37.89990 + ,34.79640 + ,35.21440 + ,36.37270 + ,36.25020 + ,36.82610 + ,36.77230 + ,36.90420 + ,37.04940 + ,36.82590 + ,36.13570 + ,36.03000 + ,35.79270 + ,35.91740 + ,35.40080 + ,35.17230 + ,34.92110 + ,35.02920 + ,34.77390 + ,34.89990 + ,34.90540 + ,34.56800 + ,34.40600 + ,34.45780 + ,34.73160 + ,34.26020 + ,33.88490 + ,34.05490 + ,34.27550 + ,34.13930 + ,34.15870 + ,34.53860 + ,33.79870 + ,33.49730 + ,33.68020 + ,34.32840 + ,34.15380 + ,33.91840 + ,34.32620 + ,34.77500 + ,35.01190 + ,34.55130 + ,34.69510 + ,35.47300 + ,35.97940 + ,36.47890 + ,36.39100 + ,36.67040 + ,37.41620 + ,37.11850 + ,36.30010 + ,35.70020 + ,35.58590 + ,35.67770 + ,35.24080 + ,34.80160 + ,34.43890 + ,34.98810 + ,36.06800 + ,36.35660 + ,36.12540 + ,34.87100 + ,35.21990 + ,34.33900 + ,33.82340 + ,34.51990 + ,35.53000 + ,35.79660 + ,33.84840 + ,33.98710 + ,34.11610 + ,33.82350 + ,32.45400 + ,31.87740 + ,31.11500 + ,31.04360 + ,30.88680 + ,31.30010 + ,30.05070 + ,28.67990 + ,27.64380 + ,27.23940 + ,26.85490 + ,27.01580 + ,26.91880 + ,26.49660 + ,26.78500 + ,26.83980 + ,26.44780 + ,25.17280 + ,24.87840 + ,25.40150 + ,25.77160 + ,26.11810 + ,26.3969 + ,26.65710 + ,25.18390 + ,23.83940 + ,23.86190 + ,24.25810 + ,25.10980 + ,26.16170 + ,26.80870 + ,25.65770 + ,27.09820 + ,27.46650 + ,28.28900 + ,28.69330 + ,27.24010 + ,27.27980 + ,27.64040 + ,26.83100 + ,26.24670 + ,25.22120 + ,25.36530 + ,26.25920 + ,27.22790 + ,26.33150 + ,25.89810 + ,26.68980) > par3 = 'additive' > par2 = 'Single' > par1 = '12' > par1 <- 5 > if (par2 == 'Single') K <- 1 > if (par2 == 'Double') K <- 2 > if (par2 == 'Triple') K <- par1 > nx <- length(x) > nxmK <- nx - K > x <- ts(x, frequency = par1) > if (par2 == 'Single') fit <- HoltWinters(x, gamma=F, beta=F) > if (par2 == 'Double') fit <- HoltWinters(x, gamma=F) > if (par2 == 'Triple') fit <- HoltWinters(x, seasonal=par3) > fit Holt-Winters exponential smoothing without trend and without seasonal component. Call: HoltWinters(x = x, beta = F, gamma = F) Smoothing parameters: alpha: 0.99994 beta : FALSE gamma: FALSE Coefficients: [,1] a 26.68975 > myresid <- x - fit$fitted[,'xhat'] > postscript(file="/var/www/rcomp/tmp/1kqst1292011454.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > op <- par(mfrow=c(2,1)) > plot(fit,ylab='Observed (black) / Fitted (red)',main='Interpolation Fit of Exponential Smoothing') > plot(myresid,ylab='Residuals',main='Interpolation Prediction Errors') > par(op) > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/2kqst1292011454.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > p <- predict(fit, par1, prediction.interval=TRUE) > np <- length(p[,1]) > plot(fit,p,ylab='Observed (black) / Fitted (red)',main='Extrapolation Fit of Exponential Smoothing') > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/3disf1292011454.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > op <- par(mfrow = c(2,2)) > acf(as.numeric(myresid),lag.max = nx/2,main='Residual ACF') > spectrum(myresid,main='Residals Periodogram') > cpgram(myresid,main='Residal Cumulative Periodogram') > qqnorm(myresid,main='Residual Normal QQ Plot') > qqline(myresid) > par(op) > dev.off() null device 1 > > #Note: the /var/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/rcomp/createtable") > > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Estimated Parameters of Exponential Smoothing',2,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Parameter',header=TRUE) > a<-table.element(a,'Value',header=TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'alpha',header=TRUE) > a<-table.element(a,fit$alpha) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'beta',header=TRUE) > a<-table.element(a,fit$beta) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'gamma',header=TRUE) > a<-table.element(a,fit$gamma) > a<-table.row.end(a) > a<-table.end(a) > table.save(a,file="/var/www/rcomp/tmp/4z0821292011454.tab") > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Interpolation Forecasts of Exponential Smoothing',4,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'t',header=TRUE) > a<-table.element(a,'Observed',header=TRUE) > a<-table.element(a,'Fitted',header=TRUE) > a<-table.element(a,'Residuals',header=TRUE) > a<-table.row.end(a) > for (i in 1:nxmK) { + a<-table.row.start(a) + a<-table.element(a,i+K,header=TRUE) + a<-table.element(a,x[i+K]) + a<-table.element(a,fit$fitted[i,'xhat']) + a<-table.element(a,myresid[i]) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/rcomp/tmp/52jpq1292011454.tab") > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Extrapolation Forecasts of Exponential Smoothing',4,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'t',header=TRUE) > a<-table.element(a,'Forecast',header=TRUE) > a<-table.element(a,'95% Lower Bound',header=TRUE) > a<-table.element(a,'95% Upper Bound',header=TRUE) > a<-table.row.end(a) > for (i in 1:np) { + a<-table.row.start(a) + a<-table.element(a,nx+i,header=TRUE) + a<-table.element(a,p[i,'fit']) + a<-table.element(a,p[i,'lwr']) + a<-table.element(a,p[i,'upr']) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/rcomp/tmp/6njne1292011454.tab") > > try(system("convert tmp/1kqst1292011454.ps tmp/1kqst1292011454.png",intern=TRUE)) character(0) > try(system("convert tmp/2kqst1292011454.ps tmp/2kqst1292011454.png",intern=TRUE)) character(0) > try(system("convert tmp/3disf1292011454.ps tmp/3disf1292011454.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.120 0.340 1.454