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(420.677 + ,417.428 + ,423.245 + ,423.113 + ,418.873 + ,405.733 + ,397.812 + ,389.918 + ,391.116 + ,443.814 + ,460.373 + ,455.422 + ,456.288 + ,452.233 + ,459.256 + ,461.146 + ,451.391 + ,443.101 + ,438.81 + ,430.457 + ,435.721 + ,488.28 + ,505.814 + ,502.338 + ,500.91 + ,501.434 + ,515.476 + ,520.862 + ,519.517 + ,511.805 + ,508.607 + ,505.327 + ,511.435 + ,570.158 + ,591.665 + ,593.572 + ,586.346 + ,586.063 + ,591.504 + ,594.033 + ,585.597 + ,572.45 + ,562.917 + ,554.675 + ,553.997 + ,601.31 + ,622.255 + ,616.735 + ,606.48 + ,595.079 + ,598.588 + ,599.917 + ,591.573 + ,575.489 + ,567.223 + ,555.338 + ,555.252 + ,608.249 + ,630.859 + ,628.632 + ,624.435 + ,609.67 + ,615.83 + ,621.17 + ,604.212 + ,584.348 + ,573.717 + ,555.234 + ,544.897 + ,598.866 + ,620.081 + ,607.699 + ,589.96 + ,578.665 + ,580.166 + ,579.457 + ,571.56 + ,560.46 + ,551.397 + ,536.763 + ,540.562 + ,588.184 + ,607.049 + ,598.968 + ,577.644 + ,562.64 + ,565.867 + ,561.274 + ,554.144 + ,539.9 + ,526.271 + ,511.841 + ,505.282 + ,554.083 + ,584.225 + ,568.858 + ,539.516 + ,521.612 + ,525.562 + ,526.519 + ,515.713 + ,503.454 + ,489.301 + ,479.02 + ,475.102 + ,523.682 + ,551.528 + ,531.626 + ,511.037 + ,492.417 + ,492.188 + ,492.865 + ,480.961 + ,461.935 + ,456.608 + ,441.977 + ,439.148 + ,488.18 + ,520.564 + ,501.492 + ,485.025 + ,464.196 + ,460.17 + ,467.037 + ,460.07 + ,447.988 + ,442.867 + ,436.087 + ,431.328 + ,484.015 + ,509.673 + ,512.927 + ,502.831 + ,470.984 + ,471.067 + ,476.049 + ,474.605 + ,470.439 + ,461.251 + ,454.724 + ,455.626 + ,516.847 + ,525.192 + ,522.975 + ,518.585 + ,509.239 + ,512.238 + ,519.164 + ,517.009 + ,509.933 + ,509.127 + ,500.857 + ,506.971 + ,569.323 + ,579.714 + ,577.992 + ,565.464 + ,547.344 + ,554.788 + ,562.325 + ,560.854 + ,555.332 + ,543.599 + ,536.662 + ,542.722 + ,593.53 + ,610.763 + ,612.613 + ,611.324 + ,594.167 + ,595.454 + ,590.865 + ,589.379 + ,584.428 + ,573.1 + ,567.456 + ,569.028 + ,620.735 + ,628.884 + ,628.232 + ,612.117 + ,595.404 + ,597.141 + ,593.408 + ,590.072 + ,579.799 + ,574.205 + ,572.775 + ,572.942 + ,619.567 + ,625.809 + ,619.916 + ,587.625 + ,565.742 + ,557.274 + ,560.576 + ,548.854 + ,531.673 + ,525.919 + ,511.038 + ,498.662 + ,555.362 + ,564.591 + ,541.657 + ,527.07 + ,509.846 + ,514.258 + ,516.922 + ,507.561 + ,492.622 + ,490.243 + ,469.357 + ,477.58 + ,528.379 + ,533.59 + ,517.945 + ,506.174 + ,501.866 + ,516.141 + ,528.222 + ,532.638 + ,536.322 + ,536.535 + ,523.597 + ,536.214 + ,586.57 + ,596.594 + ,580.523 + ,564.478 + ,557.56 + ,575.093 + ,580.112 + ,574.761 + ,563.25 + ,551.531 + ,537.034 + ,544.686 + ,600.991 + ,604.378 + ,586.111 + ,563.668 + ,548.604 + ,551.174 + ,555.654 + ,547.97 + ,540.324 + ,530.577 + ,520.579 + ,518.654 + ,572.273 + ,581.302 + ,563.28 + ,547.612) > par3 = 'additive' > par2 = 'Triple' > par1 = '12' > 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=0, beta=0) > if (par2 == 'Double') fit <- HoltWinters(x, gamma=0) > 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.8992035 beta : 0.07267612 gamma: 1 Coefficients: [,1] a 541.3110517 b -0.8934555 s1 -3.2878335 s2 5.5191098 s3 11.6765513 s4 5.7810771 s5 -7.0394193 s6 -19.0808231 s7 -33.6122816 s8 -33.6175269 s9 16.3239176 s10 26.7538404 s11 17.8456910 s12 6.3009483 > myresid <- x - fit$fitted[,'xhat'] > postscript(file="/var/wessaorg/rcomp/tmp/1z4ni1322557044.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/27cn31322557044.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/3lrbw1322557044.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/4ygk21322557044.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/5m2o91322557044.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/67pa81322557044.tab") > > try(system("convert tmp/1z4ni1322557044.ps tmp/1z4ni1322557044.png",intern=TRUE)) character(0) > try(system("convert tmp/27cn31322557044.ps tmp/27cn31322557044.png",intern=TRUE)) character(0) > try(system("convert tmp/3lrbw1322557044.ps tmp/3lrbw1322557044.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.808 0.175 1.986