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(90604,97527,111940,100280,100009,95558,98533,92694,97920,110933,110855,111716,96348,105425,114874,104199,101166,99010,101607,97492,106088,113536,112475,115491,97733,102591,114783,100397,97772,96128,91261,90686,97792,108848,109989,109453,93945,98750,119043,104776,103262,106735,101600,99358,105240,114079,121637,111747,99496,104992,124255,108258,106940,104939,105896,107287,110783,122139,125823,120480,103296,117121,129924,118589,118062,113597,117161,112893,119657,136562,140446,138744,120324,118113,130257,125510,117986,118316,122075,117573,122566,135934,138394,137999,118780,117907,142932,132200,125666,127958,127718,124368,135241,144734,142320,141481,120471,123422,145829,134572,132156,140265,137771,134035,144016,151905,155791,148440,129862,134264,151952,143191,137242,136993,134431,132523,133486,140120,137521,112193,94256,99047,109761,102160,104792,104341,112430,113034,114197,127876,135199,123663,112578,117104,139703,114961,134222,128390,134197,135963,135936,146803,143231,131510) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '0' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '0.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: ar1 ar2 ar3 sma1 -0.1774 0.0368 0.3455 -0.6789 s.e. 0.0854 0.0880 0.0867 0.0898 sigma^2 estimated as 0.0001212: log likelihood = 363.82, aic = -717.65 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 133 End = 144 Frequency = 1 [1] 3.186151 3.202375 3.242948 3.221212 3.217440 3.218934 3.226119 3.221823 [9] 3.232890 3.260477 3.267263 3.239802 $se Time Series: Start = 133 End = 144 Frequency = 1 [1] 0.01101014 0.01425606 0.01730398 0.02188975 0.02502140 0.02807849 [7] 0.03129835 0.03397298 0.03658512 0.03912400 0.04142499 0.04366139 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 133 End = 144 Frequency = 1 [1] 3.164572 3.174433 3.209032 3.178308 3.168398 3.163901 3.164774 3.155236 [9] 3.161183 3.183794 3.186070 3.154226 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 133 End = 144 Frequency = 1 [1] 3.207731 3.230317 3.276864 3.264116 3.266482 3.273968 3.287464 3.288410 [9] 3.304596 3.337160 3.348456 3.325378 > 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] 90604.0 97527.0 111940.0 100280.0 100009.0 95558.0 98533.0 92694.0 [9] 97920.0 110933.0 110855.0 111716.0 96348.0 105425.0 114874.0 104199.0 [17] 101166.0 99010.0 101607.0 97492.0 106088.0 113536.0 112475.0 115491.0 [25] 97733.0 102591.0 114783.0 100397.0 97772.0 96128.0 91261.0 90686.0 [33] 97792.0 108848.0 109989.0 109453.0 93945.0 98750.0 119043.0 104776.0 [41] 103262.0 106735.0 101600.0 99358.0 105240.0 114079.0 121637.0 111747.0 [49] 99496.0 104992.0 124255.0 108258.0 106940.0 104939.0 105896.0 107287.0 [57] 110783.0 122139.0 125823.0 120480.0 103296.0 117121.0 129924.0 118589.0 [65] 118062.0 113597.0 117161.0 112893.0 119657.0 136562.0 140446.0 138744.0 [73] 120324.0 118113.0 130257.0 125510.0 117986.0 118316.0 122075.0 117573.0 [81] 122566.0 135934.0 138394.0 137999.0 118780.0 117907.0 142932.0 132200.0 [89] 125666.0 127958.0 127718.0 124368.0 135241.0 144734.0 142320.0 141481.0 [97] 120471.0 123422.0 145829.0 134572.0 132156.0 140265.0 137771.0 134035.0 [105] 144016.0 151905.0 155791.0 148440.0 129862.0 134264.0 151952.0 143191.0 [113] 137242.0 136993.0 134431.0 132523.0 133486.0 140120.0 137521.0 112193.0 [121] 94256.0 99047.0 109761.0 102160.0 104792.0 104341.0 112430.0 113034.0 [129] 114197.0 127876.0 135199.0 123663.0 107811.3 113428.5 128647.1 120280.0 [137] 118879.0 119432.1 122124.9 120508.3 124712.2 135772.4 138624.9 127404.5 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 133 End = 144 Frequency = 1 [1] 0.03562873 0.04630636 0.05594132 0.07217608 0.08332497 0.09425554 [7] 0.10575214 0.11581390 0.12515537 0.13352461 0.14194804 0.15196644 > postscript(file="/var/wessaorg/rcomp/tmp/1n20o1324422909.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/2c96i1324422910.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/3ytzk1324422910.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/4ybms1324422910.tab") > > try(system("convert tmp/1n20o1324422909.ps tmp/1n20o1324422909.png",intern=TRUE)) character(0) > try(system("convert tmp/2c96i1324422910.ps tmp/2c96i1324422910.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.072 0.160 1.229