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(17848,19592,21092,20899,25890,24965,22225,20977,22897,22785,22769,19637,20203,20450,23083,21738,26766,25280,22574,22729,21378,22902,24989,21116,15169,15846,20927,18273,22538,15596,14034,11366,14861,15149,13577,13026,13190,13196,15826,14733,16307,15703,14589,12043,15057,14053,12698,10888,10045,11549,13767,12434,13116,14211,12266,12602,15714,13742,12745,10491,10057,10900,11771,11992,11933,14504,11727,11477,13578,11555,11846,11397,10066,10269,14279,13870,13695,14420,11424,9704,12464,14301,13464,9893,11572,12380,16692,16052,16459,14761,13654,13480,18068,16560,14530,10650,11651,13735,13360,17818,20613,16231,13862,12004,17734,15034,12609,12320,10833,11350,13648,14890,16325,18045,15616,11926,16855,15083,12520,12355) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '0' > par6 = '0' > 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: sma1 -0.6384 s.e. 0.1240 sigma^2 estimated as 3308536: log likelihood = -743.91, aic = 1491.81 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 97 End = 120 Frequency = 1 [1] 10547.698 11238.219 14571.782 13922.616 14648.893 14286.420 12302.441 [8] 11535.874 14792.723 14175.991 13106.599 10254.091 10151.788 10842.310 [15] 14175.873 13526.707 14252.984 13890.511 11906.532 11139.964 14396.814 [22] 13780.082 12710.690 9858.182 $se Time Series: Start = 97 End = 120 Frequency = 1 [1] 1819.946 2573.370 3151.549 3638.996 4068.454 4456.719 4813.769 [8] 5146.106 5458.245 5753.474 6034.276 6302.580 6772.553 7211.513 [15] 7625.244 8017.655 8391.735 8749.838 9093.849 9425.313 9745.510 [22] 10055.516 10356.246 10648.487 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 97 End = 120 Frequency = 1 [1] 6980.6036 6194.4144 8394.7461 6790.1849 6674.7234 5551.2505 [7] 2867.4533 1449.5063 4094.5635 2899.1820 1279.4178 -2098.9666 [13] -3122.4160 -3292.2547 -769.6059 -2187.8959 -2194.8172 -3259.1705 [19] -5917.4124 -7333.6496 -4704.3861 -5928.7297 -7587.5526 -11012.8527 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 97 End = 120 Frequency = 1 [1] 14114.79 16282.02 20748.82 21055.05 22623.06 23021.59 21737.43 21622.24 [9] 25490.88 25452.80 24933.78 22607.15 23425.99 24976.87 29121.35 29241.31 [17] 30700.79 31040.19 29730.48 29613.58 33498.01 33488.89 33008.93 30729.22 > 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] 17848.000 19592.000 21092.000 20899.000 25890.000 24965.000 22225.000 [8] 20977.000 22897.000 22785.000 22769.000 19637.000 20203.000 20450.000 [15] 23083.000 21738.000 26766.000 25280.000 22574.000 22729.000 21378.000 [22] 22902.000 24989.000 21116.000 15169.000 15846.000 20927.000 18273.000 [29] 22538.000 15596.000 14034.000 11366.000 14861.000 15149.000 13577.000 [36] 13026.000 13190.000 13196.000 15826.000 14733.000 16307.000 15703.000 [43] 14589.000 12043.000 15057.000 14053.000 12698.000 10888.000 10045.000 [50] 11549.000 13767.000 12434.000 13116.000 14211.000 12266.000 12602.000 [57] 15714.000 13742.000 12745.000 10491.000 10057.000 10900.000 11771.000 [64] 11992.000 11933.000 14504.000 11727.000 11477.000 13578.000 11555.000 [71] 11846.000 11397.000 10066.000 10269.000 14279.000 13870.000 13695.000 [78] 14420.000 11424.000 9704.000 12464.000 14301.000 13464.000 9893.000 [85] 11572.000 12380.000 16692.000 16052.000 16459.000 14761.000 13654.000 [92] 13480.000 18068.000 16560.000 14530.000 10650.000 10547.698 11238.219 [99] 14571.782 13922.616 14648.893 14286.420 12302.441 11535.874 14792.723 [106] 14175.991 13106.599 10254.091 10151.788 10842.310 14175.873 13526.707 [113] 14252.984 13890.511 11906.532 11139.964 14396.814 13780.082 12710.690 [120] 9858.182 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 97 End = 120 Frequency = 1 [1] 0.1725444 0.2289838 0.2162775 0.2613730 0.2777312 0.3119549 0.3912857 [8] 0.4460959 0.3689817 0.4058604 0.4603998 0.6146406 0.6671291 0.6651270 [15] 0.5379030 0.5927277 0.5887704 0.6299147 0.7637698 0.8460811 0.6769213 [22] 0.7297138 0.8147666 1.0801674 > postscript(file="/var/www/html/rcomp/tmp/14c3j1292072378.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/2tv0c1292072378.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/30xxo1292072378.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/43xec1292072378.tab") > > try(system("convert tmp/14c3j1292072378.ps tmp/14c3j1292072378.png",intern=TRUE)) character(0) > try(system("convert tmp/2tv0c1292072378.ps tmp/2tv0c1292072378.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.717 0.412 1.715