R version 2.13.0 (2011-04-13) Copyright (C) 2011 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(12.008,9.169,8.788,8.417,8.247,8.197,8.236,8.253,7.733,8.366,8.626,8.863,10.102,8.463,9.114,8.563,8.872,8.301,8.301,8.278,7.736,7.973,8.268,9.476,11.100,8.962,9.173,8.738,8.459,8.078,8.411,8.291,7.810,8.616,8.312,9.692,9.911,8.915,9.452,9.112,8.472,8.230,8.384,8.625,8.221,8.649,8.625,10.443,10.357,8.586,8.892,8.329,8.101,7.922,8.120,7.838,7.735,8.406,8.209,9.451,10.041,9.411,10.405,8.467,8.464,8.102,7.627,7.513,7.510,8.291,8.064,9.383,9.706,8.579,9.474,8.318,8.213,8.059,9.111,7.708,7.680,8.014,8.007,8.718,9.486,9.113,9.025,8.476,7.952,7.759,7.835,7.600,7.651,8.319,8.812,8.630) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '1' > 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 ma1 sar1 sar2 sma1 0.4528 0.0388 -1.1653 -0.2109 0.7994 s.e. 0.2305 0.2362 0.6224 0.3871 0.7244 sigma^2 estimated as 0.1599: log likelihood = -33.29, aic = 78.58 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 73 End = 96 Frequency = 1 [1] 10.212049 9.025752 9.677417 8.286233 8.203278 7.964581 7.790373 [8] 7.533146 7.518612 8.374379 8.068227 9.186769 9.845833 9.194959 [15] 10.158325 8.446102 8.420734 8.082314 7.701949 7.577300 7.555616 [22] 8.301280 8.093797 9.429749 $se Time Series: Start = 73 End = 96 Frequency = 1 [1] 0.4021926 0.4479142 0.4567239 0.4585094 0.4588746 0.4589495 0.4589648 [8] 0.4589677 0.4589670 0.4589606 0.4589291 0.4587754 0.5228080 0.5371888 [15] 0.5400901 0.5406831 0.5408046 0.5408295 0.5408346 0.5408357 0.5408359 [22] 0.5408358 0.5408350 0.5408315 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 73 End = 96 Frequency = 1 [1] 9.423751 8.147840 8.782238 7.387554 7.303883 7.065040 6.890802 6.633570 [9] 6.619037 7.474816 7.168726 8.287570 8.821129 8.142069 9.099748 7.386363 [17] 7.360757 7.022288 6.641913 6.517263 6.495578 7.241242 7.033761 8.369719 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 73 End = 96 Frequency = 1 [1] 11.000346 9.903663 10.572596 9.184911 9.102672 8.864122 8.689944 [8] 8.432723 8.418187 9.273942 8.967728 10.085969 10.870536 10.247849 [15] 11.216901 9.505841 9.480711 9.142339 8.761984 8.637338 8.615655 [22] 9.361319 9.153834 10.489779 > 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] 12.008000 9.169000 8.788000 8.417000 8.247000 8.197000 8.236000 [8] 8.253000 7.733000 8.366000 8.626000 8.863000 10.102000 8.463000 [15] 9.114000 8.563000 8.872000 8.301000 8.301000 8.278000 7.736000 [22] 7.973000 8.268000 9.476000 11.100000 8.962000 9.173000 8.738000 [29] 8.459000 8.078000 8.411000 8.291000 7.810000 8.616000 8.312000 [36] 9.692000 9.911000 8.915000 9.452000 9.112000 8.472000 8.230000 [43] 8.384000 8.625000 8.221000 8.649000 8.625000 10.443000 10.357000 [50] 8.586000 8.892000 8.329000 8.101000 7.922000 8.120000 7.838000 [57] 7.735000 8.406000 8.209000 9.451000 10.041000 9.411000 10.405000 [64] 8.467000 8.464000 8.102000 7.627000 7.513000 7.510000 8.291000 [71] 8.064000 9.383000 10.212049 9.025752 9.677417 8.286233 8.203278 [78] 7.964581 7.790373 7.533146 7.518612 8.374379 8.068227 9.186769 [85] 9.845833 9.194959 10.158325 8.446102 8.420734 8.082314 7.701949 [92] 7.577300 7.555616 8.301280 8.093797 9.429749 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 73 End = 96 Frequency = 1 [1] 0.03938413 0.04962625 0.04719482 0.05533388 0.05593796 0.05762381 [7] 0.05891436 0.06092642 0.06104411 0.05480534 0.05688104 0.04993871 [13] 0.05309942 0.05842210 0.05316725 0.06401570 0.06422298 0.06691519 [19] 0.07022050 0.07137577 0.07158064 0.06515088 0.06682093 0.05735375 > postscript(file="/var/wessaorg/rcomp/tmp/10cev1323162864.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/wessaorg/rcomp/tmp/22xlf1323162864.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/3u6jh1323162864.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/wessaorg/rcomp/tmp/43iym1323162864.tab") > > try(system("convert tmp/10cev1323162864.ps tmp/10cev1323162864.png",intern=TRUE)) character(0) > try(system("convert tmp/22xlf1323162864.ps tmp/22xlf1323162864.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.617 0.585 4.198