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(11.40,11.00,9.20,7.10,9.30,9.30,11.50,13.00,13.20,13.10,13.90,11.00,11.30,10.80,11.20,12.90,13.90,14.50,14.50,13.30,12.00,11.50,11.00,12.10,13.00,14.00,15.10,14.50,14.20,13.30,12.70,11.80,11.40,10.50,9.60,10.80,10.70,11.90,12.00,11.10,10.90,10.40,10.70,12.10,12.80,13.90,13.50,12.00,12.00,11.50,12.50,13.10,12.70,12.80,12.50,13.00,13.20,12.80,12.40,12.00,11.80,11.10,8.50,6.30) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '0' > 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 1.2705 -0.5531 -0.2026 -1.5031 1.2576 -0.5336 s.e. 0.3982 0.6025 0.3732 0.4144 0.6049 0.3414 sigma^2 estimated as 0.6814: log likelihood = -44.57, aic = 103.14 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 37 End = 64 Frequency = 1 [1] 10.65284 11.75353 12.58627 13.06532 12.99034 12.46140 11.73377 11.11705 [9] 10.84314 10.98367 11.43867 11.99453 12.42062 12.56233 12.39409 12.01561 [17] 11.59909 11.31333 11.25732 11.42862 11.73513 12.04116 12.22574 12.22888 [25] 12.06876 11.82620 11.60595 11.49272 $se Time Series: Start = 37 End = 64 Frequency = 1 [1] 0.8254623 1.0404816 1.4231447 1.6828978 1.8069850 1.8359387 1.8365894 [8] 1.8378711 1.8378724 1.8501829 1.9078774 2.0173551 2.1401072 2.2317407 [15] 2.2783397 2.2942658 2.2987357 2.3019777 2.3109524 2.3364391 2.3856808 [22] 2.4512816 2.5147627 2.5613551 2.5887222 2.6034428 2.6133462 2.6245304 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 37 End = 64 Frequency = 1 [1] 9.034936 9.714188 9.796905 9.766839 9.448654 8.862957 8.134052 7.514827 [9] 7.240912 7.357310 7.699229 8.040511 8.226008 8.188123 7.928543 7.518851 [17] 7.093572 6.801452 6.727856 6.849199 7.059197 7.236651 7.296805 7.208620 [25] 6.994867 6.723455 6.483793 6.348641 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 37 End = 64 Frequency = 1 [1] 12.27075 13.79288 15.37563 16.36380 16.53203 16.05984 15.33348 14.71928 [9] 14.44537 14.61003 15.17811 15.94854 16.61523 16.93655 16.85963 16.51237 [17] 16.10462 15.82521 15.78679 16.00804 16.41107 16.84568 17.15468 17.24913 [25] 17.14266 16.92895 16.72811 16.63680 > 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] 11.40000 11.00000 9.20000 7.10000 9.30000 9.30000 11.50000 13.00000 [9] 13.20000 13.10000 13.90000 11.00000 11.30000 10.80000 11.20000 12.90000 [17] 13.90000 14.50000 14.50000 13.30000 12.00000 11.50000 11.00000 12.10000 [25] 13.00000 14.00000 15.10000 14.50000 14.20000 13.30000 12.70000 11.80000 [33] 11.40000 10.50000 9.60000 10.80000 10.65284 11.75353 12.58627 13.06532 [41] 12.99034 12.46140 11.73377 11.11705 10.84314 10.98367 11.43867 11.99453 [49] 12.42062 12.56233 12.39409 12.01561 11.59909 11.31333 11.25732 11.42862 [57] 11.73513 12.04116 12.22574 12.22888 12.06876 11.82620 11.60595 11.49272 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 37 End = 64 Frequency = 1 [1] 0.07748752 0.08852501 0.11307122 0.12880649 0.13910216 0.14733009 [7] 0.15652172 0.16531997 0.16949630 0.16844854 0.16679191 0.16818964 [13] 0.17230280 0.17765334 0.18382471 0.19094041 0.19818235 0.20347484 [19] 0.20528436 0.20443757 0.20329391 0.20357516 0.20569411 0.20945139 [25] 0.21449773 0.22014190 0.22517294 0.22836459 > postscript(file="/var/www/html/rcomp/tmp/1z9un1260564135.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/2k38w1260564135.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/3wj091260564135.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/45nxg1260564135.tab") > > system("convert tmp/1z9un1260564135.ps tmp/1z9un1260564135.png") > system("convert tmp/2k38w1260564135.ps tmp/2k38w1260564135.png") > > > proc.time() user system elapsed 0.760 0.329 0.889