R version 2.9.0 (2009-04-17) Copyright (C) 2009 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. 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(13.193,15.234,14.718,16.961,13.945,15.876,16.226,18.316,16.748,17.904,17.209,18.950,17.225,18.710,17.236,18.687,17.580,19.568,17.381,19.580,17.260,18.661,15.658,18.674,15.908,17.475,17.725,19.562,16.368,19.555,17.743,19.867,15.703,19.324,18.162,19.074,15.323,19.704,18.375,18.352,13.927,17.795,16.761,18.902,16.239,19.158,18.279,15.698,16.239,18.431,18.414,19.801,14.995,18.706,18.232,19.409,16.263,19.017,20.298,19.891,15.203,17.845,17.502,18.532,15.737,17.770,17.224,17.601,14.940,18.507,17.635,19.392,15.699,17.661,18.243,19.643,15.770,17.344,17.229,17.322,16.152,17.919,16.918,18.114,16.308,17.759,16.021,17.952,15.954,17.762,16.610,17.751,15.458,18.106,15.990,15.349,13.185,15.409,16.007,16.633,14.800,15.974,15.693) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '1' > par6 = '2' > par5 = '4' > par4 = '1' > par3 = '0' > par2 = '1' > 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 ma1 sar1 sma1 1.1917 -0.2418 -0.7811 0.2711 -1.0000 s.e. 0.3423 0.2100 0.2932 0.1186 0.1477 sigma^2 estimated as 0.8625: log likelihood = -121.76, aic = 255.51 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 92 End = 103 Frequency = 1 [1] 18.10769 15.54409 17.76636 16.87974 18.19334 15.45809 17.78700 16.96999 [9] 18.23224 15.44933 17.80614 17.00708 $se Time Series: Start = 92 End = 103 Frequency = 1 [1] 0.9479443 1.0233257 1.0492687 1.0649854 1.1590867 1.1885809 1.2067494 [8] 1.2205463 1.2538243 1.2688178 1.2804923 1.2898772 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 92 End = 103 Frequency = 1 [1] 16.24972 13.53838 15.70979 14.79237 15.92153 13.12848 15.42177 14.57772 [9] 15.77474 12.96244 15.29637 14.47892 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 92 End = 103 Frequency = 1 [1] 19.96566 17.54981 19.82292 18.96711 20.46515 17.78771 20.15223 19.36226 [9] 20.68973 17.93621 20.31590 19.53524 > 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] 13.19300 15.23400 14.71800 16.96100 13.94500 15.87600 16.22600 18.31600 [9] 16.74800 17.90400 17.20900 18.95000 17.22500 18.71000 17.23600 18.68700 [17] 17.58000 19.56800 17.38100 19.58000 17.26000 18.66100 15.65800 18.67400 [25] 15.90800 17.47500 17.72500 19.56200 16.36800 19.55500 17.74300 19.86700 [33] 15.70300 19.32400 18.16200 19.07400 15.32300 19.70400 18.37500 18.35200 [41] 13.92700 17.79500 16.76100 18.90200 16.23900 19.15800 18.27900 15.69800 [49] 16.23900 18.43100 18.41400 19.80100 14.99500 18.70600 18.23200 19.40900 [57] 16.26300 19.01700 20.29800 19.89100 15.20300 17.84500 17.50200 18.53200 [65] 15.73700 17.77000 17.22400 17.60100 14.94000 18.50700 17.63500 19.39200 [73] 15.69900 17.66100 18.24300 19.64300 15.77000 17.34400 17.22900 17.32200 [81] 16.15200 17.91900 16.91800 18.11400 16.30800 17.75900 16.02100 17.95200 [89] 15.95400 17.76200 16.61000 18.10769 15.54409 17.76636 16.87974 18.19334 [97] 15.45809 17.78700 16.96999 18.23224 15.44933 17.80614 17.00708 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 92 End = 103 Frequency = 1 [1] 0.05235036 0.06583373 0.05905930 0.06309251 0.06370941 0.07689052 [7] 0.06784447 0.07192383 0.06876963 0.08212771 0.07191297 0.07584355 > postscript(file="/var/www/html/rcomp/tmp/15q1d1293197997.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/rcomp/tmp/2j0z41293197997.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/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/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/rcomp/tmp/381ey1293197997.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/rcomp/tmp/4tjv41293197997.tab") > > try(system("convert tmp/15q1d1293197997.ps tmp/15q1d1293197997.png",intern=TRUE)) character(0) > try(system("convert tmp/2j0z41293197997.ps tmp/2j0z41293197997.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.825 0.354 1.920