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(35.36,31.19,35.29,33.80,36.38,37.77,34.88,37.07,35.56,34.18,32.05,32.35,34.79,33.75,33.76,36.80,36.57,34.14,33.85,35.10,33.92,33.34,30.69,32.32,32.47,34.71,37.19,35.58,36.04,35.63,32.74,33.31,28.40,27.37,28.20,29.23,28.05,27.70,28.05,28.01,30.73,30.82,30.48,30.92,31.20,31.41,31.96,36.95,35.64,37.18,38.69,39.97,40.36,40.79,42.92,41.21,44.15,44.70,47.42,45.14,46.08,50.59,48.63,47.46,47.30,49.02,51.77,54.15,56.10,52.58,52.56,51.27,57.72,53.46,55.48,59.33,57.32,56.44,58.80,55.64,53.62,54.87,56.15,55.35,52.38,51.27,53.95,56.09,56.34,60.65,58.35,57.18,58.87,66.20,62.25,62.62,54.73,56.20,52.54,63.06,63.53,60.95,53.83,51.20,44.57,44.15,44.04,42.28,38.42,35.41,37.01,39.19,46.50,44.79,47.01,49.15,50.85,54.09,55.40,56.16,54.37,52.34,56.13,51.29,42.95,28.88,38.47,34.83,41.17,40.80,40.00,44.00) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '0' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '1' > par1 = '10' > #'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 ar2 ar3 sar1 sma1 -0.0504 0.0884 -0.1995 -0.6499 0.6050 s.e. 0.0904 0.0905 0.0976 0.6798 0.7038 sigma^2 estimated as 7.312: log likelihood = -292.16, aic = 596.33 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 123 End = 132 Frequency = 1 [1] 51.98427 52.36937 52.43397 52.38678 52.13853 51.86029 51.54496 51.29511 [9] 51.33727 51.22954 $se Time Series: Start = 123 End = 132 Frequency = 1 [1] 2.704062 3.728976 4.671409 5.184940 5.683243 6.103025 6.539420 6.938111 [9] 7.325651 7.684813 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 123 End = 132 Frequency = 1 [1] 46.68431 45.06058 43.27801 42.22430 40.99938 39.89836 38.72769 37.69641 [9] 36.97899 36.16730 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 123 End = 132 Frequency = 1 [1] 57.28423 59.67816 61.58993 62.54926 63.27769 63.82221 64.36222 64.89380 [9] 65.69554 66.29177 > 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] 35.36000 31.19000 35.29000 33.80000 36.38000 37.77000 34.88000 37.07000 [9] 35.56000 34.18000 32.05000 32.35000 34.79000 33.75000 33.76000 36.80000 [17] 36.57000 34.14000 33.85000 35.10000 33.92000 33.34000 30.69000 32.32000 [25] 32.47000 34.71000 37.19000 35.58000 36.04000 35.63000 32.74000 33.31000 [33] 28.40000 27.37000 28.20000 29.23000 28.05000 27.70000 28.05000 28.01000 [41] 30.73000 30.82000 30.48000 30.92000 31.20000 31.41000 31.96000 36.95000 [49] 35.64000 37.18000 38.69000 39.97000 40.36000 40.79000 42.92000 41.21000 [57] 44.15000 44.70000 47.42000 45.14000 46.08000 50.59000 48.63000 47.46000 [65] 47.30000 49.02000 51.77000 54.15000 56.10000 52.58000 52.56000 51.27000 [73] 57.72000 53.46000 55.48000 59.33000 57.32000 56.44000 58.80000 55.64000 [81] 53.62000 54.87000 56.15000 55.35000 52.38000 51.27000 53.95000 56.09000 [89] 56.34000 60.65000 58.35000 57.18000 58.87000 66.20000 62.25000 62.62000 [97] 54.73000 56.20000 52.54000 63.06000 63.53000 60.95000 53.83000 51.20000 [105] 44.57000 44.15000 44.04000 42.28000 38.42000 35.41000 37.01000 39.19000 [113] 46.50000 44.79000 47.01000 49.15000 50.85000 54.09000 55.40000 56.16000 [121] 54.37000 52.34000 51.98427 52.36937 52.43397 52.38678 52.13853 51.86029 [129] 51.54496 51.29511 51.33727 51.22954 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 123 End = 132 Frequency = 1 [1] 0.05201694 0.07120528 0.08909128 0.09897422 0.10900273 0.11768205 [7] 0.12686828 0.13525872 0.14269655 0.15000746 > postscript(file="/var/www/html/rcomp/tmp/1f9a41293457757.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/html/rcomp/tmp/2t1qd1293457757.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/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/3ik5p1293457757.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/43k4v1293457757.tab") > > try(system("convert tmp/1f9a41293457757.ps tmp/1f9a41293457757.png",intern=TRUE)) character(0) > try(system("convert tmp/2t1qd1293457757.ps tmp/2t1qd1293457757.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.971 0.333 2.174