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(9700,9081,9084,9743,8587,9731,9563,9998,9437,10038,9918,9252,9737,9035,9133,9487,8700,9627,8947,9283,8829,9947,9628,9318,9605,8640,9214,9567,8547,9185,9470,9123,9278,10170,9434,9655,9429,8739,9552,9687,9019,9672,9206,9069,9788,10312,10105,9863,9656,9295,9946,9701,9049,10190,9706,9765,9893,9994,10433,10073,10112,9266,9820,10097,9115,10411,9678,10408,10153,10368,10581,10597,10680,9738,9556) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '2' > par6 = '0' > par5 = '1' > par4 = '1' > par3 = '0' > par2 = '1' > par1 = '24' > par10 <- 'FALSE' > par9 <- '1' > par8 <- '2' > par7 <- '2' > par6 <- '0' > par5 <- '1' > par4 <- '1' > par3 <- '0' > 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: ma1 ma2 sar1 sar2 sma1 -1.2049 0.2049 0.4276 0.1537 -0.2044 s.e. 0.5089 0.4963 0.4259 0.1924 0.4958 sigma^2 estimated as 176645: log likelihood = -374.63, aic = 761.26 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 52 End = 75 Frequency = 1 [1] 9451.390 9537.882 9481.659 9470.917 9457.681 9450.369 9445.208 9441.877 [9] 9439.660 9438.199 9437.234 9436.597 9436.176 9435.898 9435.714 9435.593 [17] 9435.513 9435.460 9435.425 9435.402 9435.387 9435.377 9435.370 9435.366 $se Time Series: Start = 52 End = 75 Frequency = 1 [1] 424.2012 424.4146 434.6769 437.1725 438.8587 439.7008 440.1910 440.4767 [9] 440.6507 440.7588 440.8273 440.8712 440.8997 440.9183 440.9305 440.9384 [17] 440.9437 440.9472 440.9494 440.9509 440.9519 440.9526 440.9530 440.9533 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 52 End = 75 Frequency = 1 [1] 8619.955 8706.029 8629.693 8614.059 8597.517 8588.556 8582.434 8578.543 [9] 8575.984 8574.312 8573.213 8572.489 8572.012 8571.698 8571.491 8571.354 [17] 8571.264 8571.204 8571.165 8571.139 8571.121 8571.110 8571.103 8571.098 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 52 End = 75 Frequency = 1 [1] 10282.82 10369.73 10333.63 10327.78 10317.84 10312.18 10307.98 10305.21 [9] 10303.34 10302.09 10301.26 10300.70 10300.34 10300.10 10299.94 10299.83 [17] 10299.76 10299.72 10299.69 10299.67 10299.65 10299.64 10299.64 10299.63 > 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] 9700.000 9081.000 9084.000 9743.000 8587.000 9731.000 9563.000 [8] 9998.000 9437.000 10038.000 9918.000 9252.000 9737.000 9035.000 [15] 9133.000 9487.000 8700.000 9627.000 8947.000 9283.000 8829.000 [22] 9947.000 9628.000 9318.000 9605.000 8640.000 9214.000 9567.000 [29] 8547.000 9185.000 9470.000 9123.000 9278.000 10170.000 9434.000 [36] 9655.000 9429.000 8739.000 9552.000 9687.000 9019.000 9672.000 [43] 9206.000 9069.000 9788.000 10312.000 10105.000 9863.000 9656.000 [50] 9295.000 9946.000 9451.390 9537.882 9481.659 9470.917 9457.681 [57] 9450.369 9445.208 9441.877 9439.660 9438.199 9437.234 9436.597 [64] 9436.176 9435.898 9435.714 9435.593 9435.513 9435.460 9435.425 [71] 9435.402 9435.387 9435.377 9435.370 9435.366 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 52 End = 75 Frequency = 1 [1] 0.04488242 0.04449779 0.04584397 0.04615947 0.04640236 0.04652737 [7] 0.04660469 0.04665139 0.04668078 0.04669945 0.04671149 0.04671930 [13] 0.04672441 0.04672775 0.04672995 0.04673140 0.04673235 0.04673298 [19] 0.04673339 0.04673367 0.04673385 0.04673397 0.04673404 0.04673410 > postscript(file="/var/fisher/rcomp/tmp/1xict1355481646.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/fisher/rcomp/tmp/256nq1355481646.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/fisher/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/fisher/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/fisher/rcomp/tmp/3giz71355481646.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/fisher/rcomp/tmp/45qla1355481646.tab") > > try(system("convert tmp/1xict1355481646.ps tmp/1xict1355481646.png",intern=TRUE)) character(0) > try(system("convert tmp/256nq1355481646.ps tmp/256nq1355481646.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.589 0.431 2.004