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(175.348,154.439,136.186,113.662,106.157,100.546,98.314,118.179,112.295,126.938,130.92,181.279,180.389,146.917,150.597,124.222,101.554,102.138,110.315,111.015,105.017,119.888,127.623,149.415,159.755,139.737,136.283,101.952,104.044,96.712,100.665,103.699,103.765,122.732,127.297,160.278,191.784,155.375,142.616,115.331,102.136,95.205,101.566,105.273,117.394,121.148,116.666,154.841,177.74,154.427,133.159,118.102,101.361,101.345,102.233,108.522,101.939,118.405,125.06,178,167.714,143.582,139.259,104.674,103.722,106.153,106.21,113.986,96.906,107.512,112.616,148.507,130.48,137.436,128.21,97.552,91.55,83.104,84.68,85.98,84.891,89.896,94.835,115.348,131.284,134.701,127.193,87.077,72.744,77.542,78.005,85.329,86.041,96.384,116.678,160.672,152.364,144.936,122.974,94.456,82.491,84.89,85.277,81.206,71.012,87.302,97.427,133.242,137.064,119.042,116.47,96.028,79.281,73.872,80.964,86.739,89.997,96.292,101.355,136.543) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '0.5' > par1 = '12' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: Wessa P., (2009), ARIMA Forecasting (v1.0.5) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_arimaforecasting.wasp/ > #Source of accompanying publication: > #Technical description: > par1 <- as.numeric(par1) #cut off periods > 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 > par7 <- as.numeric(par7) #q > 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 ma1 sma1 0.3432 -0.7900 -0.8226 s.e. 0.1992 0.1488 0.1440 sigma^2 estimated as 0.1486: log likelihood = -51.1, aic = 110.2 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 109 End = 120 Frequency = 1 [1] 11.671822 11.138273 10.644811 9.259661 8.737598 8.683387 8.771819 [8] 8.972011 8.743256 9.357313 9.740399 11.336953 $se Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.3880339 0.4432823 0.4695787 0.4884700 0.5048418 0.5201152 0.5347605 [8] 0.5489522 0.5627675 0.5762525 0.5894477 0.6024003 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 109 End = 120 Frequency = 1 [1] 10.911275 10.269440 9.724436 8.302260 7.748108 7.663961 7.723688 [8] 7.896065 7.640232 8.227858 8.585082 10.156248 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 109 End = 120 Frequency = 1 [1] 12.432368 12.007106 11.565185 10.217062 9.727088 9.702813 9.819949 [8] 10.047958 9.846280 10.486768 10.895716 12.517657 > 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] 175.34800 154.43900 136.18600 113.66200 106.15700 100.54600 98.31400 [8] 118.17900 112.29500 126.93800 130.92000 181.27900 180.38900 146.91700 [15] 150.59700 124.22200 101.55400 102.13800 110.31500 111.01500 105.01700 [22] 119.88800 127.62300 149.41500 159.75500 139.73700 136.28300 101.95200 [29] 104.04400 96.71200 100.66500 103.69900 103.76500 122.73200 127.29700 [36] 160.27800 191.78400 155.37500 142.61600 115.33100 102.13600 95.20500 [43] 101.56600 105.27300 117.39400 121.14800 116.66600 154.84100 177.74000 [50] 154.42700 133.15900 118.10200 101.36100 101.34500 102.23300 108.52200 [57] 101.93900 118.40500 125.06000 178.00000 167.71400 143.58200 139.25900 [64] 104.67400 103.72200 106.15300 106.21000 113.98600 96.90600 107.51200 [71] 112.61600 148.50700 130.48000 137.43600 128.21000 97.55200 91.55000 [78] 83.10400 84.68000 85.98000 84.89100 89.89600 94.83500 115.34800 [85] 131.28400 134.70100 127.19300 87.07700 72.74400 77.54200 78.00500 [92] 85.32900 86.04100 96.38400 116.67800 160.67200 152.36400 144.93600 [99] 122.97400 94.45600 82.49100 84.89000 85.27700 81.20600 71.01200 [106] 87.30200 97.42700 133.24200 136.23143 124.06112 113.31199 85.74132 [113] 76.34562 75.40121 76.94480 80.49699 76.44453 87.55930 94.87537 [120] 128.52650 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.06865701 0.08270065 0.09204093 0.11095928 0.12209928 0.12682743 [7] 0.12921137 0.12970738 0.13685201 0.13059949 0.12820935 0.11180594 > postscript(file="/var/www/rcomp/tmp/1m4931293302165.ps",horizontal=F,onefile=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/rcomp/tmp/2bnox1293302165.ps",horizontal=F,onefile=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/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,'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/rcomp/tmp/306381293302165.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/rcomp/tmp/43oke1293302165.tab") > > try(system("convert tmp/1m4931293302165.ps tmp/1m4931293302165.png",intern=TRUE)) character(0) > try(system("convert tmp/2bnox1293302165.ps tmp/2bnox1293302165.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.880 0.220 1.063