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(2.83,2.72,2.73,2.72,2.77,2.61,2.47,2.30,2.38,2.43,2.39,2.60,2.84,2.87,2.92,2.08,3.33,3.48,3.57,3.66,3.77,3.75,3.75,3.81,3.82,3.89,4.05,4.10,4.07,4.26,4.40,4.61,4.63,4.48,4.46,4.45,4.32,4.52,4.21,3.97,4.12,4.50,4.73,5.26,4.52,4.94,4.95,3.52,3.85,2.41,2.95,2.68,2.53,2.44,2.16,2.20,2.10,2.29,2.03,2.05,2.07) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '2' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '2' > par2 = '1' > par1 = '13' > 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.0682 -0.1506 -0.1276 -1.2192 0.4047 -0.0624 s.e. 1.7331 0.6688 0.2926 1.7364 2.2021 0.8117 sigma^2 estimated as 0.07504: log likelihood = -5.08, aic = 24.16 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 34 End = 61 Frequency = 1 [1] 4.720195 4.814434 4.922198 5.019478 5.114919 5.210340 5.307376 5.404539 [9] 5.501454 5.598160 5.694901 5.791704 5.888523 5.985328 6.082123 6.178919 [17] 6.275718 6.372518 6.469317 6.566116 6.662915 6.759714 6.856513 6.953312 [25] 7.050111 7.146910 7.243709 7.340509 $se Time Series: Start = 34 End = 61 Frequency = 1 [1] 0.2739317 0.3363678 0.3966015 0.4533956 0.5229303 0.5970505 0.6739179 [8] 0.7526934 0.8344359 0.9192450 1.0069277 1.0972366 1.1900904 1.2854495 [15] 1.3832640 1.4834669 1.5859956 1.6907965 1.7978219 1.9070265 2.0183667 [22] 2.1318017 2.2472929 2.3648040 2.4843006 2.6057499 2.7291208 2.8543836 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 34 End = 61 Frequency = 1 [1] 4.183289 4.155153 4.144859 4.130822 4.089976 4.040121 3.986497 3.929260 [9] 3.865959 3.796440 3.721323 3.641120 3.555946 3.465846 3.370925 3.271324 [17] 3.167166 3.058557 2.945586 2.828344 2.706916 2.581383 2.451819 2.318296 [25] 2.180882 2.039641 1.894633 1.745917 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 34 End = 61 Frequency = 1 [1] 5.257101 5.473715 5.699537 5.908133 6.139862 6.380559 6.628255 [8] 6.879818 7.136948 7.399880 7.668480 7.942287 8.221100 8.504809 [15] 8.793320 9.086514 9.384269 9.686479 9.993048 10.303888 10.618914 [22] 10.938045 11.261207 11.588328 11.919341 12.254180 12.592786 12.935100 > 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] 2.830000 2.720000 2.730000 2.720000 2.770000 2.610000 2.470000 2.300000 [9] 2.380000 2.430000 2.390000 2.600000 2.840000 2.870000 2.920000 2.080000 [17] 3.330000 3.480000 3.570000 3.660000 3.770000 3.750000 3.750000 3.810000 [25] 3.820000 3.890000 4.050000 4.100000 4.070000 4.260000 4.400000 4.610000 [33] 4.630000 4.720195 4.814434 4.922198 5.019478 5.114919 5.210340 5.307376 [41] 5.404539 5.501454 5.598160 5.694901 5.791704 5.888523 5.985328 6.082123 [49] 6.178919 6.275718 6.372518 6.469317 6.566116 6.662915 6.759714 6.856513 [57] 6.953312 7.050111 7.146910 7.243709 7.340509 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 34 End = 61 Frequency = 1 [1] 0.05803397 0.06986652 0.08057406 0.09032724 0.10223628 0.11458956 [7] 0.12697762 0.13927058 0.15167552 0.16420486 0.17681213 0.18944972 [13] 0.20210338 0.21476678 0.22743112 0.24008519 0.25271939 0.26532629 [19] 0.27789979 0.29043447 0.30292548 0.31536862 0.32776031 0.34009749 [25] 0.35237750 0.36459810 0.37675736 0.38885366 > postscript(file="/var/www/html/rcomp/tmp/1ie091260450508.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/2me621260450508.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/3jy9u1260450508.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/4ofdm1260450508.tab") > > system("convert tmp/1ie091260450508.ps tmp/1ie091260450508.png") > system("convert tmp/2me621260450508.ps tmp/2me621260450508.png") > > > proc.time() user system elapsed 0.809 0.339 0.946