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(1021.3 + ,1039.79 + ,938.12 + ,947.36 + ,956.6 + ,956.6 + ,942.74 + ,951.98 + ,919.63 + ,901.15 + ,887.28 + ,836.45 + ,841.07 + ,836.45 + ,831.83 + ,817.97 + ,771.75 + ,707.05 + ,716.3 + ,725.54 + ,716.3 + ,707.05 + ,716.3 + ,780.99 + ,859.56 + ,961.22 + ,938.12 + ,988.95 + ,910.39 + ,901.15 + ,896.53 + ,910.39 + ,988.95 + ,988.95 + ,965.85 + ,975.09 + ,1002.82 + ,1025.92 + ,1081.38 + ,1164.56 + ,1201.53 + ,1229.26 + ,1275.47 + ,1275.47 + ,1307.82 + ,1252.36 + ,1261.61 + ,1340.17 + ,1414.11 + ,1409.49 + ,1432.59 + ,1520.4 + ,1529.64 + ,1455.7 + ,1427.97 + ,1538.88 + ,1612.82 + ,1635.93 + ,1603.58 + ,1589.72 + ,1557.37 + ,1589.72 + ,1668.28 + ,1635.93 + ,1615.68 + ,1644.69 + ,1622.71 + ,1626.11 + ,1705.55 + ,1841.35 + ,2029.03 + ,2024.21 + ,1952.87 + ,2153.06 + ,2339.29 + ,2502.89 + ,2515.37 + ,2445.68 + ,2491.11 + ,2691.32 + ,2651.8 + ,2593.49 + ,2697.23 + ,2751.63 + ,2713.9 + ,2747.21 + ,2982.32 + ,3063.39 + ,3058.7 + ,3074.38 + ,3341.06 + ,3500.03 + ,392.88 + ,3071.52 + ,2516.41 + ,2350.7 + ,2488.68 + ,2872.65 + ,3220.21 + ,3078.04 + ,3043.98 + ,3134.34 + ,3141.85 + ,3128.01 + ,3241.16 + ,3389.48 + ,3406.36 + ,3449.84 + ,3606.24 + ,3653.99 + ,3607.31 + ,3712.52 + ,3803.47 + ,3806.33 + ,3768.4 + ,3952.06 + ,4134.85 + ,4060.9 + ,3999.88 + ,4004.03 + ,3977.34 + ,3650.08 + ,3708.85 + ,3764.78 + ,3761.86 + ,3802.55 + ,3773.52 + ,3428.7 + ,3194.21 + ,3095.56 + ,3064.85 + ,3022.98 + ,2887.66 + ,3178.86 + ,3438.47 + ,3493.87 + ,3421.89 + ,3390.28 + ,3319.24 + ,3287.84 + ,3222.82 + ,3182.69 + ,3180.21 + ,3116.34 + ,3297.46 + ,3357.48 + ,3386.03 + ,3319.45 + ,3363.59 + ,3303.47 + ,3210.55 + ,3050.27 + ,3010.55 + ,3011.65 + ,3104.98 + ,3087.85 + ,3160.16 + ,3319.22 + ,3432.49 + ,3475.68 + ,3347.48 + ,3388.81 + ,3610.23 + ,3691.45 + ,3587.86 + ,3704.62 + ,3798.75 + ,3956.54 + ,4121.94 + ,4148.56 + ,4100.37 + ,4060.71 + ,4147.86 + ,3926.61 + ,3865.41 + ,3978.57 + ,3851.95 + ,3701.22 + ,3738.65 + ,3766.9 + ,3711.02 + ,3675.22 + ,3560.53 + ,3723.8 + ,3914.27 + ,3870.77 + ,3924.36 + ,3968.89 + ,3982.93 + ,3917.09 + ,3969.18 + ,4149.81 + ,4406.88 + ,423.82 + ,417.72 + ,4527.16 + ,4617.39 + ,4656.23 + ,4579.9 + ,4652.4 + ,4722.95 + ,4845.81 + ,4975.21 + ,5083.64 + ,5378.04 + ,5684.44 + ,5841.87 + ,5857.23 + ,6174.52 + ,6413.17 + ,6780.11 + ,6524.94 + ,6466.7 + ,6495.61 + ,6399.52 + ,6729.98 + ,7060.77 + ,7423.27 + ,8069.17 + ,8650.68 + ,8938.07 + ,9482.08 + ,10225.26 + ,9390.27 + ,8546.11 + ,8073.77 + ,8655.31 + ,9150.1 + ,9775.81 + ,9785.14 + ,9363.44 + ,9304.18 + ,9030.26 + ,8920.8 + ,8606.08 + ,8353.75 + ,8615.63 + ,8128.64 + ,8715.94 + ,8500.8 + ,8142.58 + ,7614.66 + ,7558.95 + ,7820.75 + ,7828.9 + ,7904.59 + ,8140.97 + ,8483.01 + ,8322.68 + ,8268.01 + ,8402.05 + ,8177.78 + ,7950.54 + ,8049.94 + ,7674.13 + ,7666.36 + ,7570.18 + ,7694.45 + ,7810.64 + ,7748.43 + ,7040.64 + ,7077.26 + ,7245.51 + ,7289.12 + ,7486.92 + ,7519.88 + ,7554.84 + ,7780.89 + ,7748.09 + ,7152.25 + ,6484.66 + ,6254.58 + ,5867.32 + ,5544.16 + ,5822.74 + ,5690.63 + ,5564.78 + ,5088.39 + ,4784.22 + ,5332.46 + ,5541.48 + ,5723.92 + ,5736.99 + ,5992.07 + ,6091.43 + ,6158.17 + ,6303.79 + ,6349.71 + ,6802.96 + ,7132.68 + ,7073.29 + ,7264.5 + ,7105.33 + ,7218.71 + ,7225.72 + ,7354.25 + ,7745.46 + ,8070.26 + ,8366.33 + ,8667.51 + ,8854.34 + ,9218.1 + ,9332.9 + ,9358.31 + ,9248.66 + ,9401.2 + ,9652.04 + ,9957.38 + ,10110.63 + ,10169.26 + ,10343.78 + ,10750.21 + ,11337.5 + ,11786.96 + ,12083.04 + ,12007.74 + ,11745.93 + ,11051.51 + ,11445.9 + ,11924.88 + ,12247.63 + ,12690.91 + ,12910.7 + ,13202.12 + ,13654.67 + ,13862.82 + ,13523.93 + ,14211.17 + ,14510.35 + ,14289.23 + ,14111.82 + ,13086.59 + ,13351.54 + ,13747.69 + ,12855.61 + ,12926.93 + ,12121.95 + ,11731.65 + ,11639.51 + ,12163.78 + ,12029.53 + ,11234.18 + ,9852.13 + ,9709.04 + ,9332.75 + ,7108.6 + ,6691.49 + ,6143.05 + ,6379.15 + ,5994.58 + ,5607.94 + ,6046.13 + ,6624.96 + ,6652.54 + ,6696 + ,7315.16 + ,7907.79 + ,8066.35 + ,7939.64 + ,8068.48 + ,8186.33 + ,7975.21 + ,8357.51 + ,8463.38 + ,7937.68 + ,8034.62 + ,8056.61 + ,8176.95 + ,8441.04 + ,8697.39 + ,8665.57 + ,8625.77 + ,8718.42 + ,8822.34 + ,8597.67 + ,8782.05 + ,8661.06 + ,8265.32 + ,8072.58 + ,721.85 + ,7138.6 + ,7351.11 + ,7077 + ,7272.37 + ,7577.84) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '0.0' > par1 = '11' > par10 <- 'FALSE' > par9 <- '0' > par8 <- '0' > par7 <- '1' > par6 <- '1' > par5 <- '12' > par4 <- '0' > par3 <- '1' > par2 <- '0.0' > par1 <- '11' > #'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 0.3297 -0.7774 s.e. 0.0721 0.0444 sigma^2 estimated as 0.04579: log likelihood = 45.63, aic = -85.26 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 375 End = 385 Frequency = 1 [1] 9.067113 9.061202 9.059253 9.058610 9.058398 9.058328 9.058305 9.058298 [9] 9.058295 9.058294 9.058294 $se Time Series: Start = 375 End = 385 Frequency = 1 [1] 0.2139792 0.2444475 0.2593334 0.2702920 0.2799112 0.2889279 0.2975820 [8] 0.3059628 0.3141108 0.3220499 0.3297969 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 375 End = 385 Frequency = 1 [1] 8.647714 8.582085 8.550959 8.528838 8.509772 8.492030 8.475045 8.458611 [9] 8.442638 8.427076 8.411892 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 375 End = 385 Frequency = 1 [1] 9.486513 9.540319 9.567546 9.588382 9.607024 9.624627 9.641566 9.657985 [9] 9.673952 9.689512 9.704696 > 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] 1021.300 1039.790 938.120 947.360 956.600 956.600 942.740 [8] 951.980 919.630 901.150 887.280 836.450 841.070 836.450 [15] 831.830 817.970 771.750 707.050 716.300 725.540 716.300 [22] 707.050 716.300 780.990 859.560 961.220 938.120 988.950 [29] 910.390 901.150 896.530 910.390 988.950 988.950 965.850 [36] 975.090 1002.820 1025.920 1081.380 1164.560 1201.530 1229.260 [43] 1275.470 1275.470 1307.820 1252.360 1261.610 1340.170 1414.110 [50] 1409.490 1432.590 1520.400 1529.640 1455.700 1427.970 1538.880 [57] 1612.820 1635.930 1603.580 1589.720 1557.370 1589.720 1668.280 [64] 1635.930 1615.680 1644.690 1622.710 1626.110 1705.550 1841.350 [71] 2029.030 2024.210 1952.870 2153.060 2339.290 2502.890 2515.370 [78] 2445.680 2491.110 2691.320 2651.800 2593.490 2697.230 2751.630 [85] 2713.900 2747.210 2982.320 3063.390 3058.700 3074.380 3341.060 [92] 3500.030 392.880 3071.520 2516.410 2350.700 2488.680 2872.650 [99] 3220.210 3078.040 3043.980 3134.340 3141.850 3128.010 3241.160 [106] 3389.480 3406.360 3449.840 3606.240 3653.990 3607.310 3712.520 [113] 3803.470 3806.330 3768.400 3952.060 4134.850 4060.900 3999.880 [120] 4004.030 3977.340 3650.080 3708.850 3764.780 3761.860 3802.550 [127] 3773.520 3428.700 3194.210 3095.560 3064.850 3022.980 2887.660 [134] 3178.860 3438.470 3493.870 3421.890 3390.280 3319.240 3287.840 [141] 3222.820 3182.690 3180.210 3116.340 3297.460 3357.480 3386.030 [148] 3319.450 3363.590 3303.470 3210.550 3050.270 3010.550 3011.650 [155] 3104.980 3087.850 3160.160 3319.220 3432.490 3475.680 3347.480 [162] 3388.810 3610.230 3691.450 3587.860 3704.620 3798.750 3956.540 [169] 4121.940 4148.560 4100.370 4060.710 4147.860 3926.610 3865.410 [176] 3978.570 3851.950 3701.220 3738.650 3766.900 3711.020 3675.220 [183] 3560.530 3723.800 3914.270 3870.770 3924.360 3968.890 3982.930 [190] 3917.090 3969.180 4149.810 4406.880 423.820 417.720 4527.160 [197] 4617.390 4656.230 4579.900 4652.400 4722.950 4845.810 4975.210 [204] 5083.640 5378.040 5684.440 5841.870 5857.230 6174.520 6413.170 [211] 6780.110 6524.940 6466.700 6495.610 6399.520 6729.980 7060.770 [218] 7423.270 8069.170 8650.680 8938.070 9482.080 10225.260 9390.270 [225] 8546.110 8073.770 8655.310 9150.100 9775.810 9785.140 9363.440 [232] 9304.180 9030.260 8920.800 8606.080 8353.750 8615.630 8128.640 [239] 8715.940 8500.800 8142.580 7614.660 7558.950 7820.750 7828.900 [246] 7904.590 8140.970 8483.010 8322.680 8268.010 8402.050 8177.780 [253] 7950.540 8049.940 7674.130 7666.360 7570.180 7694.450 7810.640 [260] 7748.430 7040.640 7077.260 7245.510 7289.120 7486.920 7519.880 [267] 7554.840 7780.890 7748.090 7152.250 6484.660 6254.580 5867.320 [274] 5544.160 5822.740 5690.630 5564.780 5088.390 4784.220 5332.460 [281] 5541.480 5723.920 5736.990 5992.070 6091.430 6158.170 6303.790 [288] 6349.710 6802.960 7132.680 7073.290 7264.500 7105.330 7218.710 [295] 7225.720 7354.250 7745.460 8070.260 8366.330 8667.510 8854.340 [302] 9218.100 9332.900 9358.310 9248.660 9401.200 9652.040 9957.380 [309] 10110.630 10169.260 10343.780 10750.210 11337.500 11786.960 12083.040 [316] 12007.740 11745.930 11051.510 11445.900 11924.880 12247.630 12690.910 [323] 12910.700 13202.120 13654.670 13862.820 13523.930 14211.170 14510.350 [330] 14289.230 14111.820 13086.590 13351.540 13747.690 12855.610 12926.930 [337] 12121.950 11731.650 11639.510 12163.780 12029.530 11234.180 9852.130 [344] 9709.040 9332.750 7108.600 6691.490 6143.050 6379.150 5994.580 [351] 5607.940 6046.130 6624.960 6652.540 6696.000 7315.160 7907.790 [358] 8066.350 7939.640 8068.480 8186.330 7975.210 8357.510 8463.380 [365] 7937.680 8034.620 8056.610 8176.950 8441.040 8697.390 8665.570 [372] 8625.770 8718.420 8822.340 8665.574 8614.498 8597.723 8592.199 [379] 8590.379 8589.778 8589.580 8589.515 8589.494 8589.487 8589.484 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 375 End = 385 Frequency = 1 [1] 0.2658405 0.3135960 0.3379856 0.3564008 0.3728944 0.3886399 0.4040161 [8] 0.4191574 0.4341187 0.4489278 0.4636026 > postscript(file="/var/wessaorg/rcomp/tmp/1qjbp1355695400.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/wessaorg/rcomp/tmp/2zx2m1355695400.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/399891355695400.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/wessaorg/rcomp/tmp/4u2d81355695400.tab") > > try(system("convert tmp/1qjbp1355695400.ps tmp/1qjbp1355695400.png",intern=TRUE)) character(0) > try(system("convert tmp/2zx2m1355695400.ps tmp/2zx2m1355695400.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.616 0.366 1.957