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(9051,8823,8776,8255,7969,8758,8693,8271,7790,7769,8170,8209,9395,9260,9018,8501,8500,9649,9319,8830,8436,8169,8269,7945,9144,8770,8834,7837,7792,8616,8518,7940,7545,7531,7665,7599,8444,8549,7986,7335,7287,7870,7839,7327,7259,6964,7271,6956,7608,7692,7255,6804,6655,7341,7602,7086,6625,6272,6576,6491,7649,7400,6913,6532,6486,7295,7556,7088,6952,6773,6917,7371,8221,7953,8027,7287,8076,8933,9433,9479,9199,9469,10015,10999,13009,13699,13895,13248,13973,15095,15201,14823,14538,14547,14407) > par10 = 'FALSE' > par9 = '0' > par8 = '1' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '12' > 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 sar1 -0.2946 -0.8677 -0.4800 -0.0035 0.9842 0.1240 -0.4326 s.e. 0.2784 0.0705 0.2858 0.3072 0.0999 0.3324 0.1385 sigma^2 estimated as 40584: log likelihood = -365.99, aic = 747.97 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 68 End = 95 Frequency = 1 [1] 6982.321 6789.661 6455.447 6705.803 6495.765 7493.086 7419.523 6906.645 [9] 6454.185 6401.922 7204.962 7438.575 6838.534 6545.988 6256.546 6525.096 [17] 6316.950 7378.122 7278.033 6791.773 6325.562 6252.086 7096.107 7372.451 [25] 6752.876 6467.426 6181.278 6481.469 $se Time Series: Start = 68 End = 95 Frequency = 1 [1] 204.5503 250.0537 307.8113 341.5611 375.3065 409.3775 443.1784 [8] 470.3034 494.1895 519.8102 546.6527 569.9855 629.9621 673.9501 [15] 725.9246 767.2767 804.6236 841.9987 881.7933 918.1539 949.7171 [22] 980.8880 1014.4472 1046.9632 1120.8851 1174.7963 1238.0368 1292.7151 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 68 End = 95 Frequency = 1 [1] 6581.402 6299.556 5852.137 6036.343 5760.165 6690.707 6550.894 5984.850 [9] 5485.574 5383.094 6133.522 6321.403 5603.808 5225.046 4833.734 5021.234 [17] 4739.888 5727.804 5549.718 4992.191 4464.116 4329.546 5107.790 5320.403 [25] 4555.941 4164.825 3754.726 3947.748 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 68 End = 95 Frequency = 1 [1] 7383.239 7279.766 7058.757 7375.263 7231.366 8295.466 8288.153 7828.439 [9] 7422.797 7420.750 8276.401 8555.746 8073.260 7866.930 7679.358 8028.958 [17] 7894.012 9028.439 9006.347 8591.355 8187.007 8174.627 9084.424 9424.499 [25] 8949.810 8770.027 8607.831 9015.191 > 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] 9051.000 8823.000 8776.000 8255.000 7969.000 8758.000 8693.000 8271.000 [9] 7790.000 7769.000 8170.000 8209.000 9395.000 9260.000 9018.000 8501.000 [17] 8500.000 9649.000 9319.000 8830.000 8436.000 8169.000 8269.000 7945.000 [25] 9144.000 8770.000 8834.000 7837.000 7792.000 8616.000 8518.000 7940.000 [33] 7545.000 7531.000 7665.000 7599.000 8444.000 8549.000 7986.000 7335.000 [41] 7287.000 7870.000 7839.000 7327.000 7259.000 6964.000 7271.000 6956.000 [49] 7608.000 7692.000 7255.000 6804.000 6655.000 7341.000 7602.000 7086.000 [57] 6625.000 6272.000 6576.000 6491.000 7649.000 7400.000 6913.000 6532.000 [65] 6486.000 7295.000 7556.000 6982.321 6789.661 6455.447 6705.803 6495.765 [73] 7493.086 7419.523 6906.645 6454.185 6401.922 7204.962 7438.575 6838.534 [81] 6545.988 6256.546 6525.096 6316.950 7378.122 7278.033 6791.773 6325.562 [89] 6252.086 7096.107 7372.451 6752.876 6467.426 6181.278 6481.469 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 68 End = 95 Frequency = 1 [1] 0.02929546 0.03682859 0.04768242 0.05093515 0.05777710 0.05463402 [7] 0.05973139 0.06809434 0.07656884 0.08119597 0.07587170 0.07662563 [13] 0.09211946 0.10295621 0.11602641 0.11758857 0.12737534 0.11412101 [19] 0.12115820 0.13518619 0.15013958 0.15688972 0.14295828 0.14201019 [25] 0.16598634 0.18164819 0.20028815 0.19944785 > postscript(file="/var/www/html/rcomp/tmp/1smx81260540551.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/278j31260540551.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/3ty0g1260540551.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/4crcc1260540551.tab") > > system("convert tmp/1smx81260540551.ps tmp/1smx81260540551.png") > system("convert tmp/278j31260540551.ps tmp/278j31260540551.png") > > > proc.time() user system elapsed 2.354 0.345 3.701