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(20366,22782,19169,13807,29743,25591,29096,26482,22405,27044,17970,18730,19684,19785,18479,10698,31956,29506,34506,27165,26736,23691,18157,17328,18205,20995,17382,9367,31124,26551,30651,25859,25100,25778,20418,18688,20424,24776,19814,12738,31566,30111,30019,31934,25826,26835,20205,17789,20520,22518,15572,11509,25447,24090,27786,26195,20516,22759,19028,16971) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '24' > 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 0.5698 -0.1213 -0.2795 -1.3187 1.3818 -0.8889 s.e. 0.2779 0.2648 0.3105 0.2823 0.4037 0.3565 sigma^2 estimated as 3266683: log likelihood = -172.27, aic = 358.55 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 33 End = 60 Frequency = 1 [1] 24211.623 23612.085 18123.329 17363.937 17591.568 19990.448 16213.914 [8] 8334.694 30298.231 25872.157 29992.866 25137.109 23409.820 22766.694 [15] 17280.618 16550.378 16806.480 19217.297 15435.961 7544.599 29498.464 [22] 25069.693 29193.433 24342.434 22618.242 21975.457 16487.868 15755.860 $se Time Series: Start = 33 End = 60 Frequency = 1 [1] 1890.297 1958.006 2735.642 2854.844 2883.680 2883.688 2882.265 2888.889 [9] 2925.039 2977.415 3022.387 3050.818 3776.261 3864.257 4471.810 4628.599 [17] 4698.703 4708.053 4721.907 4756.931 4828.357 4916.419 4997.292 5060.361 [25] 5693.627 5819.115 6387.208 6578.265 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 20506.642 19774.393 12761.471 11768.443 11939.556 14338.420 10564.674 [8] 2672.472 24565.155 20036.424 24068.987 19157.506 16008.348 15192.751 [15] 8515.870 7478.325 7597.022 9989.512 6181.024 -1778.987 20034.884 [22] 15433.511 19398.741 14424.127 11458.734 10569.991 3968.940 2862.461 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 27916.60 27449.78 23485.19 22959.43 23243.58 25642.48 21863.15 13996.92 [9] 36031.31 31707.89 35916.75 31116.71 30811.29 30340.64 26045.37 25622.43 [17] 26015.94 28445.08 24690.90 16868.18 38962.04 34705.87 38988.12 34260.74 [25] 33777.75 33380.92 29006.80 28649.26 > 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] 20366.000 22782.000 19169.000 13807.000 29743.000 25591.000 29096.000 [8] 26482.000 22405.000 27044.000 17970.000 18730.000 19684.000 19785.000 [15] 18479.000 10698.000 31956.000 29506.000 34506.000 27165.000 26736.000 [22] 23691.000 18157.000 17328.000 18205.000 20995.000 17382.000 9367.000 [29] 31124.000 26551.000 30651.000 25859.000 24211.623 23612.085 18123.329 [36] 17363.937 17591.568 19990.448 16213.914 8334.694 30298.231 25872.157 [43] 29992.866 25137.109 23409.820 22766.694 17280.618 16550.378 16806.480 [50] 19217.297 15435.961 7544.599 29498.464 25069.693 29193.433 24342.434 [57] 22618.242 21975.457 16487.868 15755.860 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 33 End = 60 Frequency = 1 [1] 0.07807394 0.08292390 0.15094589 0.16441223 0.16392398 0.14425329 [7] 0.17776492 0.34661004 0.09654157 0.11508181 0.10077021 0.12136709 [13] 0.16131099 0.16973290 0.25877606 0.27966724 0.27957687 0.24499041 [19] 0.30590299 0.63050820 0.16368165 0.19611008 0.17117862 0.20788228 [25] 0.25172721 0.26480065 0.38738836 0.41751227 > postscript(file="/var/www/html/rcomp/tmp/15f5m1261140069.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/2yg681261140069.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/33agy1261140069.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/4pibw1261140069.tab") > > try(system("convert tmp/15f5m1261140069.ps tmp/15f5m1261140069.png",intern=TRUE)) character(0) > try(system("convert tmp/2yg681261140069.ps tmp/2yg681261140069.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.916 0.366 1.139