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(8.2,8,7.5,6.8,6.5,6.6,7.6,8,8.1,7.7,7.5,7.6,7.8,7.8,7.8,7.5,7.5,7.1,7.5,7.5,7.6,7.7,7.7,7.9,8.1,8.2,8.2,8.2,7.9,7.3,6.9,6.6,6.7,6.9,7,7.1,7.2,7.1,6.9,7,6.8,6.4,6.7,6.6,6.4,6.3,6.2,6.5,6.8,6.8,6.4,6.1,5.8,6.1,7.2,7.3,6.9,6.1,5.8,6.2,7.1,7.7,7.9,7.7,7.4,7.5,8,8.1) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '2' > par2 = '1' > par1 = '12' > 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 0.2479 -0.261 -0.2007 -0.6235 0.3969 -0.7734 1.0000 s.e. 0.2255 0.205 0.2003 0.2360 0.1822 0.3052 0.4321 sigma^2 estimated as 0.02278: log likelihood = 7.13, aic = 1.75 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 41 End = 68 Frequency = 1 [1] 6.876668 6.847035 6.547545 6.299151 6.269013 6.266002 6.304804 6.292018 [9] 6.283156 6.142351 6.051272 6.129604 6.250813 6.383503 6.316718 6.188876 [17] 6.095663 6.067001 6.057555 6.029075 5.977906 5.922225 5.875167 5.835978 [25] 5.797394 5.755175 5.710319 5.665636 $se Time Series: Start = 41 End = 68 Frequency = 1 [1] 0.1712697 0.3287000 0.5152019 0.6332265 0.7067261 0.7632968 0.8226900 [8] 0.8894095 0.9564212 1.0178003 1.0750352 1.1306680 1.2347816 1.3692411 [15] 1.5333371 1.6739119 1.7895395 1.8935844 1.9988494 2.1072761 2.2147732 [22] 2.3180129 2.4172638 2.5144611 2.6108926 2.7065913 2.8010808 2.8941572 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 41 End = 68 Frequency = 1 [1] 6.540979408 6.202782815 5.537748981 5.058027208 4.883830080 [6] 4.769940032 4.692331782 4.548774995 4.408570735 4.147462345 [11] 3.944203415 3.913494889 3.830641440 3.699790575 3.311377129 [16] 2.908008942 2.588165704 2.355575309 2.139809848 1.898813317 [21] 1.636950502 1.378919610 1.137329822 0.907633864 0.680044178 [26] 0.450256452 0.220201027 -0.006911806 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 41 End = 68 Frequency = 1 [1] 7.212357 7.491287 7.557340 7.540275 7.654197 7.762063 7.917276 [8] 8.035260 8.157742 8.137240 8.158341 8.345713 8.670985 9.067216 [15] 9.322058 9.469743 9.603160 9.778426 9.975300 10.159336 10.318861 [22] 10.465530 10.613004 10.764321 10.914743 11.060095 11.200438 11.338184 > 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] 8.200000 8.000000 7.500000 6.800000 6.500000 6.600000 7.600000 8.000000 [9] 8.100000 7.700000 7.500000 7.600000 7.800000 7.800000 7.800000 7.500000 [17] 7.500000 7.100000 7.500000 7.500000 7.600000 7.700000 7.700000 7.900000 [25] 8.100000 8.200000 8.200000 8.200000 7.900000 7.300000 6.900000 6.600000 [33] 6.700000 6.900000 7.000000 7.100000 7.200000 7.100000 6.900000 7.000000 [41] 6.876668 6.847035 6.547545 6.299151 6.269013 6.266002 6.304804 6.292018 [49] 6.283156 6.142351 6.051272 6.129604 6.250813 6.383503 6.316718 6.188876 [57] 6.095663 6.067001 6.057555 6.029075 5.977906 5.922225 5.875167 5.835978 [65] 5.797394 5.755175 5.710319 5.665636 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 41 End = 68 Frequency = 1 [1] 0.02490592 0.04800618 0.07868628 0.10052569 0.11273323 0.12181560 [7] 0.13048621 0.14135521 0.15221986 0.16570208 0.17765440 0.18446020 [13] 0.19753935 0.21449682 0.24274269 0.27047105 0.29357585 0.31211211 [19] 0.32997629 0.34951900 0.37049315 0.39140913 0.41143747 0.43085516 [25] 0.45035627 0.47028824 0.49052962 0.51082651 > postscript(file="/var/www/html/rcomp/tmp/1jl4b1260987696.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/2smtr1260987696.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/3aadg1260987696.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/42ea61260987696.tab") > > try(system("convert tmp/1jl4b1260987696.ps tmp/1jl4b1260987696.png",intern=TRUE)) character(0) > try(system("convert tmp/2smtr1260987696.ps tmp/2smtr1260987696.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.068 0.352 2.038