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(23187,14727,43080,32519,39657,33614,28671,34243,27336,22916,24537,26128,22602,15744,41086,39690,43129,37863,35953,29133,24693,22205,21725,27192,21790,13253,37702,30364,32609,30212,29965,28352,25814,22414,20506,28806,22228,13971,36845,35338,35022,34777,26887,23970,22780,17351,21382,24561,17409,11514,31514,27071,29462,26105,22397,23843,21705,18089,20764,25316,17704,15548,28029,29383,36438,32034,22679,24319,18004,17537,20366,22782,19169,13807,29743,25591,29096,26482,22405,27044,17970,18730,19684,19785,18479,10698,31956,29506,34506,27165,26736,23691,18157,17328,18205,20995,17382,9367,31124,26551,30651,25859,25100,25778,20418,18688,20424,24776,19814,12738,31566,30111,30019,31934,25826,26835,20205,17789,20520,22518,15572,11509,25447,24090,27786,26195,20516,22759,19028,16971,20036,22485,18730,14538,27561,25985,34670,32066,27186,29586,21359,21553,19573,24256,22380) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '0' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '0.0' > 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: ma1 sma1 -0.7151 -1.0000 s.e. 0.0776 0.1457 sigma^2 estimated as 0.007691: log likelihood = 95.42, aic = -184.85 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 122 End = 145 Frequency = 1 [1] 9.354338 10.315737 10.204234 10.311150 10.204130 10.064123 10.070294 [8] 9.858133 9.745558 9.824019 9.975006 9.741110 9.327110 10.288509 [15] 10.177006 10.283922 10.176902 10.036895 10.043066 9.830904 9.718330 [22] 9.796791 9.947778 9.713882 $se Time Series: Start = 122 End = 145 Frequency = 1 [1] 0.09209942 0.09575603 0.09927806 0.10267935 0.10597152 0.10916446 [7] 0.11226662 0.11528534 0.11822701 0.12109724 0.12390099 0.12671988 [13] 0.13136440 0.13441881 0.13740533 0.14032831 0.14319163 0.14599881 [19] 0.14875302 0.15145715 0.15411385 0.15672552 0.15929437 0.16198744 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 122 End = 145 Frequency = 1 [1] 9.173824 10.128055 10.009649 10.109899 9.996426 9.850160 9.850252 [8] 9.632173 9.513833 9.586668 9.732160 9.492739 9.069636 10.025048 [15] 9.907691 10.008879 9.896246 9.750737 9.751510 9.534048 9.416267 [22] 9.489609 9.635561 9.396386 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 122 End = 145 Frequency = 1 [1] 9.534853 10.503419 10.398819 10.512402 10.411834 10.278085 10.290337 [8] 10.084092 9.977283 10.061369 10.217852 9.989481 9.584584 10.551970 [15] 10.446320 10.558966 10.457557 10.323052 10.334622 10.127760 10.020393 [22] 10.103973 10.259995 10.031377 > 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] 23187.00 14727.00 43080.00 32519.00 39657.00 33614.00 28671.00 34243.00 [9] 27336.00 22916.00 24537.00 26128.00 22602.00 15744.00 41086.00 39690.00 [17] 43129.00 37863.00 35953.00 29133.00 24693.00 22205.00 21725.00 27192.00 [25] 21790.00 13253.00 37702.00 30364.00 32609.00 30212.00 29965.00 28352.00 [33] 25814.00 22414.00 20506.00 28806.00 22228.00 13971.00 36845.00 35338.00 [41] 35022.00 34777.00 26887.00 23970.00 22780.00 17351.00 21382.00 24561.00 [49] 17409.00 11514.00 31514.00 27071.00 29462.00 26105.00 22397.00 23843.00 [57] 21705.00 18089.00 20764.00 25316.00 17704.00 15548.00 28029.00 29383.00 [65] 36438.00 32034.00 22679.00 24319.00 18004.00 17537.00 20366.00 22782.00 [73] 19169.00 13807.00 29743.00 25591.00 29096.00 26482.00 22405.00 27044.00 [81] 17970.00 18730.00 19684.00 19785.00 18479.00 10698.00 31956.00 29506.00 [89] 34506.00 27165.00 26736.00 23691.00 18157.00 17328.00 18205.00 20995.00 [97] 17382.00 9367.00 31124.00 26551.00 30651.00 25859.00 25100.00 25778.00 [105] 20418.00 18688.00 20424.00 24776.00 19814.00 12738.00 31566.00 30111.00 [113] 30019.00 31934.00 25826.00 26835.00 20205.00 17789.00 20520.00 22518.00 [121] 15572.00 11548.82 30204.22 27017.34 30066.00 27014.52 23485.13 23630.52 [129] 19113.16 17078.21 18472.14 21482.76 17002.40 11238.61 29392.91 26291.63 [137] 29258.41 26288.89 22854.30 22995.78 18599.77 16619.47 17975.96 20905.71 [145] 16545.70 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 122 End = 145 Frequency = 1 [1] 0.1009357 0.1053314 0.1095953 0.1137410 0.1177801 0.1217225 0.1255764 [8] 0.1293493 0.1330474 0.1366763 0.1402409 0.1438446 0.1498258 0.1537890 [15] 0.1576871 0.1615244 0.1653049 0.1690318 0.1727084 0.1763375 0.1799218 [22] 0.1834635 0.1869649 0.1906545 > postscript(file="/var/wessaorg/rcomp/tmp/18qei1323186238.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/20cr11323186238.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/3lls91323186238.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/4lerk1323186238.tab") > > try(system("convert tmp/18qei1323186238.ps tmp/18qei1323186238.png",intern=TRUE)) character(0) > try(system("convert tmp/20cr11323186238.ps tmp/20cr11323186238.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.941 0.149 1.093