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(220206,220115,218444,214912,210705,209673,237041,242081,241878,242621,238545,240337,244752,244576,241572,240541,236089,236997,264579,270349,269645,267037,258113,262813,267413,267366,264777,258863,254844,254868,277267,285351,286602,283042,276687,277915,277128,277103,275037,270150,267140,264993,287259,291186,292300,288186,281477,282656,280190,280408,276836,275216,274352,271311,289802,290726,292300,278506,269826,265861,269034,264176,255198,253353,246057,235372,258556,260993,254663,250643,243422,247105,248541,245039,237080,237085,225554,226839,247934,248333,246969,245098,246263,255765,264319,268347,273046,273963,267430,271993,292710,295881,293299,288576) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '2' > par6 = '3' > 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 ar3 ma1 ma2 sar1 sar2 sma1 0.3043 0.3972 0.298 -0.4260 -0.3874 0.1496 -0.0411 -0.9376 s.e. 0.3774 0.3469 0.145 0.3782 0.3552 0.2055 0.2433 0.4714 sigma^2 estimated as 7124156: log likelihood = -538.31, aic = 1094.63 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 71 End = 94 Frequency = 1 [1] 240000.6 236201.5 236564.9 231619.4 223968.1 218067.5 210283.3 203239.1 [9] 223995.2 225176.0 220572.5 213632.9 202679.2 199456.3 197807.5 192749.2 [17] 184985.9 177798.0 169691.9 162917.5 182528.7 182893.3 178291.4 169936.1 $se Time Series: Start = 71 End = 94 Frequency = 1 [1] 2831.452 3763.770 4457.502 5409.551 6256.976 7127.454 8041.509 [8] 8956.746 9897.252 10859.529 11839.648 12840.367 14227.759 15544.500 [15] 16837.536 18221.837 19609.305 21022.768 22466.112 23929.310 25416.877 [22] 26927.946 28460.994 30015.223 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 71 End = 94 Frequency = 1 [1] 234450.9 228824.5 227828.2 221016.7 211704.5 204097.7 194522.0 185683.9 [9] 204596.6 203891.3 197366.8 188465.8 174792.8 168989.1 164805.9 157034.4 [17] 146551.7 136593.4 125658.3 116016.1 132711.7 130114.5 122507.9 111106.2 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 71 End = 94 Frequency = 1 [1] 245550.2 243578.5 245301.6 242222.1 236231.8 232037.3 226044.7 220794.3 [9] 243393.8 246460.6 243778.2 238800.1 230565.6 229923.6 230809.0 228464.0 [17] 223420.1 219002.7 213725.5 209819.0 232345.8 235672.1 234075.0 228765.9 > 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] 220206.0 220115.0 218444.0 214912.0 210705.0 209673.0 237041.0 242081.0 [9] 241878.0 242621.0 238545.0 240337.0 244752.0 244576.0 241572.0 240541.0 [17] 236089.0 236997.0 264579.0 270349.0 269645.0 267037.0 258113.0 262813.0 [25] 267413.0 267366.0 264777.0 258863.0 254844.0 254868.0 277267.0 285351.0 [33] 286602.0 283042.0 276687.0 277915.0 277128.0 277103.0 275037.0 270150.0 [41] 267140.0 264993.0 287259.0 291186.0 292300.0 288186.0 281477.0 282656.0 [49] 280190.0 280408.0 276836.0 275216.0 274352.0 271311.0 289802.0 290726.0 [57] 292300.0 278506.0 269826.0 265861.0 269034.0 264176.0 255198.0 253353.0 [65] 246057.0 235372.0 258556.0 260993.0 254663.0 250643.0 240000.6 236201.5 [73] 236564.9 231619.4 223968.1 218067.5 210283.3 203239.1 223995.2 225176.0 [81] 220572.5 213632.9 202679.2 199456.3 197807.5 192749.2 184985.9 177798.0 [89] 169691.9 162917.5 182528.7 182893.3 178291.4 169936.1 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 71 End = 94 Frequency = 1 [1] 0.01179769 0.01593457 0.01884262 0.02335535 0.02793690 0.03268462 [7] 0.03824131 0.04406999 0.04418511 0.04822686 0.05367691 0.06010481 [13] 0.07019843 0.07793435 0.08512084 0.09453653 0.10600432 0.11823959 [19] 0.13239355 0.14687991 0.13924863 0.14723308 0.15963185 0.17662655 > postscript(file="/var/wessaorg/rcomp/tmp/19ivy1324579215.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/2mtz61324579215.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/3d1ke1324579215.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/435831324579215.tab") > > try(system("convert tmp/19ivy1324579215.ps tmp/19ivy1324579215.png",intern=TRUE)) character(0) > try(system("convert tmp/2mtz61324579215.ps tmp/2mtz61324579215.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 6.860 1.708 8.565