R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-redhat-linux-gnu (64-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(621,587,655,517,646,657,382,345,625,654,606,510,614,647,580,614,636,388,356,639,753,611,639,630,586,695,552,619,681,421,307,754,690,644,643,608,651,691,627,634,731,475,337,803,722,590,724,627,696,825,677,656,785,412,352,839,729,696,641,695,638,762,635,721,854,418,367,824,687,601,676,740,691,683,594,729,731,386,331,706,715,657,653,642,643,718,654,632,731,392,344,792,852,649,629,685,617,715,715,629,916,531,357,917,828,708,858,775,785,1006,789,734,906,532,387,991,841,892,782,813,793,978,775,797,946,594,438,1022,868,795) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '-0.5' > par1 = '24' > #'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 sar1 sar2 sma1 0.8983 -0.3413 0.3585 -0.7954 -0.5604 -0.3788 0.2979 s.e. 0.1503 0.1297 0.1005 0.1316 0.4950 0.1433 0.5311 sigma^2 estimated as 6.219e-06: log likelihood = 428.14, aic = -840.28 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 107 End = 130 Frequency = 1 [1] 0.03792667 0.03704950 0.03845524 0.03661557 0.03757514 0.03825936 [7] 0.03354579 0.04480598 0.05305924 0.03388865 0.03483568 0.03707974 [13] 0.03776504 0.03746538 0.03836467 0.03620907 0.03740433 0.03847824 [19] 0.03412691 0.04610794 0.05280135 0.03383245 0.03410798 0.03752850 $se Time Series: Start = 107 End = 130 Frequency = 1 [1] 0.002493846 0.002507023 0.002582702 0.002594661 0.002647717 0.002652938 [7] 0.002653585 0.002660021 0.002667967 0.002671781 0.002674670 0.002678159 [13] 0.003325191 0.003339184 0.003357415 0.003369778 0.003404902 0.003411652 [19] 0.003414112 0.003421067 0.003428693 0.003433275 0.003436975 0.003440916 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 107 End = 130 Frequency = 1 [1] 0.03303873 0.03213574 0.03339314 0.03153003 0.03238561 0.03305960 [7] 0.02834476 0.03959233 0.04783003 0.02865196 0.02959332 0.03183054 [13] 0.03124766 0.03092058 0.03178413 0.02960430 0.03073072 0.03179141 [19] 0.02743525 0.03940265 0.04608111 0.02710323 0.02737151 0.03078430 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 107 End = 130 Frequency = 1 [1] 0.04281460 0.04196327 0.04351733 0.04170110 0.04276467 0.04345912 [7] 0.03874682 0.05001962 0.05828846 0.03912534 0.04007803 0.04232893 [13] 0.04428241 0.04401018 0.04494520 0.04281383 0.04407794 0.04516508 [19] 0.04081857 0.05281324 0.05952159 0.04056167 0.04084446 0.04427269 > 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] 621.0000 587.0000 655.0000 517.0000 646.0000 657.0000 382.0000 345.0000 [9] 625.0000 654.0000 606.0000 510.0000 614.0000 647.0000 580.0000 614.0000 [17] 636.0000 388.0000 356.0000 639.0000 753.0000 611.0000 639.0000 630.0000 [25] 586.0000 695.0000 552.0000 619.0000 681.0000 421.0000 307.0000 754.0000 [33] 690.0000 644.0000 643.0000 608.0000 651.0000 691.0000 627.0000 634.0000 [41] 731.0000 475.0000 337.0000 803.0000 722.0000 590.0000 724.0000 627.0000 [49] 696.0000 825.0000 677.0000 656.0000 785.0000 412.0000 352.0000 839.0000 [57] 729.0000 696.0000 641.0000 695.0000 638.0000 762.0000 635.0000 721.0000 [65] 854.0000 418.0000 367.0000 824.0000 687.0000 601.0000 676.0000 740.0000 [73] 691.0000 683.0000 594.0000 729.0000 731.0000 386.0000 331.0000 706.0000 [81] 715.0000 657.0000 653.0000 642.0000 643.0000 718.0000 654.0000 632.0000 [89] 731.0000 392.0000 344.0000 792.0000 852.0000 649.0000 629.0000 685.0000 [97] 617.0000 715.0000 715.0000 629.0000 916.0000 531.0000 357.0000 917.0000 [105] 828.0000 708.0000 695.2014 728.5095 676.2216 745.8792 708.2699 683.1635 [113] 888.6360 498.1133 355.2040 870.7459 824.0461 727.3220 701.1649 712.4260 [121] 679.4182 762.7203 714.7535 675.4131 858.6302 470.3796 358.6823 873.6412 [129] 859.5831 710.0315 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 107 End = 130 Frequency = 1 [1] 0.1621323 0.1679558 0.1664090 0.1778565 0.1766126 0.1731158 0.2044145 [8] 0.1432177 0.1176587 0.2035421 0.1967723 0.1821513 0.2350231 0.2388428 [15] 0.2331335 0.2530497 0.2456573 0.2371991 0.2792375 0.1884216 0.1596621 [22] 0.2847988 0.2820390 0.2480376 > postscript(file="/var/www/wessaorg/rcomp/tmp/1jf011293651945.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/wessaorg/rcomp/tmp/2qgfv1293651945.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/www/wessaorg/rcomp/tmp/3xzu71293651945.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/wessaorg/rcomp/tmp/4ihtd1293651945.tab") > try(system("convert tmp/1jf011293651945.ps tmp/1jf011293651945.png",intern=TRUE)) character(0) > try(system("convert tmp/2qgfv1293651945.ps tmp/2qgfv1293651945.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.46 0.55 4.07