R version 2.13.0 (2011-04-13) Copyright (C) 2011 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(1069.108 + ,1059.362 + ,1049.495 + ,1029.082 + ,1231.089 + ,1220.388 + ,1069.108 + ,968.521 + ,978.233 + ,978.233 + ,989.056 + ,1008.514 + ,1069.108 + ,1049.495 + ,1079.775 + ,1129.547 + ,1412.683 + ,1412.683 + ,1352.244 + ,1291.65 + ,1341.422 + ,1401.983 + ,1412.683 + ,1442.964 + ,1533.833 + ,1473.244 + ,1473.244 + ,1564.114 + ,1816.014 + ,1836.427 + ,1785.734 + ,1664.578 + ,1755.42 + ,1755.42 + ,1765.165 + ,1816.014 + ,1856.04 + ,1876.453 + ,1876.453 + ,1937.014 + ,2169.452 + ,2229.89 + ,2239.603 + ,2088.322 + ,2169.452 + ,2139.171 + ,2078.582 + ,2209.478 + ,2239.603 + ,2188.909 + ,2199.61 + ,2269.916 + ,2532.64 + ,2663.352 + ,2663.352 + ,2602.913 + ,2693.66 + ,2602.913 + ,2552.092 + ,2744.509 + ,2774.634 + ,2703.378 + ,2884.967 + ,2956.228 + ,3168.103 + ,3308.711 + ,3289.258 + ,3278.43 + ,3359.559 + ,3349.692 + ,3228.692 + ,3410.253 + ,3470.847 + ,3410.253 + ,3662.154 + ,3783.309 + ,4065.362 + ,4176.65 + ,4146.492 + ,4085.897 + ,4136.624 + ,4197.185 + ,3995.056 + ,4156.204 + ,4257.779 + ,4216.798 + ,4479.366 + ,4570.08 + ,4953.837 + ,5024.138 + ,4933.418 + ,4984.117 + ,5014.398 + ,5044.678 + ,4852.261 + ,5033.856 + ,5134.437 + ,5033.856 + ,5326.854 + ,5417.607 + ,5811.037 + ,5871.631 + ,5891.089 + ,5992.631 + ,5992.631 + ,6032.657 + ,5851.063 + ,5941.938 + ,6002.377 + ,5891.089 + ,6214.246 + ,6274.812 + ,6678.021 + ,6749.283 + ,6849.864 + ,6940.739 + ,6950.451 + ,6961.152 + ,6779.563 + ,6961.152) > par3 = 'multiplicative' > par2 = 'Triple' > par1 = '12' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: Wessa P., (2010), Exponential Smoothing (v1.0.4) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_exponentialsmoothing.wasp/ > #Source of accompanying publication: > #Technical description: > par1 <- as.numeric(par1) > 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 with trend and multiplicative seasonal component. Call: HoltWinters(x = x, seasonal = par3) Smoothing parameters: alpha: 0.2142345 beta : 0.1078708 gamma: 1 Coefficients: [,1] a 6649.9242083 b 76.6686240 s1 1.0231029 s2 0.9929708 s3 1.0366455 s4 1.0376078 s5 1.0964751 s6 1.1000047 s7 1.1039833 s8 1.1056086 s9 1.0928525 s10 1.0807451 s11 1.0370583 s12 1.0468017 > myresid <- x - fit$fitted[,'xhat'] > postscript(file="/var/wessaorg/rcomp/tmp/1m9581312907156.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/wessaorg/rcomp/tmp/2n6xu1312907156.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/wessaorg/rcomp/tmp/3m0u81312907156.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/47flr1312907156.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/wessaorg/rcomp/tmp/5kyro1312907156.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/wessaorg/rcomp/tmp/67m0u1312907156.tab") > > try(system("convert tmp/1m9581312907156.ps tmp/1m9581312907156.png",intern=TRUE)) character(0) > try(system("convert tmp/2n6xu1312907156.ps tmp/2n6xu1312907156.png",intern=TRUE)) character(0) > try(system("convert tmp/3m0u81312907156.ps tmp/3m0u81312907156.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.216 0.168 1.377