R version 2.8.0 (2008-10-20) Copyright (C) 2008 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. Natural language support but running in an English locale 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 = '12' > #'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#output/ > #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.0552 0.2748 0.6330 -0.1633 -0.6349 s.e. 0.1229 0.0710 0.0832 0.1733 0.1027 sigma^2 estimated as 0.005399: log likelihood = 124.99, aic = -237.99 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 121 End = 132 Frequency = 1 [1] 7.314747 7.767992 7.787049 8.116678 8.481218 8.563606 8.582716 8.703338 [9] 8.549009 8.076004 7.577596 7.740748 $se Time Series: Start = 121 End = 132 Frequency = 1 [1] 0.07348031 0.07521431 0.07811224 0.08818888 0.08843791 0.09189261 [7] 0.09465784 0.09466819 0.09718273 0.09812273 0.09831695 0.09982495 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 121 End = 132 Frequency = 1 [1] 7.170725 7.620572 7.633949 7.943828 8.307880 8.383497 8.397187 8.517789 [9] 8.358531 7.883683 7.384895 7.545091 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 121 End = 132 Frequency = 1 [1] 7.458768 7.915412 7.940149 8.289528 8.654556 8.743716 8.768246 8.888888 [9] 8.739487 8.268324 7.770298 7.936405 > 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 1594.000 2467.000 2222.000 3607.000 [113] 4685.000 4962.000 5770.000 5480.000 5000.000 3228.000 1993.000 2288.000 [121] 1502.291 2363.720 2409.197 3349.874 4823.321 5237.535 5338.587 6022.985 [129] 5161.638 3216.354 1953.927 2300.193 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 121 End = 132 Frequency = 1 [1] 0.07903512 0.08104113 0.08440893 0.09626941 0.09656550 0.10068800 [7] 0.10400793 0.10402040 0.10705507 0.10819336 0.10842881 0.11025999 > postscript(file="/var/www/html/freestat/rcomp/tmp/14t7w1292941542.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/html/freestat/rcomp/tmp/2aum71292941542.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/html/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/freestat/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/freestat/rcomp/tmp/3hdj11292941542.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/freestat/rcomp/tmp/42ehp1292941542.tab") > try(system("convert tmp/14t7w1292941542.ps tmp/14t7w1292941542.png",intern=TRUE)) character(0) > try(system("convert tmp/2aum71292941542.ps tmp/2aum71292941542.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.703 0.450 1.775