R version 2.13.0 (2011-04-13) Copyright (C) 2011 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(18992,0,21552,1868501,7185612,10348382,6942386,4306121,2833176,1515513,1242981,699343,89497,128,10585,1070323,7167741,13193530,7885720,6785683,3106846,1706331,1286534,499079,24637,16,27309,873433,8435418,11290088,6840395,3803252,4388988,2680940,1174135,328388,22943,5657,28156,770831,8378147,13274946,7297840,2848227,2892179,1762224,1009375,188388,3393,0,13807,2619905,13297704,6240087,5108460,4553381,3148546,2433387,1748108,723454,58525,792,42585,1634386,10360570,6798599,4847748,4971202,343863,2200366,1549422,90144,63288,338,44863,1678135,9293357,9361258,6766402,4331272,3518962,2425786,1701795,552452,16104,0,90198,1731332,7954135,11561342,6834733,4255652,4243070,3415216,1841237,655456) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '0' > par6 = '0' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '1' > par1 = '12' > 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 <- 6 #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 ar3 ar4 ar5 ar6 sar1 sma1 -0.0421 -0.1716 0.0112 -0.0649 -0.0066 -0.0175 0.3101 -1.0000 s.e. 0.1176 0.1171 0.1175 0.1185 0.1150 0.1216 0.1272 0.3149 sigma^2 estimated as 1.392e+12: log likelihood = -1117.37, aic = 2252.75 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 85 End = 96 Frequency = 1 [1] -122086.30 -55534.81 18620.96 1563336.51 9135837.60 9837556.86 [7] 6629649.70 4443941.58 3106776.50 2191823.40 1494314.53 488036.71 $se Time Series: Start = 85 End = 96 Frequency = 1 [1] 1252572 1253663 1271288 1271684 1272529 1272573 1272574 1272574 1272578 [10] 1272573 1272352 1272339 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 85 End = 96 Frequency = 1 [1] -2577127.6 -2512713.4 -2473104.4 -929164.1 6641681.4 7343313.4 [7] 4135405.5 1949696.7 612523.4 -302419.9 -999495.7 -2005746.8 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 85 End = 96 Frequency = 1 [1] 2332955 2401644 2510346 4055837 11629994 12331800 9123894 6938187 [9] 5601030 4686067 3988125 2981820 > 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] 18992.00 0.00 21552.00 1868501.00 7185612.00 10348382.00 [7] 6942386.00 4306121.00 2833176.00 1515513.00 1242981.00 699343.00 [13] 89497.00 128.00 10585.00 1070323.00 7167741.00 13193530.00 [19] 7885720.00 6785683.00 3106846.00 1706331.00 1286534.00 499079.00 [25] 24637.00 16.00 27309.00 873433.00 8435418.00 11290088.00 [31] 6840395.00 3803252.00 4388988.00 2680940.00 1174135.00 328388.00 [37] 22943.00 5657.00 28156.00 770831.00 8378147.00 13274946.00 [43] 7297840.00 2848227.00 2892179.00 1762224.00 1009375.00 188388.00 [49] 3393.00 0.00 13807.00 2619905.00 13297704.00 6240087.00 [55] 5108460.00 4553381.00 3148546.00 2433387.00 1748108.00 723454.00 [61] 58525.00 792.00 42585.00 1634386.00 10360570.00 6798599.00 [67] 4847748.00 4971202.00 343863.00 2200366.00 1549422.00 90144.00 [73] 63288.00 338.00 44863.00 1678135.00 9293357.00 9361258.00 [79] 6766402.00 4331272.00 3518962.00 2425786.00 1701795.00 552452.00 [85] -122086.30 -55534.81 18620.96 1563336.51 9135837.60 9837556.86 [91] 6629649.70 4443941.58 3106776.50 2191823.40 1494314.53 488036.71 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 85 End = 96 Frequency = 1 [1] -10.2597269 -22.5743569 68.2719080 0.8134422 0.1392898 0.1293587 [7] 0.1919519 0.2863615 0.4096137 0.5806002 0.8514621 2.6070550 > postscript(file="/var/wessaorg/rcomp/tmp/16htr1324554117.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/wessaorg/rcomp/tmp/2lsji1324554117.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/3w8np1324554117.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/wessaorg/rcomp/tmp/4hqiv1324554117.tab") > > try(system("convert tmp/16htr1324554117.ps tmp/16htr1324554117.png",intern=TRUE)) character(0) > try(system("convert tmp/2lsji1324554117.ps tmp/2lsji1324554117.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.289 0.251 2.536