R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-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(52.61 + ,65.04 + ,67.54 + ,63.58 + ,57.35 + ,54.93 + ,54.30 + ,58.89 + ,65.95 + ,82.65 + ,100.08 + ,100.68 + ,97.53 + ,92.29 + ,85.08 + ,91.61 + ,93.61 + ,90.40 + ,99.31 + ,107.71 + ,106.18 + ,98.80 + ,99.58 + ,98.85 + ,92.69 + ,91.82 + ,92.63 + ,98.41 + ,94.56 + ,85.78 + ,84.59 + ,83.49 + ,84.68 + ,80.12 + ,84.37 + ,85.94 + ,87.07 + ,84.52 + ,83.13 + ,75.95 + ,70.12 + ,78.10 + ,83.06 + ,87.92 + ,90.21 + ,89.95 + ,97.08 + ,102.08 + ,100.64 + ,97.73 + ,97.61 + ,100.32 + ,102.04 + ,107.80 + ,111.51 + ,110.18 + ,110.08 + ,117.40 + ,119.82 + ,118.79 + ,113.18 + ,122.76 + ,120.43 + ,129.16 + ,132.48 + ,135.68 + ,141.49 + ,122.40 + ,137.06 + ,144.84 + ,154.64 + ,148.04 + ,152.76 + ,172.00 + ,169.03 + ,179.68 + ,190.38 + ,233.23 + ,231.45 + ,244.87 + ,299.12 + ,385.01 + ,381.48 + ,321.56 + ,317.27 + ,323.09 + ,392.72 + ,372.37 + ,386.52 + ,412.83 + ,404.91 + ,406.73 + ,392.41 + ,363.31 + ,357.95 + ,375.10 + ,369.74 + ,386.14 + ,353.40 + ,346.87 + ,362.53 + ,349.87 + ,347.03 + ,332.94 + ,327.48 + ,327.92 + ,308.91 + ,285.71 + ,318.81 + ,284.76 + ,301.04 + ,315.16 + ,388.34 + ,383.37 + ,416.77 + ,423.24 + ,429.90 + ,486.07 + ,394.41 + ,410.93 + ,430.88 + ,447.29 + ,431.65 + ,456.53 + ,452.93 + ,440.90 + ,416.46 + ,451.49 + ,432.00 + ,436.19 + ,428.55 + ,421.40 + ,425.18 + ,437.24 + ,431.92 + ,412.65 + ,419.37 + ,436.40 + ,421.37 + ,423.66 + ,402.45 + ,402.82 + ,400.46 + ,425.73 + ,417.93 + ,403.43 + ,404.96 + ,393.64 + ,399.98 + ,375.93 + ,366.57 + ,353.90 + ,347.51 + ,364.10 + ,328.64 + ,348.01 + ,329.63 + ,350.96 + ,336.16 + ,332.15 + ,349.46 + ,383.64 + ,369.82 + ,345.50 + ,337.80 + ,334.76 + ,338.02 + ,346.74 + ,371.84 + ,375.90 + ,373.31 + ,391.91 + ,374.28 + ,384.69 + ,372.16 + ,371.97 + ,351.76 + ,352.89 + ,330.48 + ,347.70 + ,345.58 + ,360.76 + ,364.40 + ,374.62 + ,369.07 + ,341.80 + ,337.87 + ,336.58 + ,332.66 + ,335.74 + ,321.64 + ,329.38 + ,321.84 + ,324.56 + ,330.90 + ,310.91 + ,318.07 + ,312.36 + ,315.19 + ,332.89 + ,310.67 + ,321.26 + ,316.15 + ,283.87 + ,280.65 + ,280.21 + ,265.93 + ,267.80 + ,278.03 + ,291.86 + ,262.61 + ,264.80 + ,265.67 + ,251.05 + ,256.11 + ,279.75 + ,282.52 + ,288.89 + ,308.46 + ,292.89 + ,280.79 + ,273.61 + ,276.67 + ,277.92 + ,250.28 + ,264.70 + ,268.95 + ,261.69 + ,257.99 + ,251.28 + ,243.14 + ,246.81 + ,224.50 + ,241.25 + ,254.97 + ,261.39 + ,266.67 + ,264.28 + ,270.45 + ,274.97 + ,281.13 + ,300.65 + ,321.12 + ,354.79 + ,318.97 + ,298.71 + ,318.85 + ,327.89 + ,348.19 + ,335.18 + ,332.98 + ,331.04 + ,317.52 + ,325.31 + ,317.59 + ,313.37 + ,313.00 + ,314.77 + ,298.37 + ,311.10 + ,308.79 + ,297.30 + ,293.58 + ,291.35 + ,291.51 + ,289.94 + ,287.07 + ,280.74 + ,294.95 + ,288.98 + ,285.63 + ,294.55 + ,290.67 + ,314.78 + ,306.50 + ,304.48 + ,308.65 + ,307.01 + ,298.59 + ,293.51 + ,294.90 + ,296.14 + ,294.25 + ,291.75 + ,290.49 + ,288.68 + ,310.07 + ,297.45 + ,300.81 + ,301.56 + ,296.89 + ,305.23 + ,298.45 + ,298.75 + ,273.02 + ,266.62 + ,266.06 + ,284.48 + ,275.71 + ,284.19 + ,284.81 + ,267.29 + ,272.95 + ,262.35 + ,246.34 + ,251.03 + ,247.54 + ,254.80 + ,245.08 + ,251.30 + ,261.48 + ,258.85 + ,270.89 + ,257.55 + ,253.08 + ,238.81 + ,241.22 + ,280.75 + ,284.56 + ,289.35 + ,289.56 + ,289.55 + ,305.00 + ,289.22 + ,301.82 + ,293.56 + ,300.59 + ,298.67 + ,311.55 + ,310.08 + ,312.06 + ,309.13 + ,292.31 + ,284.41 + ,290.02 + ,291.52 + ,296.81 + ,315.60 + ,319.63 + ,303.89 + ,300.53 + ,321.84 + ,309.48 + ,307.68 + ,310.53 + ,327.91 + ,343.18 + ,345.48 + ,342.03 + ,349.57 + ,322.50 + ,310.74 + ,318.96 + ,327.53 + ,320.00 + ,320.72 + ,330.86 + ,342.34 + ,322.37 + ,306.86 + ,301.75 + ,307.27 + ,301.30 + ,315.18 + ,342.11 + ,333.18 + ,332.26 + ,332.32 + ,330.00 + ,321.78 + ,318.59 + ,344.78 + ,324.09 + ,322.03 + ,325.32 + ,325.10 + ,335.10 + ,334.66 + ,334.54 + ,341.15 + ,320.47 + ,323.85 + ,328.06 + ,328.93 + ,337.50 + ,335.65 + ,361.05 + ,353.19 + ,352.28 + ,392.53 + ,393.03 + ,420.42 + ,434.91 + ,468.38 + ,466.35 + ,480.93 + ,511.25 + ,508.39 + ,479.80 + ,495.63 + ,487.09 + ,473.06 + ,473.03 + ,487.87 + ,479.28 + ,500.60 + ,502.82 + ,497.13 + ,496.06 + ,489.80 + ,481.66 + ,486.17 + ,492.94 + ,522.45 + ,545.71 + ,533.77 + ,570.26 + ,623.56 + ,639.94 + ,589.13 + ,559.45 + ,569.96 + ,590.43 + ,588.37 + ,565.80 + ,629.69 + ,576.28 + ,641.89 + ,625.70 + ,717.52 + ,749.58 + ,690.29 + ,666.55 + ,689.18 + ,666.24 + ,662.32 + ,665.83 + ,681.23 + ,704.87 + ,783.13 + ,757.97 + ,775.93 + ,812.08 + ,824.40 + ,886.89 + ,984.07 + ,1015.59 + ,897.30 + ,980.37 + ,957.37 + ,968.96 + ,1062.80 + ,1047.67 + ,967.91 + ,1021.58 + ,1014.02 + ,1034.98 + ,1068.80 + ,1038.38 + ,1133.26 + ,1259.55 + ,1207.42 + ,1234.59 + ,1297.03) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '0' > par6 = '0' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '0.3' > 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: sma1 -0.9815 s.e. 0.1024 sigma^2 estimated as 0.008383: log likelihood = 408.48, aic = -812.96 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 453 End = 464 Frequency = 1 [1] 8.084341 8.136720 8.139230 8.129719 8.135480 8.159448 8.158537 8.149006 [9] 8.163394 8.195347 8.186617 8.221196 $se Time Series: Start = 453 End = 464 Frequency = 1 [1] 0.0921219 0.1302800 0.1595598 0.1842438 0.2059908 0.2256406 0.2437112 [8] 0.2605314 0.2763296 0.2912723 0.3054848 0.3190650 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 453 End = 464 Frequency = 1 [1] 7.903782 7.881371 7.826493 7.768601 7.731738 7.717192 7.680863 7.638364 [9] 7.621788 7.624453 7.587867 7.595828 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 453 End = 464 Frequency = 1 [1] 8.264900 8.392068 8.451967 8.490836 8.539222 8.601703 8.636211 8.659647 [9] 8.705000 8.766240 8.785368 8.846563 > 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] 52.610 65.040 67.540 63.580 57.350 54.930 54.300 58.890 [9] 65.950 82.650 100.080 100.680 97.530 92.290 85.080 91.610 [17] 93.610 90.400 99.310 107.710 106.180 98.800 99.580 98.850 [25] 92.690 91.820 92.630 98.410 94.560 85.780 84.590 83.490 [33] 84.680 80.120 84.370 85.940 87.070 84.520 83.130 75.950 [41] 70.120 78.100 83.060 87.920 90.210 89.950 97.080 102.080 [49] 100.640 97.730 97.610 100.320 102.040 107.800 111.510 110.180 [57] 110.080 117.400 119.820 118.790 113.180 122.760 120.430 129.160 [65] 132.480 135.680 141.490 122.400 137.060 144.840 154.640 148.040 [73] 152.760 172.000 169.030 179.680 190.380 233.230 231.450 244.870 [81] 299.120 385.010 381.480 321.560 317.270 323.090 392.720 372.370 [89] 386.520 412.830 404.910 406.730 392.410 363.310 357.950 375.100 [97] 369.740 386.140 353.400 346.870 362.530 349.870 347.030 332.940 [105] 327.480 327.920 308.910 285.710 318.810 284.760 301.040 315.160 [113] 388.340 383.370 416.770 423.240 429.900 486.070 394.410 410.930 [121] 430.880 447.290 431.650 456.530 452.930 440.900 416.460 451.490 [129] 432.000 436.190 428.550 421.400 425.180 437.240 431.920 412.650 [137] 419.370 436.400 421.370 423.660 402.450 402.820 400.460 425.730 [145] 417.930 403.430 404.960 393.640 399.980 375.930 366.570 353.900 [153] 347.510 364.100 328.640 348.010 329.630 350.960 336.160 332.150 [161] 349.460 383.640 369.820 345.500 337.800 334.760 338.020 346.740 [169] 371.840 375.900 373.310 391.910 374.280 384.690 372.160 371.970 [177] 351.760 352.890 330.480 347.700 345.580 360.760 364.400 374.620 [185] 369.070 341.800 337.870 336.580 332.660 335.740 321.640 329.380 [193] 321.840 324.560 330.900 310.910 318.070 312.360 315.190 332.890 [201] 310.670 321.260 316.150 283.870 280.650 280.210 265.930 267.800 [209] 278.030 291.860 262.610 264.800 265.670 251.050 256.110 279.750 [217] 282.520 288.890 308.460 292.890 280.790 273.610 276.670 277.920 [225] 250.280 264.700 268.950 261.690 257.990 251.280 243.140 246.810 [233] 224.500 241.250 254.970 261.390 266.670 264.280 270.450 274.970 [241] 281.130 300.650 321.120 354.790 318.970 298.710 318.850 327.890 [249] 348.190 335.180 332.980 331.040 317.520 325.310 317.590 313.370 [257] 313.000 314.770 298.370 311.100 308.790 297.300 293.580 291.350 [265] 291.510 289.940 287.070 280.740 294.950 288.980 285.630 294.550 [273] 290.670 314.780 306.500 304.480 308.650 307.010 298.590 293.510 [281] 294.900 296.140 294.250 291.750 290.490 288.680 310.070 297.450 [289] 300.810 301.560 296.890 305.230 298.450 298.750 273.020 266.620 [297] 266.060 284.480 275.710 284.190 284.810 267.290 272.950 262.350 [305] 246.340 251.030 247.540 254.800 245.080 251.300 261.480 258.850 [313] 270.890 257.550 253.080 238.810 241.220 280.750 284.560 289.350 [321] 289.560 289.550 305.000 289.220 301.820 293.560 300.590 298.670 [329] 311.550 310.080 312.060 309.130 292.310 284.410 290.020 291.520 [337] 296.810 315.600 319.630 303.890 300.530 321.840 309.480 307.680 [345] 310.530 327.910 343.180 345.480 342.030 349.570 322.500 310.740 [353] 318.960 327.530 320.000 320.720 330.860 342.340 322.370 306.860 [361] 301.750 307.270 301.300 315.180 342.110 333.180 332.260 332.320 [369] 330.000 321.780 318.590 344.780 324.090 322.030 325.320 325.100 [377] 335.100 334.660 334.540 341.150 320.470 323.850 328.060 328.930 [385] 337.500 335.650 361.050 353.190 352.280 392.530 393.030 420.420 [393] 434.910 468.380 466.350 480.930 511.250 508.390 479.800 495.630 [401] 487.090 473.060 473.030 487.870 479.280 500.600 502.820 497.130 [409] 496.060 489.800 481.660 486.170 492.940 522.450 545.710 533.770 [417] 570.260 623.560 639.940 589.130 559.450 569.960 590.430 588.370 [425] 565.800 629.690 576.280 641.890 625.700 717.520 749.580 690.290 [433] 666.550 689.180 666.240 662.320 665.830 681.230 704.870 783.130 [441] 757.970 775.930 812.080 824.400 886.890 984.070 1015.590 897.300 [449] 980.370 957.370 968.960 1062.800 1060.430 1083.506 1084.620 1080.401 [457] 1082.956 1093.627 1093.220 1088.969 1095.391 1109.748 1105.813 1121.459 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 453 End = 464 Frequency = 1 [1] 0.03898326 0.05535263 0.06832546 0.07953577 0.08939507 0.09814975 [7] 0.10655247 0.11457890 0.12182540 0.12839859 0.13534424 0.14123813 > postscript(file="/var/www/rcomp/tmp/1cmcl1323388874.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/rcomp/tmp/2laya1323388874.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/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/rcomp/tmp/3s4e71323388874.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/rcomp/tmp/4g0bn1323388874.tab") > > try(system("convert tmp/1cmcl1323388874.ps tmp/1cmcl1323388874.png",intern=TRUE)) character(0) > try(system("convert tmp/2laya1323388874.ps tmp/2laya1323388874.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.170 0.110 1.261