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(15.89,16.93,20.28,22.52,23.51,22.59,23.51,24.76,26.08,25.29,23.38,25.29,28.42,31.85,30.1,25.45,24.95,26.84,27.52,27.94,25.23,26.53,27.21,28.53,30.35,31.21,32.86,33.2,35.73,34.53,36.54,40.1,40.56,46.14,42.85,38.22,40.18,42.19,47.56,47.26,44.03,49.83,53.35,58.9,59.64,56.99,53.2,53.24,57.85,55.69,55.64,62.52,64.4,64.65,67.71,67.21,59.37,53.26,52.42,55.03) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '0' > par6 = '2' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '0.1' > par1 = '24' > par1 <- as.numeric(par1) #cut off periods > par1 <- 28 > 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 > par6 <- 3 > par7 <- as.numeric(par7) #q > par7 <- 3 > 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 ma2 ma3 sar1 sma1 0.1010 -0.4964 -0.0666 0.4966 0.9032 -0.1497 -0.9960 0.9538 s.e. 0.6747 0.1993 0.4001 0.6765 0.4852 0.6739 0.0766 0.4413 sigma^2 estimated as 4.624e-05: log likelihood = 105.66, aic = -193.32 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 33 End = 60 Frequency = 1 [1] 1.463517 1.468405 1.457150 1.453422 1.458011 1.462138 1.455186 1.447200 [9] 1.444431 1.448664 1.447216 1.443761 1.437955 1.439491 1.443226 1.442262 [17] 1.440503 1.439496 1.445649 1.451798 1.454550 1.451281 1.452942 1.455935 [25] 1.461502 1.460158 1.456594 1.457492 $se Time Series: Start = 33 End = 60 Frequency = 1 [1] 0.007460768 0.013927264 0.020305301 0.023299662 0.025097560 0.027179180 [7] 0.029637917 0.031787139 0.033535316 0.035191302 0.036895317 0.038557826 [13] 0.039801130 0.040824043 0.041721002 0.042738181 0.043806890 0.044822389 [19] 0.045778803 0.046729583 0.047682899 0.048614464 0.049516866 0.050403456 [25] 0.051501231 0.052710572 0.053980884 0.055122085 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 1.448894 1.441107 1.417352 1.407755 1.408819 1.408867 1.397096 1.384897 [9] 1.378701 1.379689 1.374901 1.368188 1.359944 1.359476 1.361452 1.358495 [17] 1.354642 1.351644 1.355923 1.360208 1.361092 1.355996 1.355889 1.357145 [25] 1.360560 1.356845 1.350791 1.349453 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 1.478140 1.495702 1.496949 1.499089 1.507202 1.515409 1.513276 1.509502 [9] 1.510160 1.517639 1.519530 1.519334 1.515965 1.519506 1.524999 1.526029 [17] 1.526365 1.527348 1.535376 1.543388 1.548009 1.546565 1.549995 1.554726 [25] 1.562444 1.563470 1.562397 1.565531 > 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] 15.89000 16.93000 20.28000 22.52000 23.51000 22.59000 23.51000 24.76000 [9] 26.08000 25.29000 23.38000 25.29000 28.42000 31.85000 30.10000 25.45000 [17] 24.95000 26.84000 27.52000 27.94000 25.23000 26.53000 27.21000 28.53000 [25] 30.35000 31.21000 32.86000 33.20000 35.73000 34.53000 36.54000 40.10000 [33] 45.07925 46.60767 43.15626 42.06469 43.41173 44.65634 42.57796 40.29807 [41] 39.53362 40.70776 40.30252 39.35078 37.79651 38.20228 39.20505 38.94402 [49] 38.47184 38.20368 39.86848 41.59709 42.39235 41.44898 41.92604 42.79778 [57] 44.46255 44.05520 42.99175 43.25753 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 33 End = 60 Frequency = 1 [1] 0.05333265 0.10318694 0.15778531 0.18498313 0.20076579 0.21952135 [7] 0.24443833 0.26747005 0.28596672 0.30216217 0.32061330 0.33961091 [13] 0.35512920 0.36614866 0.37510847 0.38707958 0.40009638 0.41240758 [19] 0.42146395 0.43045678 0.44081819 0.45342892 0.46380770 0.47349431 [25] 0.48473279 0.50054421 0.51845492 0.53283276 > postscript(file="/var/www/html/rcomp/tmp/1lxo81260483838.ps",horizontal=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/2annz1260483838.ps",horizontal=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/3v2ic1260483839.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/42byj1260483839.tab") > > system("convert tmp/1lxo81260483838.ps tmp/1lxo81260483838.png") > system("convert tmp/2annz1260483838.ps tmp/2annz1260483838.png") > > > proc.time() user system elapsed 1.514 0.324 1.625