R version 2.12.0 (2010-10-15) Copyright (C) 2010 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(10.92,10.98,11.15,11.19,11.33,11.38,11.4,11.45,11.56,11.61,11.82,11.77,11.85,11.82,11.92,11.86,11.87,11.94,11.86,11.92,11.83,11.91,11.93,11.99,11.96,12.12,11.85,12.01,12.1,12.21,12.31,12.31,12.39,12.35,12.41,12.51,12.27,12.51,12.44,12.47,12.51,12.58,12.5,12.52,12.59,12.51,12.67,12.64,12.54,12.66,12.67,12.62,12.72,12.85,12.85,12.82) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > par6 = '1' > par5 = '12' > par4 = '0' > par3 = '2' > 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.3567 0.015 -0.8275 -1.7951 1.7535 -0.6693 s.e. 0.1376 0.168 0.1360 0.2025 0.2701 0.2021 sigma^2 estimated as 0.00434: log likelihood = 30.88, aic = -47.76 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 29 End = 56 Frequency = 1 [1] 11.83879 11.98515 11.89634 12.00246 11.91181 11.94848 11.86634 11.90653 [9] 11.88322 11.93742 11.91708 11.92386 11.87506 11.86851 11.85378 11.88274 [17] 11.89220 11.90214 11.87579 11.85265 11.82971 11.83692 11.85223 11.87072 [25] 11.86551 11.84520 11.81651 11.80421 $se Time Series: Start = 29 End = 56 Frequency = 1 [1] 0.06797268 0.07916342 0.12255415 0.14353595 0.18119460 0.20615381 [7] 0.24324270 0.27545841 0.31804674 0.35746401 0.40204083 0.44295855 [13] 0.48707352 0.53053697 0.57854245 0.62768560 0.67976459 0.73123164 [19] 0.78347688 0.83551419 0.88964441 0.94559567 1.00406340 1.06342575 [25] 1.12330634 1.18298597 1.24342957 1.30522668 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 29 End = 56 Frequency = 1 [1] 11.705567 11.829994 11.656138 11.721125 11.556665 11.544417 11.389580 [8] 11.366627 11.259852 11.236790 11.129083 11.055656 10.920392 10.828660 [15] 10.719836 10.652477 10.559863 10.468922 10.340177 10.215041 10.086010 [22] 9.983552 9.884269 9.786403 9.663832 9.526543 9.379387 9.245970 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 29 End = 56 Frequency = 1 [1] 11.97202 12.14031 12.13655 12.28379 12.26695 12.35254 12.34309 12.44642 [9] 12.50660 12.63805 12.70508 12.79205 12.82972 12.90836 12.98772 13.11300 [17] 13.22454 13.33535 13.41141 13.49026 13.57342 13.69029 13.82020 13.95503 [25] 14.06719 14.16385 14.25363 14.36246 > 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] 10.92000 10.98000 11.15000 11.19000 11.33000 11.38000 11.40000 11.45000 [9] 11.56000 11.61000 11.82000 11.77000 11.85000 11.82000 11.92000 11.86000 [17] 11.87000 11.94000 11.86000 11.92000 11.83000 11.91000 11.93000 11.99000 [25] 11.96000 12.12000 11.85000 12.01000 11.83879 11.98515 11.89634 12.00246 [33] 11.91181 11.94848 11.86634 11.90653 11.88322 11.93742 11.91708 11.92386 [41] 11.87506 11.86851 11.85378 11.88274 11.89220 11.90214 11.87579 11.85265 [49] 11.82971 11.83692 11.85223 11.87072 11.86551 11.84520 11.81651 11.80421 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 29 End = 56 Frequency = 1 [1] 0.005741521 0.006605124 0.010301833 0.011958882 0.015211345 0.017253562 [7] 0.020498553 0.023135078 0.026764348 0.029944831 0.033736514 0.037148937 [13] 0.041016524 0.044701218 0.048806581 0.052823301 0.057160533 0.061437007 [19] 0.065972600 0.070491770 0.075204225 0.079885283 0.084715126 0.089583951 [25] 0.094669857 0.099870533 0.105228164 0.110572942 > postscript(file="/var/www/rcomp/tmp/1j1cq1293187840.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/www/rcomp/tmp/2q2911293187840.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/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/rcomp/tmp/3f3ov1293187840.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/rcomp/tmp/4i3m11293187840.tab") > > try(system("convert tmp/1j1cq1293187840.ps tmp/1j1cq1293187840.png",intern=TRUE)) character(0) > try(system("convert tmp/2q2911293187840.ps tmp/2q2911293187840.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.830 0.460 1.285