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(27.951,29.781,32.914,33.488,35.652,36.488,35.387,35.676,34.844,32.447,31.068,29.010,29.812,30.951,32.974,32.936,34.012,32.946,31.948,30.599,27.691,25.073,23.406,22.248,22.896,25.317,26.558,26.471,27.543,26.198,24.725,25.005,23.462,20.780,19.815,19.761,21.454,23.899,24.939,23.580,24.562,24.696,23.785,23.812,21.917,19.713,19.282,18.788,21.453,24.482,27.474,27.264,27.349,30.632,29.429,30.084,26.290,24.379,23.335,21.346,21.106,24.514,28.353,30.805,31.348,34.556,33.855,34.787,32.529,29.998,29.257,28.155,30.466,35.704,39.327,39.351,42.234,43.630,43.722,43.121,37.985,37.135,34.646,33.026,35.087,38.846,42.013,43.908,42.868,44.423,44.167,43.636,44.382,42.142,43.452,36.912,42.413,45.344,44.873,47.510,49.554,47.369,45.998,48.140,48.441,44.928,40.454,38.661,37.246,36.843,36.424,37.594,38.144,38.737,34.560,36.080,33.508,35.462,33.374,32.110,35.533,35.532,37.903,36.763,40.399,44.164,44.496,43.110,43.880,43.930,44.327) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '0' > par6 = '0' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '12' > #'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: sma1 -0.9204 s.e. 0.3380 sigma^2 estimated as 2.543: log likelihood = -209.83, aic = 423.67 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 120 End = 131 Frequency = 1 [1] 31.43532 33.00268 35.56862 37.51692 38.29399 39.31588 39.95037 38.69012 [9] 39.08010 37.12072 35.29532 33.85370 $se Time Series: Start = 120 End = 131 Frequency = 1 [1] 1.629608 2.304614 2.818793 3.252683 3.635147 3.981035 4.299185 4.595360 [9] 4.873570 5.136734 5.387057 5.626253 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 120 End = 131 Frequency = 1 [1] 28.24129 28.48563 30.04379 31.14167 31.16910 31.51305 31.52397 29.68321 [9] 29.52791 27.05272 24.73669 22.82624 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 120 End = 131 Frequency = 1 [1] 34.62935 37.51972 41.09346 43.89218 45.41887 47.11871 48.37678 47.69703 [9] 48.63230 47.18871 45.85395 44.88115 > 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] 27.95100 29.78100 32.91400 33.48800 35.65200 36.48800 35.38700 35.67600 [9] 34.84400 32.44700 31.06800 29.01000 29.81200 30.95100 32.97400 32.93600 [17] 34.01200 32.94600 31.94800 30.59900 27.69100 25.07300 23.40600 22.24800 [25] 22.89600 25.31700 26.55800 26.47100 27.54300 26.19800 24.72500 25.00500 [33] 23.46200 20.78000 19.81500 19.76100 21.45400 23.89900 24.93900 23.58000 [41] 24.56200 24.69600 23.78500 23.81200 21.91700 19.71300 19.28200 18.78800 [49] 21.45300 24.48200 27.47400 27.26400 27.34900 30.63200 29.42900 30.08400 [57] 26.29000 24.37900 23.33500 21.34600 21.10600 24.51400 28.35300 30.80500 [65] 31.34800 34.55600 33.85500 34.78700 32.52900 29.99800 29.25700 28.15500 [73] 30.46600 35.70400 39.32700 39.35100 42.23400 43.63000 43.72200 43.12100 [81] 37.98500 37.13500 34.64600 33.02600 35.08700 38.84600 42.01300 43.90800 [89] 42.86800 44.42300 44.16700 43.63600 44.38200 42.14200 43.45200 36.91200 [97] 42.41300 45.34400 44.87300 47.51000 49.55400 47.36900 45.99800 48.14000 [105] 48.44100 44.92800 40.45400 38.66100 37.24600 36.84300 36.42400 37.59400 [113] 38.14400 38.73700 34.56000 36.08000 33.50800 35.46200 33.37400 31.43532 [121] 33.00268 35.56862 37.51692 38.29399 39.31588 39.95037 38.69012 39.08010 [129] 37.12072 35.29532 33.85370 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 120 End = 131 Frequency = 1 [1] 0.05184005 0.06983113 0.07924943 0.08669908 0.09492736 0.10125769 [7] 0.10761313 0.11877348 0.12470719 0.13837916 0.15262807 0.16619317 > postscript(file="/var/www/html/rcomp/tmp/1d4za1292596015.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/22ne41292596015.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/396tg1292596015.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/4cp931292596015.tab") > > try(system("convert tmp/1d4za1292596015.ps tmp/1d4za1292596015.png",intern=TRUE)) character(0) > try(system("convert tmp/22ne41292596015.ps tmp/22ne41292596015.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.641 0.334 1.495