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(106.2 + ,101.6 + ,99 + ,96.4 + ,94 + ,93.2 + ,103 + ,103.6 + ,103.2 + ,102.2 + ,100 + ,99.6 + ,98.8 + ,95.2 + ,91.6 + ,88.6 + ,86 + ,84.8 + ,95.2 + ,96.2 + ,94 + ,92 + ,90.2 + ,90 + ,88.8 + ,85.8 + ,84.2 + ,80 + ,77.8 + ,76.8 + ,86.4 + ,89.2 + ,86.2 + ,84.6 + ,83.2 + ,83.2 + ,82.6 + ,79.8 + ,77.2 + ,74.8 + ,73 + ,73 + ,83.6 + ,85.6 + ,84.8 + ,84.2 + ,83.4 + ,84.6 + ,84.6 + ,83.8 + ,81.2 + ,79.6 + ,78 + ,78.2 + ,88.8 + ,92 + ,91 + ,91.2 + ,90.4 + ,91.8 + ,92.2 + ,90.2 + ,88.6 + ,87.8 + ,86 + ,87.2 + ,97.6 + ,101.2 + ,100.4 + ,100.2 + ,100.2 + ,103 + ,104.2 + ,104 + ,102.4 + ,101.8 + ,101 + ,102.2 + ,114 + ,118.4 + ,118.8 + ,117.2 + ,117.2 + ,118.4 + ,118.8 + ,117.2 + ,114.4 + ,112.6 + ,111 + ,110.8 + ,120.2 + ,124.4 + ,123.4 + ,121.2 + ,119 + ,119.8 + ,120 + ,118.4 + ,115 + ,113.4 + ,111 + ,111 + ,121.6 + ,126.2 + ,125.8 + ,124.8 + ,122 + ,123.2 + ,124.2 + ,120.8 + ,116.8 + ,114.8 + ,111 + ,109 + ,119.8 + ,124 + ,121.6 + ,118 + ,115.8 + ,116 + ,115.8 + ,114.4 + ,112 + ,110.2 + ,107.4 + ,108.2 + ,117.6 + ,121.4 + ,119.8 + ,115.6 + ,112.6 + ,113.2 + ,112.2 + ,110.8 + ,108 + ,105.2 + ,102.4 + ,101 + ,110.8 + ,116.8 + ,113.8 + ,108 + ,104.4 + ,105.2 + ,105.4 + ,103.2 + ,100.6 + ,97.8 + ,95.8 + ,95 + ,104.8 + ,110.4 + ,106.4 + ,102.2 + ,98.4 + ,98.4 + ,98.6 + ,96.2 + ,92.4 + ,91.4 + ,88.4 + ,87.8 + ,97.6 + ,104.2 + ,100.2 + ,97 + ,92.8 + ,92 + ,93.4 + ,92 + ,89.6 + ,88.6 + ,87.2 + ,86.2 + ,96.8 + ,102 + ,102.6 + ,100.6 + ,94.2 + ,94.2 + ,95.2 + ,95 + ,94 + ,92.2 + ,91 + ,91.2 + ,103.4 + ,105 + ,104.6 + ,103.8 + ,101.8 + ,102.4 + ,103.8 + ,103.4 + ,102 + ,101.8 + ,100.2 + ,101.4 + ,113.8 + ,116 + ,115.6 + ,113 + ,109.4 + ,111 + ,112.4 + ,112.2 + ,111 + ,108.8 + ,107.4 + ,108.6 + ,118.8 + ,122.2 + ,122.6 + ,122.2 + ,118.8 + ,119 + ,118.2 + ,117.8 + ,116.8 + ,114.6 + ,113.4 + ,113.8 + ,124.2 + ,125.8 + ,125.6 + ,122.4 + ,119 + ,119.4 + ,118.6 + ,118 + ,116 + ,114.8 + ,114.6 + ,114.6 + ,124 + ,125.2 + ,124 + ,117.6 + ,113.2 + ,111.4 + ,112.2 + ,109.8 + ,106.4 + ,105.2 + ,102.2 + ,99.8 + ,111 + ,113 + ,108.4 + ,105.4 + ,102 + ,102.8) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '2' > par6 = '3' > par5 = '12' > par4 = '1' > 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 ar2 ar3 ma1 ma2 sma1 1.0727 -0.2283 0.1099 -1.0040 0.1940 -0.4698 s.e. 0.7251 0.6684 0.0900 0.7295 0.6269 0.0720 sigma^2 estimated as 1.114: log likelihood = -335.87, aic = 685.74 Warning message: In arima(x[1:nx], order = c(par6, par3, par7), seasonal = list(order = c(par8, : possible convergence problem: optim gave code=1 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 241 End = 252 Frequency = 1 [1] 109.97025 108.38788 105.61801 102.97687 101.19630 100.49236 109.54032 [8] 110.35516 108.78577 103.49403 98.75936 97.27665 $se Time Series: Start = 241 End = 252 Frequency = 1 [1] 1.055482 1.544833 1.937649 2.340938 2.762365 3.193409 3.631314 4.075522 [9] 4.525202 4.979341 5.437014 5.897411 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 241 End = 252 Frequency = 1 [1] 107.90150 105.36001 101.82022 98.38863 95.78207 94.23328 102.42294 [8] 102.36714 99.91638 93.73452 88.10281 85.71772 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 241 End = 252 Frequency = 1 [1] 112.0390 111.4158 109.4158 107.5651 106.6105 106.7514 116.6577 118.3432 [9] 117.6552 113.2535 109.4159 108.8356 > 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] 106.20000 101.60000 99.00000 96.40000 94.00000 93.20000 103.00000 [8] 103.60000 103.20000 102.20000 100.00000 99.60000 98.80000 95.20000 [15] 91.60000 88.60000 86.00000 84.80000 95.20000 96.20000 94.00000 [22] 92.00000 90.20000 90.00000 88.80000 85.80000 84.20000 80.00000 [29] 77.80000 76.80000 86.40000 89.20000 86.20000 84.60000 83.20000 [36] 83.20000 82.60000 79.80000 77.20000 74.80000 73.00000 73.00000 [43] 83.60000 85.60000 84.80000 84.20000 83.40000 84.60000 84.60000 [50] 83.80000 81.20000 79.60000 78.00000 78.20000 88.80000 92.00000 [57] 91.00000 91.20000 90.40000 91.80000 92.20000 90.20000 88.60000 [64] 87.80000 86.00000 87.20000 97.60000 101.20000 100.40000 100.20000 [71] 100.20000 103.00000 104.20000 104.00000 102.40000 101.80000 101.00000 [78] 102.20000 114.00000 118.40000 118.80000 117.20000 117.20000 118.40000 [85] 118.80000 117.20000 114.40000 112.60000 111.00000 110.80000 120.20000 [92] 124.40000 123.40000 121.20000 119.00000 119.80000 120.00000 118.40000 [99] 115.00000 113.40000 111.00000 111.00000 121.60000 126.20000 125.80000 [106] 124.80000 122.00000 123.20000 124.20000 120.80000 116.80000 114.80000 [113] 111.00000 109.00000 119.80000 124.00000 121.60000 118.00000 115.80000 [120] 116.00000 115.80000 114.40000 112.00000 110.20000 107.40000 108.20000 [127] 117.60000 121.40000 119.80000 115.60000 112.60000 113.20000 112.20000 [134] 110.80000 108.00000 105.20000 102.40000 101.00000 110.80000 116.80000 [141] 113.80000 108.00000 104.40000 105.20000 105.40000 103.20000 100.60000 [148] 97.80000 95.80000 95.00000 104.80000 110.40000 106.40000 102.20000 [155] 98.40000 98.40000 98.60000 96.20000 92.40000 91.40000 88.40000 [162] 87.80000 97.60000 104.20000 100.20000 97.00000 92.80000 92.00000 [169] 93.40000 92.00000 89.60000 88.60000 87.20000 86.20000 96.80000 [176] 102.00000 102.60000 100.60000 94.20000 94.20000 95.20000 95.00000 [183] 94.00000 92.20000 91.00000 91.20000 103.40000 105.00000 104.60000 [190] 103.80000 101.80000 102.40000 103.80000 103.40000 102.00000 101.80000 [197] 100.20000 101.40000 113.80000 116.00000 115.60000 113.00000 109.40000 [204] 111.00000 112.40000 112.20000 111.00000 108.80000 107.40000 108.60000 [211] 118.80000 122.20000 122.60000 122.20000 118.80000 119.00000 118.20000 [218] 117.80000 116.80000 114.60000 113.40000 113.80000 124.20000 125.80000 [225] 125.60000 122.40000 119.00000 119.40000 118.60000 118.00000 116.00000 [232] 114.80000 114.60000 114.60000 124.00000 125.20000 124.00000 117.60000 [239] 113.20000 111.40000 109.97025 108.38788 105.61801 102.97687 101.19630 [246] 100.49236 109.54032 110.35516 108.78577 103.49403 98.75936 97.27665 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 241 End = 252 Frequency = 1 [1] 0.009597885 0.014252824 0.018345820 0.022732663 0.027297092 0.031777633 [7] 0.033150479 0.036930959 0.041597373 0.048112352 0.055053155 0.060625150 > postscript(file="/var/www/html/rcomp/tmp/1fzpe1229616240.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/2dqm11229616241.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/370b11229616241.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/4sonb1229616241.tab") > > system("convert tmp/1fzpe1229616240.ps tmp/1fzpe1229616240.png") > system("convert tmp/2dqm11229616241.ps tmp/2dqm11229616241.png") > > > proc.time() user system elapsed 6.582 0.338 8.114