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(593530.00,610943.00,612613.00,611324.00,594167.00,595454.00,590865.00,589379.00,584428.00,573100.00,567456.00,569028.00,620735.00,628884.00,628232.00,612117.00,595404.00,597141.00,593408.00,590072.00,579799.00,574205.00,572775.00,572942.00,619567.00,625809.00,619916.00,587625.00,565742.00,557274.00,560576.00,548854.00,531673.00,525919.00,511038.00,498662.00,555362.00,564591.00,541657.00,527070.00,509846.00,514258.00,516922.00,507561.00,492622.00,490243.00,469357.00,477580.00,528379.00,533590.00,517945.00,506174.00,501866.00,516141.00,528222.00,532638.00,536322.00,536535.00,523597.00,536214.00,586570.00,596594.00,580523.00) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '2' > 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.1741 0.3642 0.4610 -0.0879 0.1133 -0.9864 s.e. 0.3263 0.2536 0.2561 0.2267 0.2251 0.2108 sigma^2 estimated as 28004572: log likelihood = -222.51, aic = 459.02 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 36 End = 63 Frequency = 1 [1] 512130.2 549465.8 555090.7 546133.8 508802.0 484641.0 472528.2 472042.1 [9] 457282.9 436513.3 427282.0 409088.5 406683.2 440600.3 442829.2 430423.7 [17] 389678.7 362101.9 346561.5 342661.1 324484.5 300296.2 287651.1 266042.7 [25] 260223.5 290728.8 289546.0 273730.2 $se Time Series: Start = 36 End = 63 Frequency = 1 [1] 5569.113 8192.714 11895.098 13721.431 15714.671 17794.443 19479.959 [8] 21241.714 22961.263 24572.617 26200.071 27790.461 31677.904 35413.358 [15] 40022.956 43487.270 47073.252 50721.805 54033.533 57393.869 60702.596 [22] 63901.369 67100.941 70254.644 75316.889 80318.767 86070.321 90949.854 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 36 End = 63 Frequency = 1 [1] 501214.75 533408.04 531776.27 519239.79 478001.23 449763.91 434347.45 [8] 430408.30 412278.87 388350.94 375929.86 354619.18 344594.46 371190.12 [15] 364384.17 345188.63 297415.15 262687.20 240655.76 230169.11 205507.42 [22] 175049.53 156133.26 128343.59 112602.41 133304.02 120848.21 95468.46 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 36 End = 63 Frequency = 1 [1] 523045.7 565523.5 578405.0 573027.8 539602.7 519518.1 510708.9 513675.8 [9] 502287.0 484675.6 478634.1 463557.8 468771.8 510010.5 521274.2 515658.7 [17] 481942.3 461516.7 452467.2 455153.1 443461.6 425542.9 419168.9 403741.8 [25] 407844.6 448153.6 458243.9 451991.9 > 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] 593530.0 610943.0 612613.0 611324.0 594167.0 595454.0 590865.0 589379.0 [9] 584428.0 573100.0 567456.0 569028.0 620735.0 628884.0 628232.0 612117.0 [17] 595404.0 597141.0 593408.0 590072.0 579799.0 574205.0 572775.0 572942.0 [25] 619567.0 625809.0 619916.0 587625.0 565742.0 557274.0 560576.0 548854.0 [33] 531673.0 525919.0 511038.0 512130.2 549465.8 555090.7 546133.8 508802.0 [41] 484641.0 472528.2 472042.1 457282.9 436513.3 427282.0 409088.5 406683.2 [49] 440600.3 442829.2 430423.7 389678.7 362101.9 346561.5 342661.1 324484.5 [57] 300296.2 287651.1 266042.7 260223.5 290728.8 289546.0 273730.2 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 36 End = 63 Frequency = 1 [1] 0.01087441 0.01491033 0.02142911 0.02512467 0.03088563 0.03671675 [7] 0.04122497 0.04499962 0.05021238 0.05629295 0.06131799 0.06793264 [13] 0.07789333 0.08037525 0.09038013 0.10103364 0.12080016 0.14007604 [19] 0.15591327 0.16749456 0.18707394 0.21279446 0.23327197 0.26407282 [25] 0.28943153 0.27626698 0.29725954 0.33226098 > postscript(file="/var/www/html/rcomp/tmp/1109x1260458654.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/2zddh1260458654.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/3kz7j1260458654.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/45u0b1260458654.tab") > > system("convert tmp/1109x1260458654.ps tmp/1109x1260458654.png") > system("convert tmp/2zddh1260458654.ps tmp/2zddh1260458654.png") > > > proc.time() user system elapsed 0.936 0.338 2.155