R version 2.8.0 (2008-10-20) Copyright (C) 2008 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(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) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > par6 = '0' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '1' > par1 = '50' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > #Technical description: Write here your technical program description (don't use hard returns!) > 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") sigma^2 estimated as 25327047: log likelihood = -39.77, aic = 81.54 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 17 End = 66 Frequency = 1 [1] 22397 23843 21705 18089 20764 25316 17704 15548 28029 29383 36438 32034 [13] 22397 23843 21705 18089 20764 25316 17704 15548 28029 29383 36438 32034 [25] 22397 23843 21705 18089 20764 25316 17704 15548 28029 29383 36438 32034 [37] 22397 23843 21705 18089 20764 25316 17704 15548 28029 29383 36438 32034 [49] 22397 23843 $se Time Series: Start = 17 End = 66 Frequency = 1 [1] 5032.598 5032.598 5032.598 5032.598 5032.598 5032.598 5032.598 [8] 5032.598 5032.598 5032.598 5032.598 5032.598 7117.169 7117.169 [15] 7117.169 7117.169 7117.169 7117.169 7117.169 7117.169 7117.169 [22] 7117.169 7117.169 7117.169 8716.716 8716.716 8716.716 8716.716 [29] 8716.716 8716.716 8716.716 8716.716 8716.716 8716.716 8716.716 [36] 8716.716 10065.197 10065.197 10065.197 10065.197 10065.197 10065.197 [43] 10065.197 10065.197 10065.197 10065.197 10065.197 10065.197 11253.232 [50] 11253.232 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 17 End = 66 Frequency = 1 [1] 12533.1072 13979.1072 11841.1072 8225.1072 10900.1072 15452.1072 [7] 7840.1072 5684.1072 18165.1072 19519.1072 26574.1072 22170.1072 [13] 8447.3490 9893.3490 7755.3490 4139.3490 6814.3490 11366.3490 [19] 3754.3490 1598.3490 14079.3490 15433.3490 22488.3490 18084.3490 [25] 5312.2365 6758.2365 4620.2365 1004.2365 3679.2365 8231.2365 [31] 619.2365 -1536.7635 10944.2365 12298.2365 19353.2365 14949.2365 [37] 2669.2143 4115.2143 1977.2143 -1638.7857 1036.2143 5588.2143 [43] -2023.7857 -4179.7857 8301.2143 9655.2143 16710.2143 12306.2143 [49] 340.6651 1786.6651 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 17 End = 66 Frequency = 1 [1] 32260.89 33706.89 31568.89 27952.89 30627.89 35179.89 27567.89 25411.89 [9] 37892.89 39246.89 46301.89 41897.89 36346.65 37792.65 35654.65 32038.65 [17] 34713.65 39265.65 31653.65 29497.65 41978.65 43332.65 50387.65 45983.65 [25] 39481.76 40927.76 38789.76 35173.76 37848.76 42400.76 34788.76 32632.76 [33] 45113.76 46467.76 53522.76 49118.76 42124.79 43570.79 41432.79 37816.79 [41] 40491.79 45043.79 37431.79 35275.79 47756.79 49110.79 56165.79 51761.79 [49] 44453.33 45899.33 > 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] 31514 27071 29462 26105 22397 23843 21705 18089 20764 25316 17704 15548 [13] 28029 29383 36438 32034 22397 23843 21705 18089 20764 25316 17704 15548 [25] 28029 29383 36438 32034 22397 23843 21705 18089 20764 25316 17704 15548 [37] 28029 29383 36438 32034 22397 23843 21705 18089 20764 25316 17704 15548 [49] 28029 29383 36438 32034 22397 23843 21705 18089 20764 25316 17704 15548 [61] 28029 29383 36438 32034 22397 23843 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 17 End = 66 Frequency = 1 [1] 0.2246997 0.2110724 0.2318636 0.2782132 0.2423713 0.1987912 0.2842634 [8] 0.3236814 0.1795497 0.1712759 0.1381140 0.1571018 0.3177733 0.2985014 [15] 0.3279046 0.3934529 0.3427648 0.2811332 0.4020091 0.4577546 0.2539216 [22] 0.2422206 0.1953227 0.2221755 0.3891912 0.3655881 0.4015995 0.4818794 [29] 0.4197995 0.3443165 0.4923586 0.5606326 0.3109892 0.2966585 0.2392205 [36] 0.2721083 0.4493993 0.4221447 0.4637271 0.5564264 0.4847427 0.3975824 [43] 0.5685267 0.6473628 0.3590994 0.3425517 0.2762280 0.3142036 0.5024437 [50] 0.4719722 > postscript(file="/var/www/html/rcomp/tmp/1do481229334603.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.se <- array(0, dim=fx) > perf.mse <- 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.mape[i] = perf.mape[i] + abs(perf.pe[i]) + perf.se[i] = (x[nx+i] - forecast$pred[i])^2 + perf.mse[i] = perf.mse[i] + perf.se[i] + 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 = perf.mape / fx > perf.mse = perf.mse / fx > perf.rmse = sqrt(perf.mse) > postscript(file="/var/www/html/rcomp/tmp/2gxm21229334603.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:12] <- x[(nx+1):lx] Warning message: In NextMethod("[<-") : number of items to replace is not a multiple of replacement length > 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/34xlx1229334603.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.mape[i],4)) + a<-table.element(a,round(perf.se[i],4)) + a<-table.element(a,round(perf.mse[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/44dpv1229334603.tab") > > system("convert tmp/1do481229334603.ps tmp/1do481229334603.png") > system("convert tmp/2gxm21229334603.ps tmp/2gxm21229334603.png") > > > proc.time() user system elapsed 0.884 0.365 0.967