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(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 = '0' > 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: ma1 sma1 -0.5808 -0.9223 s.e. 0.1163 0.4473 sigma^2 estimated as 80.43: log likelihood = -309.51, aic = 625.02 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 97 End = 120 Frequency = 1 [1] 157.79478 140.00860 130.87286 101.76604 91.87410 89.42362 91.75982 [8] 97.94648 94.97354 106.66372 112.99801 150.05176 156.15211 138.36593 [15] 129.23019 100.12337 90.23143 87.78095 90.11715 96.30381 93.33087 [22] 105.02105 111.35534 148.40909 $se Time Series: Start = 97 End = 120 Frequency = 1 [1] 9.260213 10.034180 10.752582 11.425902 12.061695 12.665611 13.242014 [8] 13.794353 14.325411 14.837474 15.332445 15.811929 16.637867 17.193835 [15] 17.732380 18.255044 18.763155 19.257864 19.740178 20.210986 20.671074 [22] 21.121142 21.561817 21.993665 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 97 End = 120 Frequency = 1 [1] 139.64477 120.34161 109.79780 79.37127 68.23318 64.59903 65.80547 [8] 70.90955 66.89573 77.58228 82.94642 119.06038 123.54189 104.66601 [15] 94.47472 64.34348 53.45565 50.03554 51.42640 56.69028 52.81556 [22] 63.62362 69.09418 105.30151 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 97 End = 120 Frequency = 1 [1] 175.9448 159.6756 151.9479 124.1608 115.5150 114.2482 117.7142 124.9834 [9] 123.0513 135.7452 143.0496 181.0431 188.7623 172.0658 163.9857 135.9033 [17] 127.0072 125.5264 128.8079 135.9173 133.8462 146.4185 153.6165 191.5167 > 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 157.79478 140.00860 [99] 130.87286 101.76604 91.87410 89.42362 91.75982 97.94648 94.97354 [106] 106.66372 112.99801 150.05176 156.15211 138.36593 129.23019 100.12337 [113] 90.23143 87.78095 90.11715 96.30381 93.33087 105.02105 111.35534 [120] 148.40909 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 97 End = 120 Frequency = 1 [1] 0.05868516 0.07166831 0.08216052 0.11227618 0.13128503 0.14163608 [7] 0.14431168 0.14083561 0.15083581 0.13910515 0.13568774 0.10537649 [13] 0.10654910 0.12426350 0.13721546 0.18232551 0.20794478 0.21938545 [19] 0.21905019 0.20986694 0.22148164 0.20111341 0.19363075 0.14819621 > postscript(file="/var/www/html/rcomp/tmp/16u8r1293305842.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/224nz1293305842.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/3rnkb1293305842.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/4u5jz1293305842.tab") > > try(system("convert tmp/16u8r1293305842.ps tmp/16u8r1293305842.png",intern=TRUE)) character(0) > try(system("convert tmp/224nz1293305842.ps tmp/224nz1293305842.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.743 0.325 1.563