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(216234,213587,209465,204045,200237,203666,241476,260307,243324,244460,233575,237217,235243,230354,227184,221678,217142,219452,256446,265845,248624,241114,229245,231805,219277,219313,212610,214771,211142,211457,240048,240636,230580,208795,197922,194596,194581,185686,178106,172608,167302,168053,202300,202388,182516,173476,166444,171297,169701,164182,161914,159612,151001,158114,186530,187069,174330,169362,166827,178037,186412,189226,191563,188906,186005,195309,223532,226899,214126) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '0' > par6 = '2' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '12' > par1 <- as.numeric(par1) #cut off periods > par1 <- 28 > par2 <- as.numeric(par2) #lambda > par3 <- as.numeric(par3) #degree of non-seasonal differencing > par4 <- as.numeric(par4) #degree of seasonal differencing > par5 <- as.numeric(par5) #seasonal period > par6 <- as.numeric(par6) #p > par6 <- 3 > par7 <- as.numeric(par7) #q > par7 <- 3 > par8 <- as.numeric(par8) #P > par9 <- as.numeric(par9) #Q > if (par10 == 'TRUE') par10 <- TRUE > if (par10 == 'FALSE') par10 <- FALSE > if (par2 == 0) x <- log(x) > if (par2 != 0) x <- x^par2 > lx <- length(x) > first <- lx - 2*par1 > nx <- lx - par1 > nx1 <- nx + 1 > fx <- lx - nx > if (fx < 1) { + fx <- par5 + nx1 <- lx + fx - 1 + first <- lx - 2*fx + } > first <- 1 > if (fx < 3) fx <- round(lx/10,0) > (arima.out <- arima(x[1:nx], order=c(par6,par3,par7), seasonal=list(order=c(par8,par4,par9), period=par5), include.mean=par10, method='ML')) Call: arima(x = x[1:nx], order = c(par6, par3, par7), seasonal = list(order = c(par8, par4, par9), period = par5), include.mean = par10, method = "ML") Coefficients: ar1 ar2 ar3 ma1 ma2 ma3 sma1 -0.8354 0.8496 0.9844 0.8028 -0.7735 -0.9844 0.0061 s.e. 0.0630 0.0358 0.0348 0.2857 0.1513 0.2995 0.2815 sigma^2 estimated as 21540385: log likelihood = -279.1, aic = 574.2 Warning message: In arima(x[1:nx], order = c(par6, par3, par7), seasonal = list(order = c(par8, : possible convergence problem: optim gave code=1 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 42 End = 69 Frequency = 1 [1] 168638.124 190807.248 194677.221 177483.073 158172.666 142348.239 [7] 138233.699 137232.986 123650.762 118292.290 105905.947 103635.958 [13] 98813.118 121946.672 122759.817 102875.464 84164.699 62544.509 [19] 61132.620 53540.484 42055.043 32005.560 18830.453 15298.061 [25] 6241.634 31062.729 25626.578 8228.646 $se Time Series: Start = 42 End = 69 Frequency = 1 [1] 4819.989 6601.010 8437.874 9664.778 11115.991 12225.722 13426.237 [8] 14538.042 15558.887 16690.531 17608.279 18721.469 21598.346 24286.155 [15] 26918.104 29184.849 31672.464 33741.473 36064.480 38082.672 40214.844 [22] 42261.009 44218.829 46300.115 49758.794 53265.436 56583.369 59826.088 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 42 End = 69 Frequency = 1 [1] 159190.946 177869.270 178138.987 158540.108 136385.322 118385.823 [7] 111918.273 108738.424 93155.343 85578.850 71393.720 66941.880 [13] 56480.361 74345.809 70000.333 45673.160 22086.670 -3588.779 [19] -9553.762 -21101.554 -36766.052 -50826.018 -67838.451 -75450.165 [25] -91285.601 -73337.525 -85276.826 -109030.487 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 42 End = 69 Frequency = 1 [1] 178085.3 203745.2 211215.5 196426.0 179960.0 166310.7 164549.1 165727.5 [9] 154146.2 151005.7 140418.2 140330.0 141145.9 169547.5 175519.3 160077.8 [17] 146242.7 128677.8 131819.0 128182.5 120876.1 114837.1 105499.4 106046.3 [25] 103768.9 135463.0 136530.0 125487.8 > if (par2 == 0) { + x <- exp(x) + forecast$pred <- exp(forecast$pred) + lb <- exp(lb) + ub <- exp(ub) + } > if (par2 != 0) { + x <- x^(1/par2) + forecast$pred <- forecast$pred^(1/par2) + lb <- lb^(1/par2) + ub <- ub^(1/par2) + } > if (par2 < 0) { + olb <- lb + lb <- ub + ub <- olb + } > (actandfor <- c(x[1:nx], forecast$pred)) [1] 216234.000 213587.000 209465.000 204045.000 200237.000 203666.000 [7] 241476.000 260307.000 243324.000 244460.000 233575.000 237217.000 [13] 235243.000 230354.000 227184.000 221678.000 217142.000 219452.000 [19] 256446.000 265845.000 248624.000 241114.000 229245.000 231805.000 [25] 219277.000 219313.000 212610.000 214771.000 211142.000 211457.000 [31] 240048.000 240636.000 230580.000 208795.000 197922.000 194596.000 [37] 194581.000 185686.000 178106.000 172608.000 167302.000 168638.124 [43] 190807.248 194677.221 177483.073 158172.666 142348.239 138233.699 [49] 137232.986 123650.762 118292.290 105905.947 103635.958 98813.118 [55] 121946.672 122759.817 102875.464 84164.699 62544.509 61132.620 [61] 53540.484 42055.043 32005.560 18830.453 15298.061 6241.634 [67] 31062.729 25626.578 8228.646 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 42 End = 69 Frequency = 1 [1] 0.02858185 0.03459517 0.04334289 0.05445465 0.07027758 0.08588601 [7] 0.09712709 0.10593693 0.12582929 0.14109568 0.16626337 0.18064646 [13] 0.21857772 0.19915389 0.21927455 0.28369105 0.37631530 0.53947939 [19] 0.58993841 0.71128741 0.95624309 1.32042712 2.34826153 3.02653497 [25] 7.97207752 1.71476999 2.20799551 7.27046555 > postscript(file="/var/www/html/rcomp/tmp/17o7f1260310895.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > opar <- par(mar=c(4,4,2,2),las=1) > ylim <- c( min(x[first:nx],lb), max(x[first:nx],ub)) > plot(x,ylim=ylim,type='n',xlim=c(first,lx)) > usr <- par('usr') > rect(usr[1],usr[3],nx+1,usr[4],border=NA,col='lemonchiffon') > rect(nx1,usr[3],usr[2],usr[4],border=NA,col='lavender') > abline(h= (-3:3)*2 , col ='gray', lty =3) > polygon( c(nx1:lx,lx:nx1), c(lb,rev(ub)), col = 'orange', lty=2,border=NA) > lines(nx1:lx, lb , lty=2) > lines(nx1:lx, ub , lty=2) > lines(x, lwd=2) > lines(nx1:lx, forecast$pred , lwd=2 , col ='white') > box() > par(opar) > dev.off() null device 1 > prob.dec <- array(NA, dim=fx) > prob.sdec <- array(NA, dim=fx) > prob.ldec <- array(NA, dim=fx) > prob.pval <- array(NA, dim=fx) > perf.pe <- array(0, dim=fx) > perf.mape <- array(0, dim=fx) > perf.mape1 <- array(0, dim=fx) > perf.se <- array(0, dim=fx) > perf.mse <- array(0, dim=fx) > perf.mse1 <- array(0, dim=fx) > perf.rmse <- array(0, dim=fx) > for (i in 1:fx) { + locSD <- (ub[i] - forecast$pred[i]) / 1.96 + perf.pe[i] = (x[nx+i] - forecast$pred[i]) / forecast$pred[i] + perf.se[i] = (x[nx+i] - forecast$pred[i])^2 + prob.dec[i] = pnorm((x[nx+i-1] - forecast$pred[i]) / locSD) + prob.sdec[i] = pnorm((x[nx+i-par5] - forecast$pred[i]) / locSD) + prob.ldec[i] = pnorm((x[nx] - forecast$pred[i]) / locSD) + prob.pval[i] = pnorm(abs(x[nx+i] - forecast$pred[i]) / locSD) + } > perf.mape[1] = abs(perf.pe[1]) > perf.mse[1] = abs(perf.se[1]) > for (i in 2:fx) { + perf.mape[i] = perf.mape[i-1] + abs(perf.pe[i]) + perf.mape1[i] = perf.mape[i] / i + perf.mse[i] = perf.mse[i-1] + perf.se[i] + perf.mse1[i] = perf.mse[i] / i + } > perf.rmse = sqrt(perf.mse1) > postscript(file="/var/www/html/rcomp/tmp/2o3781260310895.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(forecast$pred, pch=19, type='b',main='ARIMA Extrapolation Forecast', ylab='Forecast and 95% CI', xlab='time',ylim=c(min(lb),max(ub))) > dum <- forecast$pred > dum[1:par1] <- x[(nx+1):lx] > lines(dum, lty=1) > lines(ub,lty=3) > lines(lb,lty=3) > 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,'Univariate ARIMA Extrapolation Forecast',9,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'time',1,header=TRUE) > a<-table.element(a,'Y[t]',1,header=TRUE) > a<-table.element(a,'F[t]',1,header=TRUE) > a<-table.element(a,'95% LB',1,header=TRUE) > a<-table.element(a,'95% UB',1,header=TRUE) > a<-table.element(a,'p-value
(H0: Y[t] = F[t])',1,header=TRUE) > a<-table.element(a,'P(F[t]>Y[t-1])',1,header=TRUE) > a<-table.element(a,'P(F[t]>Y[t-s])',1,header=TRUE) > mylab <- paste('P(F[t]>Y[',nx,sep='') > mylab <- paste(mylab,'])',sep='') > a<-table.element(a,mylab,1,header=TRUE) > a<-table.row.end(a) > for (i in (nx-par5):nx) { + a<-table.row.start(a) + a<-table.element(a,i,header=TRUE) + a<-table.element(a,x[i]) + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.row.end(a) + } > for (i in 1:fx) { + a<-table.row.start(a) + a<-table.element(a,nx+i,header=TRUE) + a<-table.element(a,round(x[nx+i],4)) + a<-table.element(a,round(forecast$pred[i],4)) + a<-table.element(a,round(lb[i],4)) + a<-table.element(a,round(ub[i],4)) + a<-table.element(a,round((1-prob.pval[i]),4)) + a<-table.element(a,round((1-prob.dec[i]),4)) + a<-table.element(a,round((1-prob.sdec[i]),4)) + a<-table.element(a,round((1-prob.ldec[i]),4)) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/html/rcomp/tmp/3jvht1260310895.tab") > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Univariate ARIMA Extrapolation Forecast Performance',7,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'time',1,header=TRUE) > a<-table.element(a,'% S.E.',1,header=TRUE) > a<-table.element(a,'PE',1,header=TRUE) > a<-table.element(a,'MAPE',1,header=TRUE) > a<-table.element(a,'Sq.E',1,header=TRUE) > a<-table.element(a,'MSE',1,header=TRUE) > a<-table.element(a,'RMSE',1,header=TRUE) > a<-table.row.end(a) > for (i in 1:fx) { + a<-table.row.start(a) + a<-table.element(a,nx+i,header=TRUE) + a<-table.element(a,round(perc.se[i],4)) + a<-table.element(a,round(perf.pe[i],4)) + a<-table.element(a,round(perf.mape1[i],4)) + a<-table.element(a,round(perf.se[i],4)) + a<-table.element(a,round(perf.mse1[i],4)) + a<-table.element(a,round(perf.rmse[i],4)) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/html/rcomp/tmp/49xt41260310895.tab") > > system("convert tmp/17o7f1260310895.ps tmp/17o7f1260310895.png") > system("convert tmp/2o3781260310895.ps tmp/2o3781260310895.png") > > > proc.time() user system elapsed 2.493 0.473 2.705