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(14.458,13.594,17.814,20.235,21.811,21.439,21.393,19.831,20.468,21.080,21.600,17.390,17.848,19.592,21.092,20.899,25.890,24.965,22.225,20.977,22.897,22.785,22.769,19.637,20.203,20.450,23.083,21.738,26.766,25.280,22.574,22.729,21.378,22.902,24.989,21.116,15.169,15.846,20.927,18.273,22.538,15.596,14.034,11.366,14.861,15.149,13.577,13.026,13.190,13.196,15.826,14.733,16.307,15.703,14.589,12.043,15.057,14.053,12.698,10.888,10.045,11.549,13.767,12.434,13.116,14.211,12.266,12.602,15.714,13.742,12.745,10.491,10.057,10.900,11.771,11.992,11.933,14.504,11.727,11.477,13.578,11.555,11.846,11.397,10.066,10.269,14.279,13.870,13.695,14.420,11.424,9.704,12.464,14.301,13.464,9.893,11.572,12.380,16.692,16.052,16.459,14.761,13.654,13.480,18.068,16.560,14.530,10.650,11.651,13.735,13.360,17.818,20.613,16.231,13.862,12.004,17.734,15.034,12.609,12.320,10.833,11.350,13.648,14.890,16.325,18.045,15.616,11.926,16.855,15.083,12.520,12.355) > par20 = '' > par19 = '' > par18 = '' > par17 = '' > par16 = '' > par15 = '' > par14 = '' > par13 = '' > par12 = '' > par11 = '' > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '24' > ylab = '' > xlab = '' > main = '' > #'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 ma1 sar1 sma1 0.3003 -0.6242 0.2556 -1.0000 s.e. 0.1999 0.1561 0.1211 0.3581 sigma^2 estimated as 2.436: log likelihood = -187.61, aic = 385.22 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 109 End = 132 Frequency = 1 [1] 11.31128 12.11105 15.60909 15.12416 16.69126 15.61739 13.99867 13.16491 [9] 16.03371 15.44317 14.58332 11.55218 11.35684 11.97542 15.21161 14.75018 [17] 16.60900 15.69323 13.94326 12.94070 15.36996 15.01396 14.45323 11.63909 $se Time Series: Start = 109 End = 132 Frequency = 1 [1] 1.646895 1.985101 2.200240 2.377571 2.537499 2.686507 2.827270 2.961237 [9] 3.089381 3.212450 3.331105 3.446060 3.749615 3.957398 4.138011 4.306351 [17] 4.467001 4.621679 4.771235 4.916216 5.057055 5.194145 5.327935 5.459146 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 109 End = 132 Frequency = 1 [1] 8.0833610 8.2202499 11.2966205 10.4641247 11.7177581 10.3518392 [7] 8.4572242 7.3608813 9.9785224 9.1467727 8.0543526 4.7978989 [13] 4.0075922 4.2189206 7.1011112 6.3097362 7.8536743 6.6347384 [19] 4.5916373 3.3049137 5.4581372 4.8334356 4.0104812 0.9391672 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 109 End = 132 Frequency = 1 [1] 14.53919 16.00185 19.92156 19.78420 21.66476 20.88295 19.54012 18.96893 [9] 22.08890 21.73958 21.11228 18.30645 18.70608 19.73192 23.32212 23.19063 [17] 25.36432 24.75172 23.29488 22.57648 25.28179 25.19448 24.89599 22.33902 > 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] 14.45800 13.59400 17.81400 20.23500 21.81100 21.43900 21.39300 19.83100 [9] 20.46800 21.08000 21.60000 17.39000 17.84800 19.59200 21.09200 20.89900 [17] 25.89000 24.96500 22.22500 20.97700 22.89700 22.78500 22.76900 19.63700 [25] 20.20300 20.45000 23.08300 21.73800 26.76600 25.28000 22.57400 22.72900 [33] 21.37800 22.90200 24.98900 21.11600 15.16900 15.84600 20.92700 18.27300 [41] 22.53800 15.59600 14.03400 11.36600 14.86100 15.14900 13.57700 13.02600 [49] 13.19000 13.19600 15.82600 14.73300 16.30700 15.70300 14.58900 12.04300 [57] 15.05700 14.05300 12.69800 10.88800 10.04500 11.54900 13.76700 12.43400 [65] 13.11600 14.21100 12.26600 12.60200 15.71400 13.74200 12.74500 10.49100 [73] 10.05700 10.90000 11.77100 11.99200 11.93300 14.50400 11.72700 11.47700 [81] 13.57800 11.55500 11.84600 11.39700 10.06600 10.26900 14.27900 13.87000 [89] 13.69500 14.42000 11.42400 9.70400 12.46400 14.30100 13.46400 9.89300 [97] 11.57200 12.38000 16.69200 16.05200 16.45900 14.76100 13.65400 13.48000 [105] 18.06800 16.56000 14.53000 10.65000 11.31128 12.11105 15.60909 15.12416 [113] 16.69126 15.61739 13.99867 13.16491 16.03371 15.44317 14.58332 11.55218 [121] 11.35684 11.97542 15.21161 14.75018 16.60900 15.69323 13.94326 12.94070 [129] 15.36996 15.01396 14.45323 11.63909 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 109 End = 132 Frequency = 1 [1] 0.1455976 0.1639083 0.1409589 0.1572035 0.1520257 0.1720202 0.2019670 [8] 0.2249342 0.1926804 0.2080175 0.2284189 0.2983040 0.3301636 0.3304600 [15] 0.2720297 0.2919524 0.2689507 0.2945015 0.3421894 0.3799035 0.3290219 [22] 0.3459544 0.3686327 0.4690353 > postscript(file="/var/www/html/rcomp/tmp/1j1g81293206931.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/2qkd21293206931.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/3pdd91293206932.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/4tete1293206932.tab") > > try(system("convert tmp/1j1g81293206931.ps tmp/1j1g81293206931.png",intern=TRUE)) character(0) > try(system("convert tmp/2qkd21293206931.ps tmp/2qkd21293206931.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.083 0.392 2.666