R version 2.8.0 (2008-10-20) Copyright (C) 2008 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(13363,12530,11420,10948,10173,10602,16094,19631,17140,14345,12632,12894,11808,10673,9939,9890,9283,10131,15864,19283,16203,13919,11937,11795,11268,10522,9929,9725,9372,10068,16230,19115,18351,16265,14103,14115,13327,12618,12129,11775,11493,12470,20792,22337,21325,18581,16475,16581,15745,14453,13712,13766,13336,15346,24446,26178,24628,21282,18850,18822,18060,17536,16417,15842,15188,16905,25430,27962,26607,23364,20827,20506,19181,18016,17354,16256,15770,17538,26899,28915,25247,22856,19980,19856,16994,16839,15618,15883,15513,17106,25272,26731,22891,19583,16939,16757,15435,14786,13680,13208,12707,14277,22436,23229,18241,16145,13994,14780,13100,12329,12463,11532,10784,13106,19491,20418,16094,14491) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '0' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '0.5' > par1 = '12' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > #Technical description: Write here your technical program description (don't use hard returns!) > 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: ma1 sma1 -0.1463 -0.2353 s.e. 0.0994 0.1031 sigma^2 estimated as 5.363: log likelihood = -210.42, aic = 426.83 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 107 End = 118 Frequency = 1 [1] 117.07875 116.41625 110.29581 107.95465 103.38967 101.82070 99.75923 [8] 106.43240 136.40268 139.57370 123.58295 114.96308 $se Time Series: Start = 107 End = 118 Frequency = 1 [1] 2.315912 3.045075 3.630636 4.134072 4.582530 4.990853 5.368207 5.720724 [9] 6.052745 6.367476 6.667367 6.954338 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 107 End = 118 Frequency = 1 [1] 112.53956 110.44790 103.17976 99.85187 94.40791 92.03863 89.23754 [8] 95.21978 124.53930 127.09345 110.51491 101.33257 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 107 End = 118 Frequency = 1 [1] 121.6179 122.3846 117.4119 116.0574 112.3714 111.6028 110.2809 117.6450 [9] 148.2661 152.0540 136.6510 128.5936 > 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] 13363.000 12530.000 11420.000 10948.000 10173.000 10602.000 16094.000 [8] 19631.000 17140.000 14345.000 12632.000 12894.000 11808.000 10673.000 [15] 9939.000 9890.000 9283.000 10131.000 15864.000 19283.000 16203.000 [22] 13919.000 11937.000 11795.000 11268.000 10522.000 9929.000 9725.000 [29] 9372.000 10068.000 16230.000 19115.000 18351.000 16265.000 14103.000 [36] 14115.000 13327.000 12618.000 12129.000 11775.000 11493.000 12470.000 [43] 20792.000 22337.000 21325.000 18581.000 16475.000 16581.000 15745.000 [50] 14453.000 13712.000 13766.000 13336.000 15346.000 24446.000 26178.000 [57] 24628.000 21282.000 18850.000 18822.000 18060.000 17536.000 16417.000 [64] 15842.000 15188.000 16905.000 25430.000 27962.000 26607.000 23364.000 [71] 20827.000 20506.000 19181.000 18016.000 17354.000 16256.000 15770.000 [78] 17538.000 26899.000 28915.000 25247.000 22856.000 19980.000 19856.000 [85] 16994.000 16839.000 15618.000 15883.000 15513.000 17106.000 25272.000 [92] 26731.000 22891.000 19583.000 16939.000 16757.000 15435.000 14786.000 [99] 13680.000 13208.000 12707.000 14277.000 22436.000 23229.000 18241.000 [106] 16145.000 13707.434 13552.743 12165.165 11654.208 10689.424 10367.454 [113] 9951.903 11327.855 18605.691 19480.817 15272.745 13216.509 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 107 End = 118 Frequency = 1 [1] 0.04032852 0.05365456 0.06795827 0.07946332 0.09249626 0.10274125 [7] 0.11329883 0.11316220 0.09260753 0.09532106 0.11360598 0.12815603 > postscript(file="/var/www/html/rcomp/tmp/1c49e1229171589.ps",horizontal=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.se <- array(0, dim=fx) > perf.mse <- 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.mape[i] = perf.mape[i] + abs(perf.pe[i]) + perf.se[i] = (x[nx+i] - forecast$pred[i])^2 + perf.mse[i] = perf.mse[i] + perf.se[i] + 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 = perf.mape / fx > perf.mse = perf.mse / fx > perf.rmse = sqrt(perf.mse) > postscript(file="/var/www/html/rcomp/tmp/2hewl1229171589.ps",horizontal=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:12] <- 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/3f6b21229171589.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.mape[i],4)) + a<-table.element(a,round(perf.se[i],4)) + a<-table.element(a,round(perf.mse[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/4d8lt1229171589.tab") > > system("convert tmp/1c49e1229171589.ps tmp/1c49e1229171589.png") > system("convert tmp/2hewl1229171589.ps tmp/2hewl1229171589.png") > > > proc.time() user system elapsed 0.654 0.334 0.791