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(128.6,128.9,129.06,129.23,129.27,129.33,129.35,129.31,129.4,129.49,129.47,129.46,129.45,129.28,129.2,129.25,129.14,129.11,129.02,129.08,128.99,129.11,129.08,129.19,129.23,129.25,129.31,129.33,129.39,129.55,129.43,129.45,129.57,129.76,129.92,130.08,130.41,130.84,131.24,131.49,131.74,132.34,133.5,134.43,136.5,137.41,138.02,138.15,138.24,138.2,138.31,138.65,139.3,139.8,140.52,141.57,141.77,141.66,141.36,141.17) > par10 = 'FALSE' > par9 = '0' > par8 = '2' > par7 = '0' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '1' > par1 = '1' > 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 sar1 sar2 -0.1483 0.2770 -0.5746 0.2785 0.2934 0.9913 -0.6154 -0.3650 s.e. 0.2010 0.1908 0.1766 0.1272 0.1340 0.1334 0.2747 0.2909 sigma^2 estimated as 0.004177: log likelihood = 35.17, aic = -52.35 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 33 End = 60 Frequency = 1 [1] 129.3699 129.2760 129.2351 129.2435 129.1860 129.2995 129.2306 129.2477 [9] 129.1903 129.1602 129.2141 129.2385 129.2644 129.3332 129.3120 129.3227 [17] 129.2878 129.2674 129.2318 129.2700 129.2270 129.2432 129.1977 129.2317 [25] 129.1888 129.2369 129.2087 129.2552 $se Time Series: Start = 33 End = 60 Frequency = 1 [1] 0.06735632 0.09982185 0.15005639 0.19899517 0.24046376 0.26758740 [7] 0.28951092 0.30769474 0.32789791 0.34721350 0.36743590 0.38480758 [13] 0.39202974 0.39748185 0.40022191 0.40149266 0.40294510 0.40498799 [19] 0.40791949 0.41074150 0.41339538 0.41552711 0.41772616 0.41984601 [25] 0.42236732 0.42476739 0.42735972 0.42972334 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 129.2378 129.0803 128.9410 128.8534 128.7146 128.7750 128.6631 128.6447 [9] 128.5476 128.4796 128.4939 128.4843 128.4960 128.5542 128.5275 128.5358 [17] 128.4980 128.4736 128.4323 128.4649 128.4167 128.4288 128.3789 128.4088 [25] 128.3610 128.4044 128.3711 128.4130 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 129.5019 129.4716 129.5292 129.6335 129.6573 129.8239 129.7980 129.8508 [9] 129.8330 129.8407 129.9343 129.9927 130.0328 130.1123 130.0964 130.1096 [17] 130.0775 130.0611 130.0313 130.0750 130.0372 130.0577 130.0164 130.0546 [25] 130.0167 130.0695 130.0463 130.0975 > 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] 128.6000 128.9000 129.0600 129.2300 129.2700 129.3300 129.3500 129.3100 [9] 129.4000 129.4900 129.4700 129.4600 129.4500 129.2800 129.2000 129.2500 [17] 129.1400 129.1100 129.0200 129.0800 128.9900 129.1100 129.0800 129.1900 [25] 129.2300 129.2500 129.3100 129.3300 129.3900 129.5500 129.4300 129.4500 [33] 129.3699 129.2760 129.2351 129.2435 129.1860 129.2995 129.2306 129.2477 [41] 129.1903 129.1602 129.2141 129.2385 129.2644 129.3332 129.3120 129.3227 [49] 129.2878 129.2674 129.2318 129.2700 129.2270 129.2432 129.1977 129.2317 [57] 129.1888 129.2369 129.2087 129.2552 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 33 End = 60 Frequency = 1 [1] 0.0005206493 0.0007721610 0.0011611120 0.0015396923 0.0018613770 [6] 0.0020695165 0.0022402669 0.0023806586 0.0025381002 0.0026882397 [11] 0.0028436204 0.0029774997 0.0030327744 0.0030733154 0.0030950105 [16] 0.0031045800 0.0031166533 0.0031329487 0.0031564945 0.0031773925 [21] 0.0031989864 0.0032150784 0.0032332331 0.0032487857 0.0032693792 [26] 0.0032867335 0.0033075145 0.0033246111 > postscript(file="/var/www/html/rcomp/tmp/19veb1260432431.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/28pla1260432431.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/30bol1260432431.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/4ja6z1260432431.tab") > > system("convert tmp/19veb1260432431.ps tmp/19veb1260432431.png") > system("convert tmp/28pla1260432431.ps tmp/28pla1260432431.png") > > > proc.time() user system elapsed 2.943 1.020 3.785