R version 2.9.0 (2009-04-17) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 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(5.2 + ,7.9 + ,8.7 + ,8.9 + ,15.3 + ,15.4 + ,18.1 + ,19.7 + ,13 + ,12.6 + ,6.2 + ,3.5 + ,3.4 + ,0 + ,9.5 + ,8.9 + ,10.4 + ,13.2 + ,18.9 + ,19 + ,16.3 + ,10.6 + ,5.8 + ,3.6 + ,2.6 + ,5 + ,7.3 + ,9.2 + ,15.7 + ,16.8 + ,18.4 + ,18.1 + ,14.6 + ,7.8 + ,7.6 + ,3.8 + ,5.6 + ,2.2 + ,6.8 + ,11.8 + ,14.9 + ,16.7 + ,16.7 + ,15.9 + ,13.6 + ,9.2 + ,2.8 + ,2.5 + ,4.8 + ,2.8 + ,7.8 + ,9 + ,12.9 + ,16.4 + ,21.8 + ,17.8 + ,13.5 + ,10 + ,10.4 + ,5.5 + ,4 + ,6.8 + ,5.7 + ,9.1 + ,13.6 + ,15 + ,20.9 + ,20.4 + ,14 + ,13.7 + ,7.1 + ,0.8 + ,2.1 + ,1.3 + ,3.9 + ,10.7 + ,11.1 + ,16.4 + ,17.1 + ,17.3 + ,12.9 + ,10.9 + ,5.3 + ,0.7 + ,-0.2 + ,6.5 + ,8.6 + ,8.5 + ,13.3 + ,16.2 + ,17.5 + ,21.2 + ,14.8 + ,10.3 + ,7.3 + ,5.1 + ,4.4 + ,6.2 + ,7.7 + ,9.3 + ,15.6 + ,16.3 + ,16.6 + ,17.4 + ,15.3 + ,9.7 + ,3.7 + ,4.6 + ,5.4 + ,3.1 + ,7.9 + ,10.1 + ,15 + ,15.6 + ,19.7 + ,18.1 + ,17.7 + ,10.7 + ,6.2 + ,4.2 + ,4 + ,5.9 + ,7.1 + ,10.5 + ,15.1 + ,16.8 + ,15.3 + ,18.4 + ,16.1 + ,11.3 + ,7.9 + ,5.6 + ,3.4 + ,4.8 + ,6.5 + ,8.5 + ,15.1 + ,15.7 + ,18.7 + ,19.2 + ,12.9 + ,14.4 + ,6.2 + ,3.3 + ,4.6 + ,7.2 + ,7.8 + ,9.9 + ,13.6 + ,17.1 + ,17.8 + ,18.6 + ,14.7 + ,10.5 + ,8.6 + ,4.4 + ,2.3 + ,2.8 + ,8.8 + ,10.7 + ,13.9 + ,19.3 + ,19.5 + ,20.4 + ,15.3 + ,7.9 + ,8.3 + ,4.5 + ,3.2 + ,5 + ,6.6 + ,11.1 + ,12.8 + ,16.3 + ,17.4 + ,18.9 + ,15.8 + ,11.7 + ,6.4 + ,2.9 + ,4.7 + ,2.4 + ,7.2 + ,10.7 + ,13.4 + ,18.5 + ,18.3 + ,16.8 + ,16.6 + ,14.1 + ,6.1 + ,3.5 + ,1.7 + ,2.3 + ,4.5 + ,9.3 + ,14.2 + ,17.3 + ,23 + ,16.3 + ,18.4 + ,14.2 + ,9.1 + ,5.9 + ,7.2 + ,6.8 + ,8 + ,14.3 + ,14.6 + ,17.5 + ,17.2 + ,17.2 + ,14.1 + ,10.5 + ,6.8 + ,4.1 + ,6.5 + ,6.1 + ,6.3 + ,9.3 + ,16.4 + ,16.1 + ,18 + ,17.6 + ,14 + ,10.5 + ,6.9 + ,2.8 + ,0.7 + ,3.6 + ,6.7 + ,12.5 + ,14.4 + ,16.5 + ,18.7 + ,19.4 + ,15.8 + ,11.3 + ,9.7 + ,2.9) > par3 = 'additive' > 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 additive seasonal component. Call: HoltWinters(x = x, seasonal = par3) Smoothing parameters: alpha: 0.1091090 beta : 0.02274475 gamma: 0.2455152 Coefficients: [,1] a 10.477669469 b 0.001426859 s1 -6.568389642 s2 -5.810574792 s3 -3.515777099 s4 0.722910244 s5 4.115438393 s6 6.463704601 s7 8.198709430 s8 7.733528281 s9 4.997400332 s10 1.071603419 s11 -2.670793263 s12 -6.749721861 > myresid <- x - fit$fitted[,'xhat'] > postscript(file="/var/www/html/rcomp/tmp/159171293402974.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/html/rcomp/tmp/2g1ia1293402974.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/html/rcomp/tmp/3g1ia1293402974.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/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/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/html/rcomp/tmp/4usgj1293402974.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/html/rcomp/tmp/5m2x31293402974.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/html/rcomp/tmp/6qkw91293402974.tab") > > try(system("convert tmp/159171293402974.ps tmp/159171293402974.png",intern=TRUE)) character(0) > try(system("convert tmp/2g1ia1293402974.ps tmp/2g1ia1293402974.png",intern=TRUE)) character(0) > try(system("convert tmp/3g1ia1293402974.ps tmp/3g1ia1293402974.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.559 0.624 3.269