R version 2.9.0 (2009-04-17) Copyright (C) 2009 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(107.11,107.57,107.81,108.75,109.43,109.62,109.54,109.53,109.84,109.67,109.79,109.56,110.22,110.40,110.69,110.72,110.89,110.58,110.94,110.91,111.22,111.09,111.00,111.06,111.55,112.32,112.64,112.36,112.04,112.37,112.59,112.89,113.22,112.85,113.06,112.99,113.32,113.74,113.91,114.52,114.96,114.91,115.30,115.44,115.52,116.08,115.94,115.56,115.88,116.66,117.41,117.68,117.85,118.21,118.92,119.03,119.17,118.95,118.92,118.90) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '0' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '1' > par1 = '24' > par1 <- as.numeric(par1) #cut off periods > par1 <- 28 > 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 > par6 <- 3 > par7 <- as.numeric(par7) #q > par7 <- 3 > 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 ma3 sma1 -0.5785 0.9365 0.6405 0.8129 -0.7783 -0.9876 0.7080 s.e. 0.1875 0.0427 0.1919 0.1558 0.1653 0.1588 0.6415 sigma^2 estimated as 0.05763: log likelihood = -5.75, aic = 27.5 Warning messages: 1: In log(s2) : NaNs produced 2: In log(s2) : NaNs produced 3: 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,par1)) $pred Time Series: Start = 33 End = 60 Frequency = 1 [1] 112.9449 113.2105 113.0822 113.4530 113.5706 114.2516 114.4501 114.5575 [9] 114.4934 114.9712 115.0684 115.3550 115.4543 115.7151 115.8240 116.0689 [17] 116.1963 116.4217 116.5674 116.7758 116.9361 117.1319 117.3023 117.4897 [25] 117.6662 117.8488 118.0285 118.2086 $se Time Series: Start = 33 End = 60 Frequency = 1 [1] 0.2553552 0.4021206 0.5169622 0.5942270 0.6939915 0.7511962 0.8334289 [8] 0.8864108 0.9586212 1.0107402 1.0752837 1.1273856 1.2529661 1.3756396 [15] 1.4998112 1.6039599 1.7219876 1.8184191 1.9292055 2.0223774 2.1265747 [22] 2.2182434 2.3170983 2.4078443 2.5026314 2.5925691 2.6843665 2.7734735 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 112.4444 112.4223 112.0689 112.2883 112.2104 112.7793 112.8166 112.8201 [9] 112.6146 112.9901 112.9608 113.1453 112.9984 113.0189 112.8844 112.9251 [17] 112.8212 112.8576 112.7862 112.8119 112.7680 112.7841 112.7607 112.7703 [25] 112.7611 112.7673 112.7672 112.7726 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 33 End = 60 Frequency = 1 [1] 113.4454 113.9986 114.0954 114.6177 114.9309 115.7239 116.0836 116.2948 [9] 116.3723 116.9522 117.1760 117.5646 117.9101 118.4114 118.7636 119.2127 [17] 119.5714 119.9858 120.3487 120.7397 121.1042 121.4796 121.8438 122.2091 [25] 122.5714 122.9302 123.2899 123.6446 > 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] 107.1100 107.5700 107.8100 108.7500 109.4300 109.6200 109.5400 109.5300 [9] 109.8400 109.6700 109.7900 109.5600 110.2200 110.4000 110.6900 110.7200 [17] 110.8900 110.5800 110.9400 110.9100 111.2200 111.0900 111.0000 111.0600 [25] 111.5500 112.3200 112.6400 112.3600 112.0400 112.3700 112.5900 112.8900 [33] 112.9449 113.2105 113.0822 113.4530 113.5706 114.2516 114.4501 114.5575 [41] 114.4934 114.9712 115.0684 115.3550 115.4543 115.7151 115.8240 116.0689 [49] 116.1963 116.4217 116.5674 116.7758 116.9361 117.1319 117.3023 117.4897 [57] 117.6662 117.8488 118.0285 118.2086 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 33 End = 60 Frequency = 1 [1] 0.002260882 0.003551973 0.004571563 0.005237650 0.006110660 0.006574930 [7] 0.007282029 0.007737697 0.008372717 0.008791249 0.009344735 0.009773186 [13] 0.010852488 0.011888160 0.012949054 0.013819034 0.014819645 0.015619248 [19] 0.016550124 0.017318463 0.018185778 0.018937999 0.019753228 0.020494087 [25] 0.021268905 0.021999116 0.022743372 0.023462539 > postscript(file="/var/www/html/rcomp/tmp/18csg1260632135.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.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/html/rcomp/tmp/2gxsf1260632135.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: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/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/3d39z1260632135.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/html/rcomp/tmp/4u57p1260632135.tab") > try(system("convert tmp/18csg1260632135.ps tmp/18csg1260632135.png",intern=TRUE)) character(0) > try(system("convert tmp/2gxsf1260632135.ps tmp/2gxsf1260632135.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.434 0.317 1.575