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(96.96,93.11,95.62,98.30,96.38,100.82,99.06,94.03,102.07,99.31,98.64,101.82,99.14,97.63,100.06,101.32,101.49,105.43,105.09,99.48,108.53,104.34,106.10,107.35,103.00,104.50,105.17,104.84,106.18,108.86,107.77,102.74,112.63,106.26,108.86,111.38,106.85,107.86,107.94,111.38,111.29,113.72,111.88,109.87,113.72,111.71,114.81,112.05,111.54,110.87,110.87,115.48,111.63,116.24,113.56,106.01,110.45,107.77,108.61,108.19) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '3' > 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.0888 0.0643 0.4242 -1.0343 0.4374 0.1552 s.e. 0.4433 0.4995 0.3171 0.5775 0.7642 0.8026 sigma^2 estimated as 0.934: log likelihood = -27.75, aic = 69.49 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 33 End = 60 Frequency = 1 [1] 110.8795 106.1990 108.0951 108.9394 104.3541 105.8649 106.3486 105.9029 [9] 107.2252 109.8172 108.6692 103.6208 111.7177 107.0076 108.8905 109.7137 [17] 105.1131 106.6155 107.0885 106.6349 107.9523 110.5388 109.3866 104.3354 [25] 112.4294 107.7171 109.5985 110.4202 $se Time Series: Start = 33 End = 60 Frequency = 1 [1] 0.9667559 0.9682134 1.0704265 1.4605256 1.6109054 1.8248628 [7] 2.1209373 2.3359436 2.5650439 2.8131080 3.0298895 3.2455022 [13] 3.9052778 4.1010112 4.4292677 4.9587520 5.3159004 5.7165108 [19] 6.1748717 6.5666017 6.9641554 7.3723047 7.7502310 8.1224580 [25] 8.8215441 9.1750476 9.6360966 10.2527942 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 108.98467 104.30132 105.99709 106.07681 101.19672 102.28812 102.19154 [8] 101.32445 102.19772 104.30349 102.73057 97.25966 104.06331 98.96959 [15] 100.20918 99.99452 94.69389 95.41115 94.98579 93.76435 94.30255 [22] 96.08906 94.19611 88.41543 95.13918 89.73403 90.71177 90.32469 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 112.7744 108.0967 110.1932 111.8021 107.5115 109.4416 110.5056 110.4813 [9] 112.2527 115.3309 114.6077 109.9820 119.3720 115.0456 117.5719 119.4328 [17] 115.5322 117.8199 119.1913 119.5054 121.6020 124.9885 124.5770 120.2555 [25] 129.7196 125.7002 128.4853 130.5156 > 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] 96.9600 93.1100 95.6200 98.3000 96.3800 100.8200 99.0600 94.0300 [9] 102.0700 99.3100 98.6400 101.8200 99.1400 97.6300 100.0600 101.3200 [17] 101.4900 105.4300 105.0900 99.4800 108.5300 104.3400 106.1000 107.3500 [25] 103.0000 104.5000 105.1700 104.8400 106.1800 108.8600 107.7700 102.7400 [33] 110.8795 106.1990 108.0951 108.9394 104.3541 105.8649 106.3486 105.9029 [41] 107.2252 109.8172 108.6692 103.6208 111.7177 107.0076 108.8905 109.7137 [49] 105.1131 106.6155 107.0885 106.6349 107.9523 110.5388 109.3866 104.3354 [57] 112.4294 107.7171 109.5985 110.4202 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 33 End = 60 Frequency = 1 [1] 0.008718977 0.009116971 0.009902634 0.013406766 0.015436916 0.017237664 [7] 0.019943259 0.022057410 0.023922023 0.025616283 0.027881780 0.031320940 [13] 0.034956676 0.038324495 0.040676331 0.045197210 0.050573171 0.053618001 [19] 0.057661368 0.061580235 0.064511418 0.066694285 0.070851762 0.077849460 [25] 0.078462960 0.085177245 0.087921778 0.092852555 > postscript(file="/var/www/html/rcomp/tmp/1hchr1260552274.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/2jp511260552274.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/36v7y1260552274.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/4mugb1260552274.tab") > system("convert tmp/1hchr1260552274.ps tmp/1hchr1260552274.png") > system("convert tmp/2jp511260552274.ps tmp/2jp511260552274.png") > > > proc.time() user system elapsed 0.870 0.337 1.184