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(117.09,116.77,119.39,122.49,124.08,118.29,112.94,113.79,114.43,118.70,120.36,118.27,118.34,117.82,117.65,118.18,121.02,124.78,131.16,130.14,131.75,134.73,135.35,140.32,136.35,131.60,128.90,133.89,138.25,146.23,144.76,149.30,156.80,159.08,165.12,163.14,153.43,151.01,154.72,154.58,155.63,161.67,163.51,162.91,164.80,164.98,154.54,148.60,149.19,150.61) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > par6 = '0' > 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 -0.3088 -0.4957 -0.5420 0.8123 0.9333 0.8873 s.e. 0.3900 0.2691 0.3656 0.3702 0.2873 0.3795 sigma^2 estimated as 5.203: log likelihood = -48.9, aic = 111.81 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 23 End = 50 Frequency = 1 [1] 136.1297 138.4780 137.4139 135.8198 135.5665 137.0117 137.5551 136.8082 [9] 135.9862 136.3156 137.0262 137.0891 136.5389 136.2924 136.6072 136.9304 [17] 136.8082 136.5151 136.4910 136.7099 136.8131 136.6858 136.5553 136.6028 [25] 136.7218 136.7323 136.6443 136.6018 $se Time Series: Start = 23 End = 50 Frequency = 1 [1] 2.365847 4.276607 5.900484 7.116934 7.766500 8.380566 9.126648 [8] 9.934297 10.558184 11.055362 11.558947 12.130937 12.682663 13.154057 [15] 13.581240 14.026828 14.490583 14.929429 15.328113 15.714163 16.109794 [22] 16.505459 16.881235 17.237986 17.590981 17.946518 18.296172 18.632613 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 23 End = 50 Frequency = 1 [1] 131.4926 130.0959 125.8490 121.8706 120.3442 120.5858 119.6669 117.3370 [9] 115.2921 114.6471 114.3707 113.3125 111.6809 110.5105 109.9879 109.4378 [17] 108.4066 107.2534 106.4479 105.9102 105.2380 104.3351 103.4681 102.8163 [25] 102.2435 101.5571 100.7838 100.0818 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 23 End = 50 Frequency = 1 [1] 140.7667 146.8602 148.9789 149.7690 150.7889 153.4376 155.4433 156.2795 [9] 156.6802 157.9842 159.6818 160.8657 161.3969 162.0744 163.2264 164.4230 [17] 165.2097 165.7768 166.5341 167.5097 168.3883 169.0365 169.6425 170.3892 [25] 171.2001 171.9075 172.5048 173.1217 > 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] 117.0900 116.7700 119.3900 122.4900 124.0800 118.2900 112.9400 113.7900 [9] 114.4300 118.7000 120.3600 118.2700 118.3400 117.8200 117.6500 118.1800 [17] 121.0200 124.7800 131.1600 130.1400 131.7500 134.7300 136.1297 138.4780 [25] 137.4139 135.8198 135.5665 137.0117 137.5551 136.8082 135.9862 136.3156 [33] 137.0262 137.0891 136.5389 136.2924 136.6072 136.9304 136.8082 136.5151 [41] 136.4910 136.7099 136.8131 136.6858 136.5553 136.6028 136.7218 136.7323 [49] 136.6443 136.6018 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 23 End = 50 Frequency = 1 [1] 0.01737936 0.03088292 0.04293949 0.05239984 0.05728921 0.06116679 [7] 0.06634904 0.07261475 0.07764160 0.08110119 0.08435574 0.08848943 [13] 0.09288682 0.09651347 0.09941820 0.10243765 0.10591899 0.10936100 [19] 0.11230129 0.11494529 0.11775033 0.12075472 0.12362197 0.12619061 [25] 0.12866257 0.13125297 0.13389633 0.13640097 > postscript(file="/var/www/html/rcomp/tmp/18gkv1260360651.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/24vf81260360651.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/3btt01260360651.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/4c9mb1260360651.tab") > > system("convert tmp/18gkv1260360651.ps tmp/18gkv1260360651.png") > system("convert tmp/24vf81260360651.ps tmp/24vf81260360651.png") > > > proc.time() user system elapsed 0.773 0.314 1.003