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(267413,267366,264777,258863,254844,254868,277267,285351,286602,283042,276687,277915,277128,277103,275037,270150,267140,264993,287259,291186,292300,288186,281477,282656,280190,280408,276836,275216,274352,271311,289802,290726,292300,278506,269826,265861,269034,264176,255198,253353,246057,235372,258556,260993,254663,250643,243422,247105,248541,245039,237080,237085,225554,226839,247934,248333,246969,245098,246263,255765,264319,268347,273046,273963,267430,271993,292710) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '2' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '6' > 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.2044 0.4834 0.2594 0.1722 0.0149 -0.9101 s.e. 0.3039 0.2083 0.2327 0.2453 0.2242 0.2260 sigma^2 estimated as 6224559: log likelihood = -242.69, aic = 499.37 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 40 End = 67 Frequency = 1 [1] 248783.8 245467.4 242584.4 258678.5 258552.7 258794.5 243598.9 233716.2 [9] 228482.2 230450.8 224421.2 214292.3 206764.0 202359.7 198417.3 213479.9 [17] 212348.8 211611.8 195462.6 184650.9 178512.2 179599.4 172711.3 161746.2 [25] 153403.4 148205.6 143490.4 157800.2 $se Time Series: Start = 40 End = 67 Frequency = 1 [1] 2580.891 4315.136 6485.928 7633.294 8992.578 10224.770 11394.726 [8] 12569.464 13708.186 14838.222 15958.429 17069.233 19215.774 21608.195 [15] 24447.915 26722.563 29164.136 31518.726 33823.667 36129.534 38401.472 [22] 40661.107 42907.130 45139.668 48207.715 51497.750 55169.341 58436.402 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 40 End = 67 Frequency = 1 [1] 243725.23 237009.72 229872.02 243717.26 240927.25 238753.99 221265.27 [8] 209080.00 201614.14 201367.87 193142.65 180836.60 169101.12 160007.61 [15] 150499.35 161103.65 155187.14 149835.06 129168.18 113837.01 103245.27 [22] 99903.65 88613.35 73272.48 58916.31 47270.05 35358.47 43264.82 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 40 End = 67 Frequency = 1 [1] 253842.3 253925.1 255296.9 273639.8 276178.2 278835.1 265932.6 258352.3 [9] 255350.2 259533.7 255699.7 247748.0 244427.0 244711.7 246335.2 265856.1 [17] 269510.6 273388.5 261757.0 255464.8 253779.0 259295.2 256809.3 250220.0 [25] 247890.6 249141.2 251622.3 272335.5 > 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] 267413.0 267366.0 264777.0 258863.0 254844.0 254868.0 277267.0 285351.0 [9] 286602.0 283042.0 276687.0 277915.0 277128.0 277103.0 275037.0 270150.0 [17] 267140.0 264993.0 287259.0 291186.0 292300.0 288186.0 281477.0 282656.0 [25] 280190.0 280408.0 276836.0 275216.0 274352.0 271311.0 289802.0 290726.0 [33] 292300.0 278506.0 269826.0 265861.0 269034.0 264176.0 255198.0 248783.8 [41] 245467.4 242584.4 258678.5 258552.7 258794.5 243598.9 233716.2 228482.2 [49] 230450.8 224421.2 214292.3 206764.0 202359.7 198417.3 213479.9 212348.8 [57] 211611.8 195462.6 184650.9 178512.2 179599.4 172711.3 161746.2 153403.4 [65] 148205.6 143490.4 157800.2 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 40 End = 67 Frequency = 1 [1] 0.01037403 0.01757927 0.02673678 0.02950881 0.03478044 0.03950922 [7] 0.04677658 0.05378090 0.05999674 0.06438781 0.07110929 0.07965397 [13] 0.09293576 0.10678113 0.12321466 0.12517603 0.13734069 0.14894600 [19] 0.17304422 0.19566400 0.21511964 0.22639888 0.24843263 0.27907709 [25] 0.31425447 0.34747496 0.38448111 0.37031901 > postscript(file="/var/www/html/rcomp/tmp/18kkq1261083633.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/222uw1261083633.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/31mkk1261083633.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/4bp4u1261083633.tab") > try(system("convert tmp/18kkq1261083633.ps tmp/18kkq1261083633.png",intern=TRUE)) character(0) > try(system("convert tmp/222uw1261083633.ps tmp/222uw1261083633.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.874 0.303 1.153