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(116222,110924,103753,99983,93302,91496,119321,139261,133739,123913,113438,109416,109406,105645,101328,97686,93093,91382,122257,139183,139887,131822,116805,113706,113012,110452,107005,102841,98173,98181,137277,147579,146571,138920,130340,128140,127059,122860,117702,113537,108366,111078,150739,159129,157928,147768,137507,136919,136151,133001,125554,119647,114158,116193,152803,161761,160942,149470,139208,134588,130322,126611,122401,117352,112135,112879,148729,157230,157221,146681,136524,132111) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > 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 0.4554 0.1594 -0.4401 -0.8998 -0.1186 0.6994 s.e. NaN NaN NaN NaN NaN NaN sigma^2 estimated as 6424568: log likelihood = -288.66, aic = 591.32 Warning message: In sqrt(diag(x$var.coef)) : NaNs produced > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 45 End = 72 Frequency = 1 [1] 157749.1 149948.3 141423.0 139387.7 138456.4 134327.7 129153.1 124925.9 [9] 119693.0 122374.2 162038.6 170452.6 169097.7 161310.6 152785.0 150740.7 [17] 149799.2 145664.6 140489.6 136265.8 131036.9 133720.7 173385.5 181798.2 [25] 180441.7 172653.5 164127.7 162083.8 $se Time Series: Start = 45 End = 72 Frequency = 1 [1] 2600.633 3024.724 3222.751 3489.206 3940.975 4553.191 5178.669 [8] 5710.797 6124.264 6452.332 6738.928 7018.734 8411.880 9173.080 [15] 9737.221 10341.581 11069.902 11900.313 12736.015 13500.063 14166.095 [22] 14754.175 15298.455 15828.684 17201.234 18137.212 18911.429 19715.157 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 45 End = 72 Frequency = 1 [1] 152651.9 144019.9 135106.5 132548.9 130732.1 125403.4 119002.9 113732.7 [9] 107689.4 109727.6 148830.3 156695.8 152610.4 143331.3 133700.0 130471.2 [17] 128102.2 122340.0 115527.0 109805.7 103271.4 104802.5 143400.5 150774.0 [25] 146727.2 137104.5 127061.3 123442.1 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 45 End = 72 Frequency = 1 [1] 162846.4 155876.8 147739.6 146226.6 146180.7 143251.9 139303.3 136119.1 [9] 131696.5 135020.7 175246.9 184209.3 185585.0 179289.8 171869.9 171010.2 [17] 171496.2 168989.2 165452.2 162725.9 158802.5 162638.9 203370.5 212822.4 [25] 214156.1 208202.4 201194.1 200725.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] 116222.0 110924.0 103753.0 99983.0 93302.0 91496.0 119321.0 139261.0 [9] 133739.0 123913.0 113438.0 109416.0 109406.0 105645.0 101328.0 97686.0 [17] 93093.0 91382.0 122257.0 139183.0 139887.0 131822.0 116805.0 113706.0 [25] 113012.0 110452.0 107005.0 102841.0 98173.0 98181.0 137277.0 147579.0 [33] 146571.0 138920.0 130340.0 128140.0 127059.0 122860.0 117702.0 113537.0 [41] 108366.0 111078.0 150739.0 159129.0 157749.1 149948.3 141423.0 139387.7 [49] 138456.4 134327.7 129153.1 124925.9 119693.0 122374.2 162038.6 170452.6 [57] 169097.7 161310.6 152785.0 150740.7 149799.2 145664.6 140489.6 136265.8 [65] 131036.9 133720.7 173385.5 181798.2 180441.7 172653.5 164127.7 162083.8 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 45 End = 72 Frequency = 1 [1] 0.01648588 0.02017177 0.02278802 0.02503238 0.02846366 0.03389614 [7] 0.04009714 0.04571347 0.05116644 0.05272625 0.04158840 0.04117705 [13] 0.04974568 0.05686595 0.06373154 0.06860510 0.07389828 0.08169668 [19] 0.09065449 0.09907155 0.10810764 0.11033577 0.08823377 0.08706734 [25] 0.09532850 0.10504979 0.11522390 0.12163556 > postscript(file="/var/www/html/rcomp/tmp/1d7w71260459002.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/2saf31260459002.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/39f5k1260459002.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/47bfq1260459002.tab") > > system("convert tmp/1d7w71260459002.ps tmp/1d7w71260459002.png") > system("convert tmp/2saf31260459002.ps tmp/2saf31260459002.png") > > > proc.time() user system elapsed 0.898 0.362 3.076