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(5745,4549,5074,3602,2732,2589,2148,2330,2752,3241,4517,6550,6778,6240,5570,3558,3299,2447,2380,2378,2947,3651,4816,6436,7090,4682,4198,3860,3056,2563,2568,2472,2821,4015,4686,5418,5649,4572,4695,3766,2900,2528,2549,2478,2828,4139,5390,5621,5291,5272,4677,3520,2842,2723,2581,2429,2606,3787,4630,5505,5577,4911,4701,3557,2921,2734,2636,2433,2640,3794,4745,5698,5909,5119,5200,3876,3104,2251,2386,2794,2967,3392,4741,5909,5901,4962,4751,3909,3130,2860,2568,2540,2894,4216,4530,5144,6206,5645,4601,3645,3140,2264,2557,2431,2747,4587,4512,5313,6011,5328,5014,3630,3102,2739,2877,2659,2957,3785,4785,5757,5458,5427,5018,3498,3204,2763,2589,2591,2805,3278,4615,5524,6167,5380,5377,3603,2774,2470,2407,2512,2451,3134,4210,4859,5022,4584,4267,3022,2777,2428,2389,2496,2820,3854,4748,5666,5293,4905,4920,3854,2659,2491,2455,2472,3030,3987,4453,5417) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '-0.8' > 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 sma1 0.1588 -0.0406 0.2246 0.1960 -0.9965 s.e. 0.3892 0.1572 0.0855 0.4023 0.3084 sigma^2 estimated as 6.235e-09: log likelihood = 1140.7, aic = -2269.39 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 157 End = 168 Frequency = 1 [1] 0.0009570878 0.0010777090 0.0011276074 0.0014245537 0.0016565238 [6] 0.0018797542 0.0019121460 0.0019135131 0.0017564614 0.0013921792 [11] 0.0011607793 0.0009999943 $se Time Series: Start = 157 End = 168 Frequency = 1 [1] 8.183827e-05 8.681214e-05 8.682063e-05 8.853827e-05 8.901597e-05 [6] 8.902206e-05 8.909813e-05 8.913621e-05 8.913531e-05 8.913037e-05 [11] 8.913277e-05 8.910881e-05 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 157 End = 168 Frequency = 1 [1] 0.0007966848 0.0009075572 0.0009574390 0.0012510187 0.0014820525 [6] 0.0017052710 0.0017375137 0.0017388062 0.0015817561 0.0012174837 [11] 0.0009860791 0.0008253410 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 157 End = 168 Frequency = 1 [1] 0.001117491 0.001247861 0.001297776 0.001598089 0.001830995 0.002054237 [7] 0.002086778 0.002088220 0.001931167 0.001566875 0.001335480 0.001174648 > 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] 5745.000 4549.000 5074.000 3602.000 2732.000 2589.000 2148.000 2330.000 [9] 2752.000 3241.000 4517.000 6550.000 6778.000 6240.000 5570.000 3558.000 [17] 3299.000 2447.000 2380.000 2378.000 2947.000 3651.000 4816.000 6436.000 [25] 7090.000 4682.000 4198.000 3860.000 3056.000 2563.000 2568.000 2472.000 [33] 2821.000 4015.000 4686.000 5418.000 5649.000 4572.000 4695.000 3766.000 [41] 2900.000 2528.000 2549.000 2478.000 2828.000 4139.000 5390.000 5621.000 [49] 5291.000 5272.000 4677.000 3520.000 2842.000 2723.000 2581.000 2429.000 [57] 2606.000 3787.000 4630.000 5505.000 5577.000 4911.000 4701.000 3557.000 [65] 2921.000 2734.000 2636.000 2433.000 2640.000 3794.000 4745.000 5698.000 [73] 5909.000 5119.000 5200.000 3876.000 3104.000 2251.000 2386.000 2794.000 [81] 2967.000 3392.000 4741.000 5909.000 5901.000 4962.000 4751.000 3909.000 [89] 3130.000 2860.000 2568.000 2540.000 2894.000 4216.000 4530.000 5144.000 [97] 6206.000 5645.000 4601.000 3645.000 3140.000 2264.000 2557.000 2431.000 [105] 2747.000 4587.000 4512.000 5313.000 6011.000 5328.000 5014.000 3630.000 [113] 3102.000 2739.000 2877.000 2659.000 2957.000 3785.000 4785.000 5757.000 [121] 5458.000 5427.000 5018.000 3498.000 3204.000 2763.000 2589.000 2591.000 [129] 2805.000 3278.000 4615.000 5524.000 6167.000 5380.000 5377.000 3603.000 [137] 2774.000 2470.000 2407.000 2512.000 2451.000 3134.000 4210.000 4859.000 [145] 5022.000 4584.000 4267.000 3022.000 2777.000 2428.000 2389.000 2496.000 [153] 2820.000 3854.000 4748.000 5666.000 5940.326 5121.216 4839.523 3613.279 [161] 2992.285 2554.899 2500.914 2498.680 2781.005 3718.614 4667.270 5623.453 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 157 End = 168 Frequency = 1 [1] 0.13148626 0.12224899 0.11576437 0.08994993 0.07615214 0.06606924 [7] 0.06488478 0.06486402 0.07138704 0.09309675 0.11538811 0.13835425 > postscript(file="/var/www/html/rcomp/tmp/1lgoa1293188505.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/2sz3m1293188505.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/3zi0g1293188505.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/4cbjg1293188506.tab") > > try(system("convert tmp/1lgoa1293188505.ps tmp/1lgoa1293188505.png",intern=TRUE)) character(0) > try(system("convert tmp/2sz3m1293188505.ps tmp/2sz3m1293188505.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.518 0.330 3.927