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(2938,2909,3141,2427,3059,2918,2901,2823,2798,2892,2967,2397,3458,3024,3100,2904,3056,2771,2897,2772,2857,3020,2648,2364,3194,3013,2560,3074,2746,2846,3184,2354,3080,2963,2430,2296,2416,2647,2789,2685,2666,2882,2953,2127,2563,3061,2809,2861,2781,2555,3206,2570,2410,3195,2736,2743,2934,2668,2907,2866,2983,2878,3225,2515,3193,2663,2908,2896,2853,3028,3053,2455,3401,2969,3243,2849,3296,3121,3194,3023,2984,3525,3116,2383,3294,2882,2820,2583,2803,2767,2945,2716,2644,2956,2598,2171,2994,2645,2724,2550,2707,2679,2878,2307,2496,2637,2436,2426,2607,2533,2888,2520,2229,2804,2661,2547,2509,2465,2629,2706,2666,2432,2836,2888,2566,2802,2611,2683,2675,2434,2693,2619,2903,2550,2900,2456,2912,2883,2464,2655,2447,2592,2698,2274,2901,2397,3004,2614,2882,2671,2761,2806,2414,2673,2748,2112,2903,2633,2684,2861,2504,2708,2961,2535,2688,2699,2469,2585,2582,2480,2709,2441,2182,2585,2881,2422,2690,2659,2535,2613) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '0' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '-2.0' > 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 sar1 sar2 sma1 0.1030 0.3708 -0.3552 -0.8391 s.e. 0.0826 0.0919 0.0823 0.0968 sigma^2 estimated as 4.792e-16: log likelihood = 2521.47, aic = -5032.93 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 169 End = 180 Frequency = 1 [1] 1.162408e-07 1.332317e-07 1.313361e-07 1.327026e-07 1.532343e-07 [6] 1.261470e-07 1.219062e-07 1.576114e-07 1.320580e-07 1.349331e-07 [11] 1.525837e-07 1.413968e-07 $se Time Series: Start = 169 End = 180 Frequency = 1 [1] 2.192131e-08 2.203704e-08 2.203826e-08 2.203827e-08 2.203827e-08 [6] 2.203827e-08 2.203827e-08 2.203827e-08 2.203827e-08 2.203827e-08 [11] 2.203827e-08 2.203817e-08 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 169 End = 180 Frequency = 1 [1] 7.327501e-08 9.003916e-08 8.814110e-08 8.950756e-08 1.100393e-07 [6] 8.295200e-08 7.871118e-08 1.144164e-07 8.886299e-08 9.173813e-08 [11] 1.093887e-07 9.820197e-08 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 169 End = 180 Frequency = 1 [1] 1.592065e-07 1.764243e-07 1.745311e-07 1.758976e-07 1.964293e-07 [6] 1.693420e-07 1.651012e-07 2.008064e-07 1.752530e-07 1.781282e-07 [11] 1.957787e-07 1.845916e-07 > 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] 2938.000 2909.000 3141.000 2427.000 3059.000 2918.000 2901.000 2823.000 [9] 2798.000 2892.000 2967.000 2397.000 3458.000 3024.000 3100.000 2904.000 [17] 3056.000 2771.000 2897.000 2772.000 2857.000 3020.000 2648.000 2364.000 [25] 3194.000 3013.000 2560.000 3074.000 2746.000 2846.000 3184.000 2354.000 [33] 3080.000 2963.000 2430.000 2296.000 2416.000 2647.000 2789.000 2685.000 [41] 2666.000 2882.000 2953.000 2127.000 2563.000 3061.000 2809.000 2861.000 [49] 2781.000 2555.000 3206.000 2570.000 2410.000 3195.000 2736.000 2743.000 [57] 2934.000 2668.000 2907.000 2866.000 2983.000 2878.000 3225.000 2515.000 [65] 3193.000 2663.000 2908.000 2896.000 2853.000 3028.000 3053.000 2455.000 [73] 3401.000 2969.000 3243.000 2849.000 3296.000 3121.000 3194.000 3023.000 [81] 2984.000 3525.000 3116.000 2383.000 3294.000 2882.000 2820.000 2583.000 [89] 2803.000 2767.000 2945.000 2716.000 2644.000 2956.000 2598.000 2171.000 [97] 2994.000 2645.000 2724.000 2550.000 2707.000 2679.000 2878.000 2307.000 [105] 2496.000 2637.000 2436.000 2426.000 2607.000 2533.000 2888.000 2520.000 [113] 2229.000 2804.000 2661.000 2547.000 2509.000 2465.000 2629.000 2706.000 [121] 2666.000 2432.000 2836.000 2888.000 2566.000 2802.000 2611.000 2683.000 [129] 2675.000 2434.000 2693.000 2619.000 2903.000 2550.000 2900.000 2456.000 [137] 2912.000 2883.000 2464.000 2655.000 2447.000 2592.000 2698.000 2274.000 [145] 2901.000 2397.000 3004.000 2614.000 2882.000 2671.000 2761.000 2806.000 [153] 2414.000 2673.000 2748.000 2112.000 2903.000 2633.000 2684.000 2861.000 [161] 2504.000 2708.000 2961.000 2535.000 2688.000 2699.000 2469.000 2585.000 [169] 2933.059 2739.657 2759.357 2745.114 2554.595 2815.539 2864.093 2518.873 [177] 2751.805 2722.329 2560.035 2659.379 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 169 End = 180 Frequency = 1 [1] 0.13240260 0.11042494 0.11259324 0.11102781 0.09186740 0.11896734 [7] 0.12474456 0.08861226 0.11176076 0.10856458 0.09237188 0.10201042 > postscript(file="/var/www/html/rcomp/tmp/1qr8t1291554230.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/2xa541291554230.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/34t2y1291554230.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/47b141291554230.tab") > > try(system("convert tmp/1qr8t1291554230.ps tmp/1qr8t1291554230.png",intern=TRUE)) character(0) > try(system("convert tmp/2xa541291554230.ps tmp/2xa541291554230.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.603 0.353 3.486