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(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,1580,2111,2192,3601,4665,4876,5813,5589,5331,3075,2002,2306,1507,1992,2487,3490,4647,5594,5611,5788,6204,3013,1931,2549,1504,2090,2702,2939,4500,6208,6415,5657,5964,3163,1997,2422,1376,2202,2683,3303,5202,5231,4880,7998,4977,3531,2025,2205,1442,2238,2179,3218,5139,4990,4914,6084,5672,3548,1793,2086) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '0' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '-0.5' > 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/ > #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 sar1 sar2 sma1 -0.1509 0.1324 0.3791 0.2344 -0.2332 -1.0000 s.e. 0.0942 0.0975 0.1163 0.1378 0.1287 0.2067 sigma^2 estimated as 4.420e-07: log likelihood = 552.15, aic = -1090.29 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.02596347 0.02129699 0.02037134 0.01709726 0.01438617 0.01401523 [7] 0.01408414 0.01239025 0.01394953 0.01769245 0.02281828 0.02105798 $se Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.0007034029 0.0007112861 0.0007195043 0.0007567272 0.0007591703 [6] 0.0007635242 0.0007665574 0.0007668351 0.0007680362 0.0007678274 [11] 0.0007677436 0.0007679027 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.02458480 0.01990287 0.01896112 0.01561408 0.01289819 0.01251872 [7] 0.01258169 0.01088725 0.01244418 0.01618751 0.02131351 0.01955289 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.02734214 0.02269111 0.02178157 0.01858045 0.01587414 0.01551173 [7] 0.01558659 0.01389324 0.01545488 0.01919739 0.02432306 0.02256307 > 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] 1579.000 2146.000 2462.000 3695.000 4831.000 5134.000 6250.000 5760.000 [9] 6249.000 2917.000 1741.000 2359.000 1511.000 2059.000 2635.000 2867.000 [17] 4403.000 5720.000 4502.000 5749.000 5627.000 2846.000 1762.000 2429.000 [25] 1169.000 2154.000 2249.000 2687.000 4359.000 5382.000 4459.000 6398.000 [33] 4596.000 3024.000 1887.000 2070.000 1351.000 2218.000 2461.000 3028.000 [41] 4784.000 4975.000 4607.000 6249.000 4809.000 3157.000 1910.000 2228.000 [49] 1594.000 2467.000 2222.000 3607.000 4685.000 4962.000 5770.000 5480.000 [57] 5000.000 3228.000 1993.000 2288.000 1580.000 2111.000 2192.000 3601.000 [65] 4665.000 4876.000 5813.000 5589.000 5331.000 3075.000 2002.000 2306.000 [73] 1507.000 1992.000 2487.000 3490.000 4647.000 5594.000 5611.000 5788.000 [81] 6204.000 3013.000 1931.000 2549.000 1504.000 2090.000 2702.000 2939.000 [89] 4500.000 6208.000 6415.000 5657.000 5964.000 3163.000 1997.000 2422.000 [97] 1376.000 2202.000 2683.000 3303.000 5202.000 5231.000 4880.000 7998.000 [105] 4977.000 3531.000 2025.000 2205.000 1483.456 2204.772 2409.687 3420.951 [113] 4831.809 5090.960 5041.261 6513.886 5139.025 3194.656 1920.587 2255.104 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.05882705 0.07397905 0.07871486 0.10153249 0.12450741 0.12927211 [7] 0.12912844 0.15059200 0.13090298 0.09927650 0.07458611 0.08156927 > postscript(file="/var/www/rcomp/tmp/1zs121291984999.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/2vkzt1291984999.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/3vcvq1291984999.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/4gdtv1291984999.tab") > > try(system("convert tmp/1zs121291984999.ps tmp/1zs121291984999.png",intern=TRUE)) character(0) > try(system("convert tmp/2vkzt1291984999.ps tmp/2vkzt1291984999.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.330 1.970 4.279