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(17885.8,16937.6,16184.9,18148.5,19053.2,20976.7,21272.7,22421.3,23294.5,24382.9,22426.1,20486.0,21382.5,17905.4,20531.3,21459.1,22317.6,23989.7,24632.0,26713.3,27570.6,29388.6,27775.1,24109.,25640.6,23038.9,22723.0,24241.5,25290.6,27071.0,28601.2,28424.5,29419.0,31555.4,29780.7,25656.6,26193.0,24095.9,22440.2,25951.7,27634.5,27930.6,31247.3,31823.7,33078.7,34032.4,28265.0,25079.5,24743.5,18845.5,21224.7,21920.6,22734.1,23972.8,25671.1,25798.1,27893.9,29557.8,27541.7,26470.1,25185.1,23363.8,24300.2,25905.7,29036.8,32866.5,33260.0,35288.5,34999.2,34820.2) > par10 = 'FALSE' > par9 = '0' > par8 = '2' > par7 = '0' > par6 = '2' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '24' > #'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 ar2 sar1 sar2 -0.6257 -0.3430 -0.5238 -0.2997 s.e. 0.1784 0.1702 0.2466 0.3129 sigma^2 estimated as 907112: log likelihood = -275.61, aic = 561.22 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 47 End = 70 Frequency = 1 [1] 32625.77 29290.40 30005.39 27466.15 27393.16 29655.17 30967.03 32006.60 [9] 34116.24 34978.65 36055.51 37532.32 35982.00 32370.59 33290.11 30831.40 [17] 30330.88 32650.07 33966.35 35061.30 37267.81 37754.74 38846.84 40404.07 $se Time Series: Start = 47 End = 70 Frequency = 1 [1] 952.4242 1016.9518 1093.7817 1237.1954 1317.3588 1399.0141 1486.5304 [8] 1561.0192 1633.7224 1704.8919 1771.7498 1836.5548 2062.2524 2163.2224 [15] 2266.2512 2390.0570 2490.2341 2588.9441 2688.0362 2780.3928 2870.4317 [22] 2958.3653 3043.1617 3125.8166 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 47 End = 70 Frequency = 1 [1] 30759.02 27297.18 27861.58 25041.25 24811.14 26913.10 28053.44 28947.01 [9] 30914.15 31637.06 32582.88 33932.68 31939.99 28130.68 28848.26 26146.89 [17] 25450.02 27575.74 28697.80 29611.73 31641.76 31956.34 32882.24 34277.47 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 47 End = 70 Frequency = 1 [1] 34492.52 31283.63 32149.21 29891.05 29975.19 32397.23 33880.63 35066.20 [9] 37318.34 38320.24 39528.14 41131.97 40024.02 36610.51 37731.96 35515.91 [17] 35211.74 37724.40 39234.91 40510.87 42893.85 43553.13 44811.43 46530.67 > 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] 17885.80 16937.60 16184.90 18148.50 19053.20 20976.70 21272.70 22421.30 [9] 23294.50 24382.90 22426.10 20486.00 21382.50 17905.40 20531.30 21459.10 [17] 22317.60 23989.70 24632.00 26713.30 27570.60 29388.60 27775.10 24109.00 [25] 25640.60 23038.90 22723.00 24241.50 25290.60 27071.00 28601.20 28424.50 [33] 29419.00 31555.40 29780.70 25656.60 26193.00 24095.90 22440.20 25951.70 [41] 27634.50 27930.60 31247.30 31823.70 33078.70 34032.40 32625.77 29290.40 [49] 30005.39 27466.15 27393.16 29655.17 30967.03 32006.60 34116.24 34978.65 [57] 36055.51 37532.32 35982.00 32370.59 33290.11 30831.40 30330.88 32650.07 [65] 33966.35 35061.30 37267.81 37754.74 38846.84 40404.07 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 47 End = 70 Frequency = 1 [1] 0.02919239 0.03471963 0.03645284 0.04504437 0.04809079 0.04717607 [7] 0.04800364 0.04877179 0.04788694 0.04874093 0.04913950 0.04893262 [13] 0.05731344 0.06682677 0.06807581 0.07752022 0.08210228 0.07929368 [19] 0.07913820 0.07930090 0.07702175 0.07835746 0.07833744 0.07736390 > postscript(file="/var/www/html/rcomp/tmp/1wupo1293198650.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/html/rcomp/tmp/2a4nx1293198650.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/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/3rw1u1293198650.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/4vx0h1293198650.tab") > > try(system("convert tmp/1wupo1293198650.ps tmp/1wupo1293198650.png",intern=TRUE)) character(0) > try(system("convert tmp/2a4nx1293198650.ps tmp/2a4nx1293198650.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.041 0.364 5.402