R version 2.12.0 (2010-10-15) Copyright (C) 2010 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(1775,2197,2920,4240,5415,6136,6719,6234,7152,3646,2165,2803,1615,2350,3350,3536,5834,6767,5993,7276,5641,3477,2247,2466,1567,2237,2598,3729,5715,5776,5852,6878,5488,3583,2054,2282,1552,2261,2446,3519,5161,5085,5711,6057,5224,3363,1899,2115,1491,2061,2419,3430,4778,4862,6176,5664,5529,3418,1941,2402,1579,2146,2462,3695,4831,5134,6250,5760,6249,2917,1741,2359,1511,2059,2635,2867,4403,5720,4502,5749,5627,2846,1762,2429,1169,2154,2249,2687,4359,5382,4459,6398,4596,3024,1887,2070,1351,2218,2461,3028,4784,4975,4607,6249,4809,3157,1910,2228,1594,2467,2222,3607,4685,4962,5770,5480,5000,3228,1993,2288,1588,2105,2191,3591,4668,4885,5822,5599,5340,3082,2010,2301) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '0.0' > 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: ar1 ar2 ar3 ma1 sma1 0.0028 0.2843 0.6082 -0.2657 -0.6419 s.e. 0.1480 0.0769 0.1006 0.2151 0.1155 sigma^2 estimated as 0.005167: log likelihood = 112.77, aic = -213.53 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 109 End = 132 Frequency = 1 [1] 7.239614 7.690658 7.799450 8.035796 8.458283 8.565098 8.505244 8.725743 [9] 8.542138 8.044939 7.540790 7.720902 7.236812 7.685517 7.805964 8.032649 [17] 8.456999 8.568161 8.502973 8.725827 8.543356 8.043585 7.541183 7.721259 $se Time Series: Start = 109 End = 132 Frequency = 1 [1] 0.07189242 0.07433630 0.07708004 0.08611566 0.08629742 0.08938684 [7] 0.09201306 0.09207125 0.09430029 0.09537206 0.09569255 0.09709930 [13] 0.10380214 0.10383724 0.10583320 0.10833359 0.10859428 0.11025090 [19] 0.11144391 0.11189434 0.11306528 0.11378543 0.11429206 0.11509030 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 109 End = 132 Frequency = 1 [1] 7.098705 7.544959 7.648373 7.867010 8.289140 8.389899 8.324898 8.545283 [9] 8.357310 7.858010 7.353232 7.530588 7.033360 7.481996 7.598531 7.820315 [17] 8.244154 8.352069 8.284543 8.506514 8.321748 7.820566 7.317171 7.495682 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 109 End = 132 Frequency = 1 [1] 7.380523 7.836357 7.950527 8.204583 8.627426 8.740296 8.685589 8.906203 [9] 8.726967 8.231868 7.728347 7.911217 7.440264 7.889038 8.013397 8.244982 [17] 8.669844 8.784253 8.721403 8.945140 8.764964 8.266605 7.765196 7.946836 > 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] 1775.000 2197.000 2920.000 4240.000 5415.000 6136.000 6719.000 6234.000 [9] 7152.000 3646.000 2165.000 2803.000 1615.000 2350.000 3350.000 3536.000 [17] 5834.000 6767.000 5993.000 7276.000 5641.000 3477.000 2247.000 2466.000 [25] 1567.000 2237.000 2598.000 3729.000 5715.000 5776.000 5852.000 6878.000 [33] 5488.000 3583.000 2054.000 2282.000 1552.000 2261.000 2446.000 3519.000 [41] 5161.000 5085.000 5711.000 6057.000 5224.000 3363.000 1899.000 2115.000 [49] 1491.000 2061.000 2419.000 3430.000 4778.000 4862.000 6176.000 5664.000 [57] 5529.000 3418.000 1941.000 2402.000 1579.000 2146.000 2462.000 3695.000 [65] 4831.000 5134.000 6250.000 5760.000 6249.000 2917.000 1741.000 2359.000 [73] 1511.000 2059.000 2635.000 2867.000 4403.000 5720.000 4502.000 5749.000 [81] 5627.000 2846.000 1762.000 2429.000 1169.000 2154.000 2249.000 2687.000 [89] 4359.000 5382.000 4459.000 6398.000 4596.000 3024.000 1887.000 2070.000 [97] 1351.000 2218.000 2461.000 3028.000 4784.000 4975.000 4607.000 6249.000 [105] 4809.000 3157.000 1910.000 2228.000 1393.556 2187.813 2439.260 3089.598 [113] 4713.956 5245.352 4940.608 6159.452 5126.294 3117.976 1883.317 2254.993 [121] 1389.656 2176.594 2455.201 3079.888 4707.908 5261.445 4929.400 6159.968 [129] 5132.540 3113.756 1884.058 2255.798 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 109 End = 132 Frequency = 1 [1] 0.07720410 0.08002454 0.08320717 0.09381000 0.09402521 0.09769508 [7] 0.10083224 0.10090193 0.10357764 0.10486835 0.10525484 0.10695415 [13] 0.11511559 0.11515862 0.11760987 0.12069420 0.12101664 0.12306952 [19] 0.12455205 0.12511268 0.12657244 0.12747188 0.12810540 0.12910485 > postscript(file="/var/www/rcomp/tmp/13k901292941058.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/rcomp/tmp/20cpr1292941058.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/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/rcomp/tmp/3h43n1292941058.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/rcomp/tmp/4se2q1292941058.tab") > > try(system("convert tmp/13k901292941058.ps tmp/13k901292941058.png",intern=TRUE)) character(0) > try(system("convert tmp/20cpr1292941058.ps tmp/20cpr1292941058.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.12 0.45 1.56