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(14.2,13.5,11.9,14.6,15.6,14.1,14.9,14.2,14.6,17.2,15.4,14.3,17.5,14.5,14.4,16.6,16.7,16.6,16.9,15.7,16.4,18.4,16.9,16.5,18.3,15.1,15.7,18.1,16.8,18.9,19,18.1,17.8,21.5,17.1,18.7,19,16.4,16.9,18.6,19.3,19.4,17.6,18.6,18.1,20.4,18.1,19.6,19.9,19.2,17.8,19.2,22,21.1,19.5,22.2,20.9,22.2,23.5,21.5,24.3,22.8,20.3,23.7,23.3,19.6,18,17.3,16.8,18.2,16.5,16,18.4) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '0' > 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 sma1 -1.2448 -1.1545 -0.1544 0.5855 0.3089 -0.5886 0.6669 s.e. 0.2338 0.2478 0.2329 0.2051 0.2126 0.1834 0.3074 sigma^2 estimated as 0.8253: log likelihood = -64.19, aic = 144.37 Warning message: In log(s2) : NaNs produced > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 46 End = 73 Frequency = 1 [1] 20.10833 17.18096 19.03825 18.51312 17.31581 18.27110 18.00654 18.86961 [9] 18.85985 16.96491 17.86016 18.34239 17.62797 17.57331 18.61572 17.49152 [17] 17.69588 18.57849 17.41741 17.81219 18.52501 17.36114 17.92603 18.45653 [25] 17.32365 18.03419 18.37575 17.30512 $se Time Series: Start = 46 End = 73 Frequency = 1 [1] 0.9331073 0.9803471 1.0194656 1.0801396 1.1442345 1.1748572 1.2314331 [8] 1.2847803 1.3125388 1.3657622 1.4111784 1.4372113 1.7482961 1.8297740 [15] 1.8871671 1.9878686 2.0714133 2.1217229 2.2150600 2.2858622 2.3334046 [22] 2.4205119 2.4816596 2.5276515 2.6093764 2.6629659 2.7082141 2.7850130 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 46 End = 73 Frequency = 1 [1] 18.27944 15.25948 17.04009 16.39604 15.07311 15.96838 15.59293 16.35144 [9] 16.28727 14.28802 15.09425 15.52545 14.20131 13.98695 14.91687 13.59530 [17] 13.63591 14.41992 13.07590 13.33190 13.95154 12.61694 13.06198 13.50234 [25] 12.20927 12.81478 13.06765 11.84649 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 46 End = 73 Frequency = 1 [1] 21.93723 19.10244 21.03640 20.63019 19.55851 20.57382 20.42015 21.38778 [9] 21.43242 19.64181 20.62607 21.15932 21.05463 21.15967 22.31457 21.38774 [17] 21.75585 22.73707 21.75893 22.29248 23.09849 22.10535 22.79008 23.41073 [25] 22.43803 23.25360 23.68385 22.76374 > 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] 14.20000 13.50000 11.90000 14.60000 15.60000 14.10000 14.90000 14.20000 [9] 14.60000 17.20000 15.40000 14.30000 17.50000 14.50000 14.40000 16.60000 [17] 16.70000 16.60000 16.90000 15.70000 16.40000 18.40000 16.90000 16.50000 [25] 18.30000 15.10000 15.70000 18.10000 16.80000 18.90000 19.00000 18.10000 [33] 17.80000 21.50000 17.10000 18.70000 19.00000 16.40000 16.90000 18.60000 [41] 19.30000 19.40000 17.60000 18.60000 18.10000 20.10833 17.18096 19.03825 [49] 18.51312 17.31581 18.27110 18.00654 18.86961 18.85985 16.96491 17.86016 [57] 18.34239 17.62797 17.57331 18.61572 17.49152 17.69588 18.57849 17.41741 [65] 17.81219 18.52501 17.36114 17.92603 18.45653 17.32365 18.03419 18.37575 [73] 17.30512 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 46 End = 73 Frequency = 1 [1] 0.04640400 0.05706008 0.05354829 0.05834455 0.06608034 0.06430140 [7] 0.06838810 0.06808727 0.06959435 0.08050512 0.07901263 0.07835464 [13] 0.09917737 0.10412232 0.10137491 0.11364757 0.11705621 0.11420318 [19] 0.12717502 0.12833132 0.12595967 0.13942123 0.13843890 0.13695158 [25] 0.15062511 0.14766208 0.14737977 0.16093579 > postscript(file="/var/www/html/rcomp/tmp/1u0ce1261155532.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/26evq1261155532.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/3d81n1261155532.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/4td2g1261155532.tab") > > try(system("convert tmp/1u0ce1261155532.ps tmp/1u0ce1261155532.png",intern=TRUE)) character(0) > try(system("convert tmp/26evq1261155532.ps tmp/26evq1261155532.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.390 0.347 1.642