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(1.19,1.18,1.18,1.33,1.3,1.25,1.22,1.17,1.18,1.19,1.21,1.21,1.2,1.2,1.29,1.83,1.85,1.54,1.52,1.43,1.4,1.4,1.39,1.37,1.33,1.36,1.34,1.75,1.84,1.73,1.63,1.5,1.45,1.38,1.38,1.27,1.31,1.29,1.32,1.48,1.39,1.45,1.44,1.44,1.42,1.39,1.4,1.39,1.3,1.32,1.35,1.51,1.37,1.25,1.15,1.09,1.09,1.06,1.02,1.01,1,1,1.05,1.3,1.34,1.24,1.22,1.06,1,1,1,1.01) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '1' > 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 0.4854 -0.1410 -0.6623 -0.3551 -0.3551 1.000 s.e. 0.1630 0.1747 0.1589 0.1771 0.1678 0.204 sigma^2 estimated as 0.009414: log likelihood = 25.29, aic = -36.58 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 45 End = 72 Frequency = 1 [1] 1.3587373 1.2124082 1.1420451 1.0293578 1.1285257 1.1842257 1.2444080 [8] 1.3691993 1.2077182 1.2179958 1.2172571 1.2761042 1.2550307 1.1234870 [15] 1.0128408 0.8386526 0.9038553 0.9784187 1.0932776 1.2644442 1.1052717 [22] 1.0739197 1.0219346 1.0602470 1.0640022 0.9813455 0.9045283 0.7234245 $se Time Series: Start = 45 End = 72 Frequency = 1 [1] 0.1010942 0.1533773 0.1702277 0.1869252 0.2016424 0.2260283 0.2525030 [8] 0.2774410 0.2940583 0.3051642 0.3141212 0.3254665 0.3837020 0.4465057 [15] 0.4825365 0.5123091 0.5356464 0.5653115 0.6002945 0.6389569 0.6720191 [22] 0.6974914 0.7170681 0.7361595 0.7895661 0.8523939 0.8995973 0.9423625 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 45 End = 72 Frequency = 1 [1] 1.16059267 0.91178859 0.80839880 0.66298441 0.73330651 0.74121019 [7] 0.74950217 0.82541504 0.63136399 0.61987397 0.60157956 0.63818985 [13] 0.50297479 0.24833580 0.06706928 -0.16547320 -0.14601153 -0.12959177 [19] -0.08329956 0.01208875 -0.21188570 -0.29316343 -0.38351898 -0.38262555 [25] -0.48354733 -0.68934649 -0.85868247 -1.12360603 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 45 End = 72 Frequency = 1 [1] 1.556882 1.513028 1.475691 1.395731 1.523745 1.627241 1.739314 1.912984 [9] 1.784072 1.816118 1.832935 1.914018 2.007087 1.998638 1.958612 1.842778 [17] 1.953722 2.086429 2.269855 2.516800 2.422429 2.441003 2.427388 2.503120 [25] 2.611552 2.652037 2.667739 2.570455 > 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] 1.1900000 1.1800000 1.1800000 1.3300000 1.3000000 1.2500000 1.2200000 [8] 1.1700000 1.1800000 1.1900000 1.2100000 1.2100000 1.2000000 1.2000000 [15] 1.2900000 1.8300000 1.8500000 1.5400000 1.5200000 1.4300000 1.4000000 [22] 1.4000000 1.3900000 1.3700000 1.3300000 1.3600000 1.3400000 1.7500000 [29] 1.8400000 1.7300000 1.6300000 1.5000000 1.4500000 1.3800000 1.3800000 [36] 1.2700000 1.3100000 1.2900000 1.3200000 1.4800000 1.3900000 1.4500000 [43] 1.4400000 1.4400000 1.3587373 1.2124082 1.1420451 1.0293578 1.1285257 [50] 1.1842257 1.2444080 1.3691993 1.2077182 1.2179958 1.2172571 1.2761042 [57] 1.2550307 1.1234870 1.0128408 0.8386526 0.9038553 0.9784187 1.0932776 [64] 1.2644442 1.1052717 1.0739197 1.0219346 1.0602470 1.0640022 0.9813455 [71] 0.9045283 0.7234245 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 45 End = 72 Frequency = 1 [1] 0.07440304 0.12650636 0.14905515 0.18159399 0.17867775 0.19086590 [7] 0.20291012 0.20263008 0.24348251 0.25054619 0.25805657 0.25504696 [13] 0.30573117 0.39742847 0.47641889 0.61087163 0.59262400 0.57778072 [19] 0.54907781 0.50532626 0.60801257 0.64948188 0.70167715 0.69432826 [25] 0.74207186 0.86859712 0.99454856 1.30264114 > postscript(file="/var/www/html/rcomp/tmp/1tc561261337532.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/2ruq01261337532.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/3zobh1261337532.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/4hah11261337532.tab") > > try(system("convert tmp/1tc561261337532.ps tmp/1tc561261337532.png",intern=TRUE)) character(0) > try(system("convert tmp/2ruq01261337532.ps tmp/2ruq01261337532.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.919 0.338 2.359