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(359640,364080,364080,359640,359640,359640,359640,359640,364080,368520,372960,377400,406780,402050,392590,368940,368940,378400,406780,420970,420970,406780,392590,392590,394250,399000,403750,399000,408500,403750,403750,399000,403750,403750,403750,403750,405450,405450,405450,405450,410220,400680,386370,381600,381600,381600,381600,376830,381420,381420,386310,396090,391200,371640,356970,342300,332520,342300,347190,352080,357130,347070,337010,337010,331980) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '1' > par1 = '12' > 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.2896 0.0382 -0.5440 -0.0433 -0.0374 -0.0683 s.e. 0.2301 0.2451 0.2145 0.2793 0.2586 0.2359 sigma^2 estimated as 49418664: log likelihood = -370.68, aic = 755.36 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 38 End = 65 Frequency = 1 [1] 405950.3 405917.6 404890.3 404319.5 404132.8 404615.7 405058.9 405307.3 [9] 405133.5 404851.5 404628.1 404647.2 404797.6 404963.4 405006.8 404943.8 [17] 404837.1 404780.1 404793.8 404853.7 404902.5 404911.5 404883.4 404849.0 [25] 404833.1 404842.5 404863.3 404878.3 $se Time Series: Start = 38 End = 65 Frequency = 1 [1] 7029.841 11232.978 14563.050 15455.826 15757.680 15887.547 16352.265 [8] 17255.992 18483.526 19434.670 20061.721 20466.416 20868.834 21372.190 [15] 22012.477 22681.035 23282.613 23781.775 24225.111 24666.060 25141.574 [22] 25645.622 26149.329 26624.474 27067.173 27490.717 27912.968 28342.327 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 38 End = 65 Frequency = 1 [1] 392171.8 383900.9 376346.8 374026.1 373247.7 373476.1 373008.5 371485.6 [9] 368905.8 366759.5 365307.1 364533.0 363894.7 363073.9 361862.3 360489.0 [17] 359203.1 358167.9 357312.6 356508.2 355625.0 354646.1 353630.7 352665.1 [25] 351781.5 350960.7 350153.9 349327.4 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 38 End = 65 Frequency = 1 [1] 419728.7 427934.2 433433.9 434612.9 435017.8 435755.3 437109.4 439129.1 [9] 441361.2 442943.4 443949.0 444761.3 445700.5 446852.9 448151.2 449398.7 [17] 450471.0 451392.4 452275.0 453199.2 454180.0 455176.9 456136.1 457033.0 [25] 457884.8 458724.3 459572.7 460429.3 > 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] 359640.0 364080.0 364080.0 359640.0 359640.0 359640.0 359640.0 359640.0 [9] 364080.0 368520.0 372960.0 377400.0 406780.0 402050.0 392590.0 368940.0 [17] 368940.0 378400.0 406780.0 420970.0 420970.0 406780.0 392590.0 392590.0 [25] 394250.0 399000.0 403750.0 399000.0 408500.0 403750.0 403750.0 399000.0 [33] 403750.0 403750.0 403750.0 403750.0 405450.0 405950.3 405917.6 404890.3 [41] 404319.5 404132.8 404615.7 405058.9 405307.3 405133.5 404851.5 404628.1 [49] 404647.2 404797.6 404963.4 405006.8 404943.8 404837.1 404780.1 404793.8 [57] 404853.7 404902.5 404911.5 404883.4 404849.0 404833.1 404842.5 404863.3 [65] 404878.3 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 38 End = 65 Frequency = 1 [1] 0.01731700 0.02767305 0.03596789 0.03822676 0.03899135 0.03926577 [7] 0.04037009 0.04257508 0.04562330 0.04800445 0.04958065 0.05057842 [13] 0.05155375 0.05277561 0.05435089 0.05601032 0.05751107 0.05875233 [19] 0.05984556 0.06092586 0.06209291 0.06333636 0.06458484 0.06576395 [25] 0.06686007 0.06790472 0.06894418 0.07000208 > postscript(file="/var/www/html/rcomp/tmp/1mgf21261171707.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/2m93a1261171707.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/3d96e1261171707.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/4e1d41261171707.tab") > try(system("convert tmp/1mgf21261171707.ps tmp/1mgf21261171707.png",intern=TRUE)) character(0) > try(system("convert tmp/2m93a1261171707.ps tmp/2m93a1261171707.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.724 0.335 1.198