R version 2.13.0 (2011-04-13) Copyright (C) 2011 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(26.663 + ,23.598 + ,26.931 + ,24.740 + ,25.806 + ,24.364 + ,24.477 + ,23.901 + ,23.175 + ,23.227 + ,21.672 + ,21.870 + ,21.439 + ,21.089 + ,23.709 + ,21.669 + ,21.752 + ,20.761 + ,23.479 + ,23.824 + ,23.105 + ,23.110 + ,21.759 + ,22.073 + ,21.937 + ,20.035 + ,23.590 + ,21.672 + ,22.222 + ,22.123 + ,23.950 + ,23.504 + ,22.238 + ,23.142 + ,21.059 + ,21.573 + ,21.548 + ,20.000 + ,22.424 + ,20.615 + ,21.761 + ,22.874 + ,24.104 + ,23.748 + ,23.262 + ,22.907 + ,21.519 + ,22.025 + ,22.604 + ,20.894 + ,24.677 + ,23.673 + ,25.320 + ,23.583 + ,24.671 + ,24.454 + ,24.122 + ,24.252 + ,22.084 + ,22.991 + ,23.287 + ,23.049 + ,25.076 + ,24.037 + ,24.430 + ,24.667 + ,26.451 + ,25.618 + ,25.014 + ,25.110 + ,22.964 + ,23.981 + ,23.798 + ,22.270 + ,24.775 + ,22.646 + ,23.988 + ,24.737 + ,26.276 + ,25.816 + ,25.210 + ,25.199 + ,23.162 + ,24.707 + ,24.364 + ,22.644 + ,25.565 + ,24.062 + ,25.431 + ,24.635 + ,27.009 + ,26.606 + ,26.268 + ,26.462 + ,25.246 + ,25.180 + ,24.657 + ,23.304 + ,26.982 + ,26.199 + ,27.210 + ,26.122 + ,26.706 + ,26.878 + ,26.152 + ,26.379 + ,24.712 + ,25.688 + ,24.990 + ,24.239 + ,26.721 + ,23.475 + ,24.767 + ,26.219 + ,28.361 + ,28.599 + ,27.914 + ,27.784 + ,25.693 + ,26.881 + ,26.217 + ,24.218 + ,27.914 + ,26.975 + ,28.527 + ,27.139 + ,28.982 + ,28.169 + ,28.056 + ,29.136 + ,26.291 + ,26.987 + ,26.589 + ,24.848 + ,27.543 + ,26.896 + ,28.878 + ,27.390 + ,28.065 + ,28.141 + ,29.048 + ,28.484 + ,26.634 + ,27.735 + ,27.132 + ,24.924 + ,28.963 + ,26.589 + ,27.931 + ,28.009 + ,29.229 + ,28.759 + ,28.405 + ,27.945 + ,25.912 + ,26.619 + ,26.076 + ,25.286 + ,27.660 + ,25.951 + ,26.398 + ,25.565 + ,28.865 + ,30.000 + ,29.261 + ,29.012 + ,26.992 + ,27.897) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '0' > par6 = '2' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '24' > #'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 sar1 sar2 sma1 -0.0488 -0.1878 -0.4801 -0.3275 -0.6203 s.e. 0.0882 0.0902 0.1352 0.1219 0.1438 sigma^2 estimated as 0.3922: log likelihood = -133.97, aic = 279.95 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 145 End = 168 Frequency = 1 [1] 27.31907 26.08944 29.05103 26.99032 28.11828 28.34596 30.12523 30.00413 [9] 29.27207 29.47441 27.54754 28.43664 27.92202 26.39692 29.56049 28.07623 [17] 29.47327 28.91131 30.54296 30.22508 29.94582 30.31876 28.10290 28.96107 $se Time Series: Start = 145 End = 168 Frequency = 1 [1] 0.6263024 0.8643953 0.9885528 1.1037914 1.2168779 1.3190848 1.4125465 [8] 1.5004609 1.5837199 1.6627601 1.7381751 1.8104633 1.8640325 1.9168104 [15] 1.9708501 2.0231887 2.0737382 2.1231527 2.1715238 2.2188245 2.2651239 [22] 2.3104992 2.3550027 2.3986804 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 145 End = 168 Frequency = 1 [1] 26.09152 24.39522 27.11347 24.82689 25.73320 25.76055 27.35663 27.06322 [9] 26.16798 26.21540 24.14071 24.88813 24.26852 22.63997 25.69763 24.11078 [17] 25.40874 24.74993 26.28677 25.87618 25.50617 25.79018 23.48709 24.25966 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 145 End = 168 Frequency = 1 [1] 28.54663 27.78365 30.98860 29.15375 30.50336 30.93136 32.89382 32.94503 [9] 32.37616 32.73342 30.95436 31.98515 31.57553 30.15387 33.42336 32.04168 [17] 33.53780 33.07269 34.79915 34.57398 34.38546 34.84734 32.71870 33.66248 > 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] 26.66300 23.59800 26.93100 24.74000 25.80600 24.36400 24.47700 23.90100 [9] 23.17500 23.22700 21.67200 21.87000 21.43900 21.08900 23.70900 21.66900 [17] 21.75200 20.76100 23.47900 23.82400 23.10500 23.11000 21.75900 22.07300 [25] 21.93700 20.03500 23.59000 21.67200 22.22200 22.12300 23.95000 23.50400 [33] 22.23800 23.14200 21.05900 21.57300 21.54800 20.00000 22.42400 20.61500 [41] 21.76100 22.87400 24.10400 23.74800 23.26200 22.90700 21.51900 22.02500 [49] 22.60400 20.89400 24.67700 23.67300 25.32000 23.58300 24.67100 24.45400 [57] 24.12200 24.25200 22.08400 22.99100 23.28700 23.04900 25.07600 24.03700 [65] 24.43000 24.66700 26.45100 25.61800 25.01400 25.11000 22.96400 23.98100 [73] 23.79800 22.27000 24.77500 22.64600 23.98800 24.73700 26.27600 25.81600 [81] 25.21000 25.19900 23.16200 24.70700 24.36400 22.64400 25.56500 24.06200 [89] 25.43100 24.63500 27.00900 26.60600 26.26800 26.46200 25.24600 25.18000 [97] 24.65700 23.30400 26.98200 26.19900 27.21000 26.12200 26.70600 26.87800 [105] 26.15200 26.37900 24.71200 25.68800 24.99000 24.23900 26.72100 23.47500 [113] 24.76700 26.21900 28.36100 28.59900 27.91400 27.78400 25.69300 26.88100 [121] 26.21700 24.21800 27.91400 26.97500 28.52700 27.13900 28.98200 28.16900 [129] 28.05600 29.13600 26.29100 26.98700 26.58900 24.84800 27.54300 26.89600 [137] 28.87800 27.39000 28.06500 28.14100 29.04800 28.48400 26.63400 27.73500 [145] 27.31907 26.08944 29.05103 26.99032 28.11828 28.34596 30.12523 30.00413 [153] 29.27207 29.47441 27.54754 28.43664 27.92202 26.39692 29.56049 28.07623 [161] 29.47327 28.91131 30.54296 30.22508 29.94582 30.31876 28.10290 28.96107 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 145 End = 168 Frequency = 1 [1] 0.02292546 0.03313200 0.03402815 0.04089582 0.04327711 0.04653520 [7] 0.04688916 0.05000848 0.05410344 0.05641369 0.06309730 0.06366656 [13] 0.06675851 0.07261493 0.06667176 0.07206056 0.07035996 0.07343676 [19] 0.07109736 0.07341005 0.07564074 0.07620692 0.08379929 0.08282430 > postscript(file="/var/wessaorg/rcomp/tmp/1b8n61322841665.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/wessaorg/rcomp/tmp/2eizp1322841665.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/3noyl1322841665.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/wessaorg/rcomp/tmp/4vcl51322841665.tab") > > try(system("convert tmp/1b8n61322841665.ps tmp/1b8n61322841665.png",intern=TRUE)) character(0) > try(system("convert tmp/2eizp1322841665.ps tmp/2eizp1322841665.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.985 0.308 2.287