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(5594,5585,5710,5511,5403,5826,5884,5965,5960,6064,6046,5954,5952,5960,5983,5996,6021,6094,6202,6276,6306,6342,6345,6328,6191,6261,6253,6198,6247,6293,6381,6448,6470,6516,6532,6526,6533,6498,6507,6464,6453,6468,6497,6808,6793,6907,6792,6757,6734,6654,6589,6469,6521,6448,6410,6528,6445,6458,6215,6167) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > par6 = '0' > par5 = '12' > par4 = '0' > 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 0.4259 -0.7211 0.2344 -0.4704 0.8104 0.2596 s.e. 0.4045 0.2539 0.3891 0.4015 0.3610 0.4285 sigma^2 estimated as 7900: log likelihood = -185.47, aic = 384.94 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 33 End = 60 Frequency = 1 [1] 6452.427 6502.047 6553.689 6540.941 6509.902 6517.979 6540.813 6537.440 [9] 6521.430 6522.396 6533.561 6533.868 6526.173 6525.292 6530.537 6531.603 [17] 6528.068 6527.023 6529.377 6530.305 6528.757 6527.981 6528.984 6529.608 [25] 6528.969 6528.482 6528.881 6529.253 $se Time Series: Start = 33 End = 60 Frequency = 1 [1] 91.52586 127.86322 157.30074 209.47062 261.09425 291.81083 314.64681 [8] 342.33336 371.88839 395.42676 415.09335 435.90941 457.63203 477.16673 [15] 494.68063 512.23600 530.08556 547.00070 562.81289 578.36864 593.92362 [22] 608.99897 623.43544 637.57576 651.59357 665.31137 678.62910 691.68311 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 6273.036 6251.435 6245.380 6130.379 5998.157 5946.029 5924.105 5866.466 [9] 5792.529 5747.359 5719.978 5679.485 5629.215 5590.045 5560.963 5527.620 [17] 5489.101 5454.902 5426.264 5396.702 5364.667 5334.343 5307.050 5279.959 [25] 5251.845 5224.471 5198.768 5173.554 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 6631.817 6752.658 6861.999 6951.504 7021.647 7089.928 7157.521 7208.413 [9] 7250.331 7297.432 7347.144 7388.250 7423.132 7460.539 7500.111 7535.586 [17] 7567.036 7599.145 7632.490 7663.907 7692.848 7721.619 7750.917 7779.256 [25] 7806.092 7832.492 7858.994 7884.952 > 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] 5594.000 5585.000 5710.000 5511.000 5403.000 5826.000 5884.000 5965.000 [9] 5960.000 6064.000 6046.000 5954.000 5952.000 5960.000 5983.000 5996.000 [17] 6021.000 6094.000 6202.000 6276.000 6306.000 6342.000 6345.000 6328.000 [25] 6191.000 6261.000 6253.000 6198.000 6247.000 6293.000 6381.000 6448.000 [33] 6452.427 6502.047 6553.689 6540.941 6509.902 6517.979 6540.813 6537.440 [41] 6521.430 6522.396 6533.561 6533.868 6526.173 6525.292 6530.537 6531.603 [49] 6528.068 6527.023 6529.377 6530.305 6528.757 6527.981 6528.984 6529.608 [57] 6528.969 6528.482 6528.881 6529.253 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 33 End = 60 Frequency = 1 [1] 0.01418472 0.01966507 0.02400186 0.03202454 0.04010725 0.04477014 [7] 0.04810515 0.05236505 0.05702559 0.06062600 0.06353248 0.06671537 [13] 0.07012257 0.07312573 0.07574885 0.07842424 0.08120098 0.08380554 [19] 0.08619703 0.08856687 0.09097039 0.09329055 0.09548736 0.09764381 [25] 0.09980038 0.10190905 0.10394263 0.10593603 > postscript(file="/var/www/html/rcomp/tmp/1lpjw1260542738.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/2tmem1260542738.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/32e2o1260542738.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/4aucy1260542738.tab") > > system("convert tmp/1lpjw1260542738.ps tmp/1lpjw1260542738.png") > system("convert tmp/2tmem1260542738.ps tmp/2tmem1260542738.png") > > > proc.time() user system elapsed 0.732 0.319 1.259