R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-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(1.894,1.757,3.582,5.321,5.561,5.907,4.944,4.966,3.258,1.964,1.743,1.262,2.086,1.793,3.548,5.672,6.084,4.914,4.990,5.139,3.218,2.179,2.238,1.442,2.205,2.025,3.531,4.977,7.998,4.880,5.231,5.202,3.303,2.683,2.202,1.376,2.422,1.997,3.163,5.964,5.657,6.415,6.208,4.500,2.939,2.702,2.090,1.504,2.549,1.931,3.013,6.204,5.788,5.611,5.594,4.647,3.490,2.487,1.992,1.507,2.306,2.002,3.075,5.331,5.589,5.813,4.876,4.665,3.601,2.192,2.111,1.580,2.288,1.993,3.228,5.000,5.480,5.770,4.962,4.685,3.607,2.222,2.467,1.594,2.228,1.910,3.157,4.809,6.249,4.607,4.975,4.784,3.028,2.461,2.218,1.351,2.070,1.887,3.024,4.596,6.398,4.459,5.382,4.359,2.687,2.249,2.154,1.169,2.429,1.762,2.846,5.627,5.749,4.502,5.720,4.403,2.867,2.635,2.059,1.511,2.359,1.741,2.917,6.249,5.760,6.250,5.134,4.831,3.695,2.462,2.146,1.579) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '1' > par1 = '12' > par10 <- 'FALSE' > par9 <- '1' > par8 <- '2' > par7 <- '1' > par6 <- '3' > par5 <- '12' > par4 <- '1' > par3 <- '0' > 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: ar1 ar2 ar3 ma1 sar1 sar2 sma1 0.4762 0.1817 0.2613 -0.8344 0.3247 -0.1124 -0.8273 s.e. 0.1319 0.1039 0.0990 0.0953 0.1866 0.1344 0.2508 sigma^2 estimated as 0.1415: log likelihood = -52.48, aic = 120.96 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 121 End = 132 Frequency = 1 [1] 2.264589 1.818624 3.069263 5.481247 5.848915 4.993176 5.441452 4.593901 [9] 3.092188 2.489490 2.095448 1.487718 $se Time Series: Start = 121 End = 132 Frequency = 1 [1] 0.3774649 0.4009319 0.4009509 0.4080668 0.4080697 0.4083669 0.4092917 [8] 0.4096173 0.4099629 0.4103493 0.4106614 0.4109005 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 121 End = 132 Frequency = 1 [1] 1.5247580 1.0327979 2.2833995 4.6814358 5.0490985 4.1927768 4.6392404 [8] 3.7910512 2.2886612 1.6852056 1.2905516 0.6823534 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 121 End = 132 Frequency = 1 [1] 3.004420 2.604451 3.855127 6.281057 6.648732 5.793575 6.243664 5.396751 [9] 3.895716 3.293775 2.900344 2.293083 > 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] 1.894000 1.757000 3.582000 5.321000 5.561000 5.907000 4.944000 4.966000 [9] 3.258000 1.964000 1.743000 1.262000 2.086000 1.793000 3.548000 5.672000 [17] 6.084000 4.914000 4.990000 5.139000 3.218000 2.179000 2.238000 1.442000 [25] 2.205000 2.025000 3.531000 4.977000 7.998000 4.880000 5.231000 5.202000 [33] 3.303000 2.683000 2.202000 1.376000 2.422000 1.997000 3.163000 5.964000 [41] 5.657000 6.415000 6.208000 4.500000 2.939000 2.702000 2.090000 1.504000 [49] 2.549000 1.931000 3.013000 6.204000 5.788000 5.611000 5.594000 4.647000 [57] 3.490000 2.487000 1.992000 1.507000 2.306000 2.002000 3.075000 5.331000 [65] 5.589000 5.813000 4.876000 4.665000 3.601000 2.192000 2.111000 1.580000 [73] 2.288000 1.993000 3.228000 5.000000 5.480000 5.770000 4.962000 4.685000 [81] 3.607000 2.222000 2.467000 1.594000 2.228000 1.910000 3.157000 4.809000 [89] 6.249000 4.607000 4.975000 4.784000 3.028000 2.461000 2.218000 1.351000 [97] 2.070000 1.887000 3.024000 4.596000 6.398000 4.459000 5.382000 4.359000 [105] 2.687000 2.249000 2.154000 1.169000 2.429000 1.762000 2.846000 5.627000 [113] 5.749000 4.502000 5.720000 4.403000 2.867000 2.635000 2.059000 1.511000 [121] 2.264589 1.818624 3.069263 5.481247 5.848915 4.993176 5.441452 4.593901 [129] 3.092188 2.489490 2.095448 1.487718 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 121 End = 132 Frequency = 1 [1] 0.16668140 0.22045887 0.13063425 0.07444780 0.06976844 0.08178500 [7] 0.07521737 0.08916546 0.13258017 0.16483266 0.19597787 0.27619506 > postscript(file="/var/wessaorg/rcomp/tmp/1t1l21355740653.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/2d9sn1355740653.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/3f5g01355740653.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/4466o1355740653.tab") > > try(system("convert tmp/1t1l21355740653.ps tmp/1t1l21355740653.png",intern=TRUE)) character(0) > try(system("convert tmp/2d9sn1355740653.ps tmp/2d9sn1355740653.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 5.419 1.175 6.573