R version 2.7.0 (2008-04-22) 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(9005.73 + ,9018.68 + ,9349.44 + ,9327.78 + ,9753.63 + ,10443.5 + ,10853.87 + ,10704.02 + ,11052.23 + ,10935.47 + ,10714.03 + ,10394.48 + ,10817.9 + ,11251.2 + ,11281.26 + ,10539.68 + ,10483.39 + ,10947.43 + ,10580.27 + ,10582.92 + ,10654.41 + ,11014.51 + ,10967.87 + ,10433.56 + ,10665.78 + ,10666.71 + ,10682.74 + ,10777.22 + ,10052.6 + ,10213.97 + ,10546.82 + ,10767.2 + ,10444.5 + ,10314.68 + ,9042.56 + ,9220.75 + ,9721.84 + ,9978.53 + ,9923.81 + ,9892.56 + ,10500.98 + ,10179.35 + ,10080.48 + ,9492.44 + ,8616.49 + ,8685.4 + ,8160.67 + ,8048.1 + ,8641.21 + ,8526.63 + ,8474.21 + ,7916.13 + ,7977.64 + ,8334.59 + ,8623.36 + ,9098.03 + ,9154.34 + ,9284.73 + ,9492.49 + ,9682.35 + ,9762.12 + ,10124.63 + ,10540.05 + ,10601.61 + ,10323.73 + ,10418.4 + ,10092.96 + ,10364.91 + ,10152.09 + ,10032.8 + ,10204.59 + ,10001.6 + ,10411.75 + ,10673.38 + ,10539.51 + ,10723.78 + ,10682.06 + ,10283.19 + ,10377.18 + ,10486.64 + ,10545.38 + ,10554.27 + ,10532.54 + ,10324.31 + ,10695.25 + ,10827.81 + ,10872.48 + ,10971.19 + ,11145.65 + ,11234.68 + ,11333.88 + ,10997.97 + ,11036.89 + ,11257.35 + ,11533.59 + ,11963.12 + ,12185.15 + ,12377.62 + ,12512.89 + ,12631.48 + ,12268.53 + ,12754.8 + ,13407.75 + ,13480.21 + ,13673.28 + ,13239.71 + ,13557.69 + ,13901.28 + ,13200.58 + ,13406.97 + ,12538.12 + ,12419.57 + ,12193.88 + ,12656.63 + ,12812.48 + ,12056.67 + ,11322.38 + ,11530.75 + ,11114.08 + ,9181.73 + ,8614.55) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '1' > 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: ar1 ma1 -0.8843 0.9885 s.e. 0.0839 0.0735 sigma^2 estimated as 111046: log likelihood = -781.15, aic = 1568.3 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 110 End = 121 Frequency = 1 [1] 13167.71 13196.78 13171.08 13193.80 13173.71 13191.48 13175.76 13189.66 [9] 13177.37 13188.24 13178.63 13187.13 $se Time Series: Start = 110 End = 121 Frequency = 1 [1] 333.4636 496.4383 600.2602 702.1369 780.3603 860.0314 925.8937 [8] 993.1888 1051.3585 1110.5386 1163.2938 1216.6581 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 110 End = 121 Frequency = 1 [1] 12514.13 12223.76 11994.57 11817.61 11644.20 11505.82 11361.01 11243.01 [9] 11116.71 11011.58 10898.57 10802.48 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 110 End = 121 Frequency = 1 [1] 13821.30 14169.80 14347.59 14569.99 14703.21 14877.14 14990.52 15136.31 [9] 15238.03 15364.89 15458.68 15571.78 > 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] 9005.73 9018.68 9349.44 9327.78 9753.63 10443.50 10853.87 10704.02 [9] 11052.23 10935.47 10714.03 10394.48 10817.90 11251.20 11281.26 10539.68 [17] 10483.39 10947.43 10580.27 10582.92 10654.41 11014.51 10967.87 10433.56 [25] 10665.78 10666.71 10682.74 10777.22 10052.60 10213.97 10546.82 10767.20 [33] 10444.50 10314.68 9042.56 9220.75 9721.84 9978.53 9923.81 9892.56 [41] 10500.98 10179.35 10080.48 9492.44 8616.49 8685.40 8160.67 8048.10 [49] 8641.21 8526.63 8474.21 7916.13 7977.64 8334.59 8623.36 9098.03 [57] 9154.34 9284.73 9492.49 9682.35 9762.12 10124.63 10540.05 10601.61 [65] 10323.73 10418.40 10092.96 10364.91 10152.09 10032.80 10204.59 10001.60 [73] 10411.75 10673.38 10539.51 10723.78 10682.06 10283.19 10377.18 10486.64 [81] 10545.38 10554.27 10532.54 10324.31 10695.25 10827.81 10872.48 10971.19 [89] 11145.65 11234.68 11333.88 10997.97 11036.89 11257.35 11533.59 11963.12 [97] 12185.15 12377.62 12512.89 12631.48 12268.53 12754.80 13407.75 13480.21 [105] 13673.28 13239.71 13557.69 13901.28 13200.58 13167.71 13196.78 13171.08 [113] 13193.80 13173.71 13191.48 13175.76 13189.66 13177.37 13188.24 13178.63 [121] 13187.13 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 110 End = 121 Frequency = 1 [1] 0.02532433 0.03761815 0.04557412 0.05321717 0.05923619 0.06519599 [7] 0.07027249 0.07530056 0.07978514 0.08420675 0.08827123 0.09226105 > postscript(file="/var/www/html/rcomp/tmp/1oehk1229443637.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/230dp1229443637.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/3y69a1229443637.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/4zjan1229443637.tab") > > system("convert tmp/1oehk1229443637.ps tmp/1oehk1229443637.png") > system("convert tmp/230dp1229443637.ps tmp/230dp1229443637.png") > > > proc.time() user system elapsed 1.553 0.527 3.377