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(152.60,153.32,165.50,139.18,136.53,115.92,96.65,83.77,84.66,106.03,86.92,54.66,151.66,121.27,132.95,119.64,122.16,117.44,106.69,87.45,80.98,110.30,87.01,55.73,146.00,137.54,138.54,135.62,107.27,99.04,91.36,68.35,82.59,98.41,71.25,47.58,130.83,113.60,125.69,113.60,97.12,104.43,91.84,75.11,89.24,110.23,78.42,68.45,122.81,129.66,159.06,139.03,102.16,113.59,81.46,77.36,87.57,101.23,87.21,64.94,133.12,117.99,135.90,125.67,108.03,128.31,84.74,86.38,92.24,95.83,92.33,54.27) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '1' > par6 = '0' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '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.7148 -0.3580 0.4838 -0.0067 0.0067 -0.9999 -0.9601 0.5530 s.e. 0.1866 0.2335 0.1813 0.2018 0.2023 0.2628 0.1554 0.8029 sigma^2 estimated as 30.21: log likelihood = -109.53, aic = 237.06 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 45 End = 72 Frequency = 1 [1] 78.08709 94.16604 74.65538 46.54149 123.83736 130.29489 128.51132 [8] 120.33365 96.17362 85.07595 76.83501 61.46504 68.50329 85.05900 [15] 62.67807 32.10645 118.67516 104.41929 109.97935 103.31160 85.88184 [22] 88.14122 81.58806 61.95480 63.02109 84.49589 60.33845 32.43892 $se Time Series: Start = 45 End = 72 Frequency = 1 [1] 5.862838 6.078762 6.609768 6.663239 6.643388 6.835386 6.828498 [8] 6.811540 6.955393 6.961397 6.955595 7.048429 7.518885 7.676663 [15] 8.002288 7.975961 8.009368 8.110646 8.093660 8.160160 8.192485 [22] 8.169954 8.275601 8.271535 9.954141 10.393102 10.701206 10.735407 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 45 End = 72 Frequency = 1 [1] 66.59593 82.25167 61.70023 33.48154 110.81632 116.89753 115.12746 [8] 106.98304 82.54105 71.43161 63.20205 47.65012 53.76628 70.01274 [15] 46.99358 16.47357 102.97680 88.52243 94.11578 87.31769 69.82457 [22] 72.12810 65.36788 45.74259 43.51097 64.12541 39.36409 11.39753 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 45 End = 72 Frequency = 1 [1] 89.57825 106.08042 87.61053 59.60143 136.85840 143.69225 141.89517 [8] 133.68427 109.80619 98.72029 90.46798 75.27996 83.24031 100.10526 [15] 78.36255 47.73933 134.37352 120.31616 125.84293 119.30552 101.93911 [22] 104.15433 97.80824 78.16701 82.53120 104.86637 81.31282 53.48032 > 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] 152.60000 153.32000 165.50000 139.18000 136.53000 115.92000 96.65000 [8] 83.77000 84.66000 106.03000 86.92000 54.66000 151.66000 121.27000 [15] 132.95000 119.64000 122.16000 117.44000 106.69000 87.45000 80.98000 [22] 110.30000 87.01000 55.73000 146.00000 137.54000 138.54000 135.62000 [29] 107.27000 99.04000 91.36000 68.35000 82.59000 98.41000 71.25000 [36] 47.58000 130.83000 113.60000 125.69000 113.60000 97.12000 104.43000 [43] 91.84000 75.11000 78.08709 94.16604 74.65538 46.54149 123.83736 [50] 130.29489 128.51132 120.33365 96.17362 85.07595 76.83501 61.46504 [57] 68.50329 85.05900 62.67807 32.10645 118.67516 104.41929 109.97935 [64] 103.31160 85.88184 88.14122 81.58806 61.95480 63.02109 84.49589 [71] 60.33845 32.43892 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 45 End = 72 Frequency = 1 [1] 0.07508076 0.06455365 0.08853707 0.14316772 0.05364607 0.05246089 [7] 0.05313538 0.05660545 0.07232121 0.08182568 0.09052637 0.11467379 [13] 0.10975947 0.09025104 0.12767286 0.24842239 0.06748985 0.07767383 [19] 0.07359254 0.07898590 0.09539252 0.09269165 0.10143153 0.13350919 [25] 0.15794937 0.12300127 0.17735302 0.33094215 > postscript(file="/var/www/html/rcomp/tmp/1mxjs1261336931.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/2hezq1261336931.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/3akg91261336931.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/4xtsq1261336931.tab") > > try(system("convert tmp/1mxjs1261336931.ps tmp/1mxjs1261336931.png",intern=TRUE)) character(0) > try(system("convert tmp/2hezq1261336931.ps tmp/2hezq1261336931.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.591 0.357 4.217