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(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,1673,2589,2332,3785,4916,5207,6055,5751,5247,3387,2091,2401,1664,2205,2295,3762,4890,5117,6099,5865,5594,3229,2106,2410,1583,2092,2612,3665,4880,5875,5892,6078,6515,3164,2028,2677,1580,2196,2838,3087,4726,6521,6739,5943,6265,3323,2098,2544,1442,2307,2811,3461,5451,5481,5114,8381,5215,3700,2122,2311,1515,2351,2289,3380,5398,5242,5162,6391,5958,3727,1883,2191) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '-0.2' > 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 ma1 sar1 sar2 sma1 0.4489 0.2059 0.2878 -0.6183 0.2462 -0.2312 -1.0000 s.e. 0.1722 0.0914 0.1282 0.1543 0.1060 0.1085 0.0986 sigma^2 estimated as 7.814e-06: log likelihood = 573.67, aic = -1131.34 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 145 End = 156 Frequency = 1 [1] 0.2293904 0.2116846 0.2075768 0.1938348 0.1796741 0.1789540 0.1788585 [8] 0.1697879 0.1785216 0.1957745 0.2176936 0.2110748 $se Time Series: Start = 145 End = 156 Frequency = 1 [1] 0.002912472 0.002954486 0.002977923 0.003110590 0.003128629 0.003159546 [7] 0.003202576 0.003230013 0.003257357 0.003284102 0.003307874 0.003330029 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 145 End = 156 Frequency = 1 [1] 0.2236820 0.2058938 0.2017401 0.1877381 0.1735420 0.1727613 0.1725814 [8] 0.1634570 0.1721372 0.1893376 0.2112101 0.2045479 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 145 End = 156 Frequency = 1 [1] 0.2350989 0.2174754 0.2134135 0.1999316 0.1858062 0.1851467 0.1851355 [8] 0.1761187 0.1849060 0.2022113 0.2241770 0.2176016 > 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] 1567.000 2237.000 2598.000 3729.000 5715.000 5776.000 5852.000 6878.000 [9] 5488.000 3583.000 2054.000 2282.000 1552.000 2261.000 2446.000 3519.000 [17] 5161.000 5085.000 5711.000 6057.000 5224.000 3363.000 1899.000 2115.000 [25] 1491.000 2061.000 2419.000 3430.000 4778.000 4862.000 6176.000 5664.000 [33] 5529.000 3418.000 1941.000 2402.000 1579.000 2146.000 2462.000 3695.000 [41] 4831.000 5134.000 6250.000 5760.000 6249.000 2917.000 1741.000 2359.000 [49] 1511.000 2059.000 2635.000 2867.000 4403.000 5720.000 4502.000 5749.000 [57] 5627.000 2846.000 1762.000 2429.000 1169.000 2154.000 2249.000 2687.000 [65] 4359.000 5382.000 4459.000 6398.000 4596.000 3024.000 1887.000 2070.000 [73] 1351.000 2218.000 2461.000 3028.000 4784.000 4975.000 4607.000 6249.000 [81] 4809.000 3157.000 1910.000 2228.000 1673.000 2589.000 2332.000 3785.000 [89] 4916.000 5207.000 6055.000 5751.000 5247.000 3387.000 2091.000 2401.000 [97] 1664.000 2205.000 2295.000 3762.000 4890.000 5117.000 6099.000 5865.000 [105] 5594.000 3229.000 2106.000 2410.000 1583.000 2092.000 2612.000 3665.000 [113] 4880.000 5875.000 5892.000 6078.000 6515.000 3164.000 2028.000 2677.000 [121] 1580.000 2196.000 2838.000 3087.000 4726.000 6521.000 6739.000 5943.000 [129] 6265.000 3323.000 2098.000 2544.000 1442.000 2307.000 2811.000 3461.000 [137] 5451.000 5481.000 5114.000 8381.000 5215.000 3700.000 2122.000 2311.000 [145] 1574.430 2352.629 2594.812 3654.609 5340.382 5448.702 5463.265 7087.072 [153] 5515.008 3477.120 2045.370 2386.813 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 145 End = 156 Frequency = 1 [1] 0.06851176 0.07589876 0.07820198 0.08840215 0.09673971 0.09823735 [7] 0.09978391 0.10675877 0.10189870 0.09282675 0.08326507 0.08676288 > postscript(file="/var/www/rcomp/tmp/1cgwj1293651016.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/288us1293651016.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/3p1by1293651017.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/4aks41293651017.tab") > > try(system("convert tmp/1cgwj1293651016.ps tmp/1cgwj1293651016.png",intern=TRUE)) character(0) > try(system("convert tmp/288us1293651016.ps tmp/288us1293651016.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 4.330 2.740 7.043