R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-pc-linux-gnu (32-bit) 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(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,295881,293299,288576,286445,297584,300431,298522,292213,285383,277537,277891,302686,300653,296369,287224,279998,283495,285775,282329,277799,271980,266730,262433,285378,286692,282917,277686,274371) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '24' > 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 ma1 sma1 0.8947 -0.6902 -0.5459 s.e. 0.1006 0.1451 0.2091 sigma^2 estimated as 17653250: log likelihood = -470.71, aic = 949.42 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 62 End = 85 Frequency = 1 [1] 292178.1 297397.8 298360.7 297395.9 297652.2 290945.0 291874.3 313332.1 [9] 315902.4 313995.4 309628.0 307004.7 312498.9 317504.9 318276.6 317140.8 [17] 317244.0 310399.9 311206.8 332554.9 335027.2 333032.5 328586.7 325893.1 $se Time Series: Start = 62 End = 85 Frequency = 1 [1] 4205.857 6584.474 8797.938 10952.071 13072.463 15165.088 17229.895 [8] 19265.019 21268.276 23237.709 25171.766 27069.327 29661.258 32282.656 [15] 34912.885 37536.718 40142.936 42723.303 45271.823 47784.202 50257.435 [22] 52689.511 55079.177 57425.766 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 62 End = 85 Frequency = 1 [1] 283934.6 284492.3 281116.8 275929.9 272030.1 261221.4 258103.7 275572.6 [9] 274216.6 268449.5 260291.4 253948.8 254362.8 254230.9 249847.4 243568.8 [17] 238563.9 226662.2 222474.0 238897.9 236522.7 229761.0 220631.5 213338.6 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 62 End = 85 Frequency = 1 [1] 300421.6 310303.4 315604.7 318862.0 323274.2 320668.5 325644.9 351091.5 [9] 357588.2 359541.3 358964.7 360060.5 370635.0 380779.0 386705.9 390712.8 [17] 395924.2 394137.6 399939.6 426211.9 433531.8 436303.9 436541.8 438447.6 > 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] 276687.0 277915.0 277128.0 277103.0 275037.0 270150.0 267140.0 264993.0 [9] 287259.0 291186.0 292300.0 288186.0 281477.0 282656.0 280190.0 280408.0 [17] 276836.0 275216.0 274352.0 271311.0 289802.0 290726.0 292300.0 278506.0 [25] 269826.0 265861.0 269034.0 264176.0 255198.0 253353.0 246057.0 235372.0 [33] 258556.0 260993.0 254663.0 250643.0 243422.0 247105.0 248541.0 245039.0 [41] 237080.0 237085.0 225554.0 226839.0 247934.0 248333.0 246969.0 245098.0 [49] 246263.0 255765.0 264319.0 268347.0 273046.0 273963.0 267430.0 271993.0 [57] 292710.0 295881.0 293299.0 288576.0 286445.0 292178.1 297397.8 298360.7 [65] 297395.9 297652.2 290945.0 291874.3 313332.1 315902.4 313995.4 309628.0 [73] 307004.7 312498.9 317504.9 318276.6 317140.8 317244.0 310399.9 311206.8 [81] 332554.9 335027.2 333032.5 328586.7 325893.1 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 62 End = 85 Frequency = 1 [1] 0.01439484 0.02214029 0.02948759 0.03682657 0.04391859 0.05212356 [7] 0.05903189 0.06148435 0.06732546 0.07400654 0.08129679 0.08817236 [13] 0.09491636 0.10167607 0.10969352 0.11835979 0.12653647 0.13763955 [19] 0.14547184 0.14368816 0.15001000 0.15821134 0.16762451 0.17621045 > postscript(file="/var/wessaorg/rcomp/tmp/186bl1324669275.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/wessaorg/rcomp/tmp/2mzf31324669275.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/3hmfz1324669275.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/wessaorg/rcomp/tmp/4pusp1324669275.tab") > > try(system("convert tmp/186bl1324669275.ps tmp/186bl1324669275.png",intern=TRUE)) character(0) > try(system("convert tmp/2mzf31324669275.ps tmp/2mzf31324669275.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.999 0.179 1.170