R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-pc-linux-gnu (32-bit) 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(25.22,27.63,27.47,22.54,27.4,29.68,28.51,29.89,32.62,30.93,32.52,25.28,25.64,27.41,24.4,25.55,28.45,27.72,24.54,25.67,25.54,20.48,18.94,18.6,19.49,20.29,23.69,25.65,25.43,24.13,25.77,26.63,28.34,27.55,24.5,28.52,31.29,32.65,30.34,25.02,25.81,27.55,28.4,29.83,27.1,29.59,28.77,29.88,31.18,30.87,33.8,33.36,37.92,35.19,38.37,43.03,43.38,49.77,43.05,39.65,44.28,45.56,53.08,51.86,48.67,54.31,57.58,64.09,62.98,58.52,55.54,56.75,63.57,59.92,62.25,70.44,70.19,68.86,73.9,73.61,62.77,58.38,58.48,62.31,54.3,57.76,62.14,67.4,67.48,71.32,77.2,70.8,77.13,83.04,92.53,91.45,91.92,94.82,103.28,110.44,123.94,133.05,133.9,113.85,99.06,72.84,53.24,41.58,44.86,43.24,46.84,50.85,57.94,68.59,64.92,72.5,67.69,73.19,77.04,74.67) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '-0.5' > par1 = '12' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: Wessa P., (2009), ARIMA Forecasting (v1.0.5) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_arimaforecasting.wasp/ > #Source of accompanying publication: > #Technical description: > par1 <- as.numeric(par1) #cut off periods > 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 > par7 <- as.numeric(par7) #q > 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 ma1 -0.7828 0.9345 s.e. 0.1362 0.0990 sigma^2 estimated as 0.0001073: log likelihood = 299.14, aic = -592.27 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.1568438 0.1536467 0.1505953 0.1463780 0.1418088 0.1380822 0.1382738 [8] 0.1452092 0.1522486 0.1687208 0.1887772 0.2066700 $se Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.01036034 0.01580209 0.01908486 0.02236730 0.02488660 0.02741558 [7] 0.02955459 0.03167724 0.03357152 0.03543477 0.03715232 0.03883321 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.13653757 0.12267463 0.11318893 0.10253807 0.09303105 0.08434764 [7] 0.08034684 0.08312184 0.08644845 0.09926863 0.11595867 0.13055688 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.1771501 0.1846188 0.1880016 0.1902179 0.1905865 0.1918167 0.1962008 [8] 0.2072966 0.2180488 0.2381729 0.2615958 0.2827830 > 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] 25.22000 27.63000 27.47000 22.54000 27.40000 29.68000 28.51000 [8] 29.89000 32.62000 30.93000 32.52000 25.28000 25.64000 27.41000 [15] 24.40000 25.55000 28.45000 27.72000 24.54000 25.67000 25.54000 [22] 20.48000 18.94000 18.60000 19.49000 20.29000 23.69000 25.65000 [29] 25.43000 24.13000 25.77000 26.63000 28.34000 27.55000 24.50000 [36] 28.52000 31.29000 32.65000 30.34000 25.02000 25.81000 27.55000 [43] 28.40000 29.83000 27.10000 29.59000 28.77000 29.88000 31.18000 [50] 30.87000 33.80000 33.36000 37.92000 35.19000 38.37000 43.03000 [57] 43.38000 49.77000 43.05000 39.65000 44.28000 45.56000 53.08000 [64] 51.86000 48.67000 54.31000 57.58000 64.09000 62.98000 58.52000 [71] 55.54000 56.75000 63.57000 59.92000 62.25000 70.44000 70.19000 [78] 68.86000 73.90000 73.61000 62.77000 58.38000 58.48000 62.31000 [85] 54.30000 57.76000 62.14000 67.40000 67.48000 71.32000 77.20000 [92] 70.80000 77.13000 83.04000 92.53000 91.45000 91.92000 94.82000 [99] 103.28000 110.44000 123.94000 133.05000 133.90000 113.85000 99.06000 [106] 72.84000 53.24000 41.58000 40.65042 42.35975 44.09379 46.67115 [113] 49.72717 52.44750 52.30220 47.42546 43.14130 35.12876 28.06085 [120] 23.41236 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.1630431 0.2901478 0.3929432 0.5295369 0.6752761 0.8571258 1.0008720 [8] 1.0468441 1.0722691 0.9636586 0.8419827 0.7682912 > postscript(file="/var/www/rcomp/tmp/15jhs1293302105.ps",horizontal=F,onefile=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/rcomp/tmp/2jtei1293302105.ps",horizontal=F,onefile=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/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/rcomp/tmp/3j3tx1293302105.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/rcomp/tmp/4xdq61293302105.tab") > > try(system("convert tmp/15jhs1293302105.ps tmp/15jhs1293302105.png",intern=TRUE)) character(0) > try(system("convert tmp/2jtei1293302105.ps tmp/2jtei1293302105.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.770 0.200 0.958