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(14.5,14.3,15.3,14.4,13.7,14.2,13.5,11.9,14.6,15.6,14.1,14.9,14.2,14.6,17.2,15.4,14.3,17.5,14.5,14.4,16.6,16.7,16.6,16.9,15.7,16.4,18.4,16.9,16.5,18.3,15.1,15.7,18.1,16.8,18.9,19,18.1,17.8,21.5,17.1,18.7,19,16.4,16.9,18.6,19.3,19.4,17.6,18.6,18.1,20.4,18.1,19.6,19.9,19.2,17.8,19.2,22,21.1,19.5,22.2,20.9,22.2,23.5,21.5,24.3,22.8,20.3,23.7,23.3,19.6,18,17.3,16.8,18.2,16.5,16,18.4) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '0' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '-0.2' > par1 = '12' > 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 sar1 sar2 -0.5229 0.2655 0.8568 -0.3427 -0.2665 -0.384 -0.6551 -0.9040 s.e. 0.2265 0.3256 0.2269 0.5279 0.3453 0.265 0.1105 0.0683 sma1 -0.8447 s.e. 2.6300 sigma^2 estimated as 3.501e-06: log likelihood = 141.67, aic = -263.34 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 51 End = 78 Frequency = 1 [1] 0.5469144 0.5501864 0.5669593 0.5439845 0.5584695 0.5713620 0.5445988 [8] 0.5437848 0.5513368 0.5413003 0.5560655 0.5461919 0.5317924 0.5451961 [15] 0.5454692 0.5327859 0.5563790 0.5485244 0.5374859 0.5406269 0.5290382 [22] 0.5308714 0.5328491 0.5356133 0.5171911 0.5360753 0.5320427 0.5266724 $se Time Series: Start = 51 End = 78 Frequency = 1 [1] 0.002377060 0.002257100 0.002686459 0.003066141 0.003035955 0.003617386 [7] 0.003557637 0.003596253 0.004067686 0.003987682 0.004175377 0.004274695 [13] 0.004249649 0.004524970 0.004404132 0.004394970 0.004629965 0.004556613 [19] 0.004666208 0.004691039 0.004663756 0.004907840 0.004825903 0.004822332 [25] 0.004837222 0.004791734 0.004814811 0.004772920 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 51 End = 78 Frequency = 1 [1] 0.5422554 0.5457625 0.5616938 0.5379748 0.5525190 0.5642719 0.5376259 [8] 0.5367361 0.5433641 0.5334844 0.5478818 0.5378135 0.5234631 0.5363271 [15] 0.5368371 0.5241717 0.5473042 0.5395935 0.5283402 0.5314324 0.5198972 [22] 0.5212521 0.5233903 0.5261615 0.5077102 0.5266835 0.5226057 0.5173175 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 51 End = 78 Frequency = 1 [1] 0.5515734 0.5546103 0.5722248 0.5499941 0.5644199 0.5784520 0.5515718 [8] 0.5508334 0.5593095 0.5491161 0.5642492 0.5545703 0.5401218 0.5540650 [15] 0.5541013 0.5414000 0.5654537 0.5574554 0.5466317 0.5498213 0.5381791 [22] 0.5404908 0.5423079 0.5450651 0.5266721 0.5454671 0.5414797 0.5360274 > 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] 14.50000 14.30000 15.30000 14.40000 13.70000 14.20000 13.50000 11.90000 [9] 14.60000 15.60000 14.10000 14.90000 14.20000 14.60000 17.20000 15.40000 [17] 14.30000 17.50000 14.50000 14.40000 16.60000 16.70000 16.60000 16.90000 [25] 15.70000 16.40000 18.40000 16.90000 16.50000 18.30000 15.10000 15.70000 [33] 18.10000 16.80000 18.90000 19.00000 18.10000 17.80000 21.50000 17.10000 [41] 18.70000 19.00000 16.40000 16.90000 18.60000 19.30000 19.40000 17.60000 [49] 18.60000 18.10000 20.43635 19.83585 17.07028 20.99266 18.40784 16.42266 [57] 20.87452 21.03123 19.62976 21.51834 18.80920 20.57186 23.51198 20.76044 [65] 20.70851 23.29360 18.75627 20.13818 22.29279 21.65269 24.13042 23.71664 [73] 23.27978 22.68523 27.02369 22.58765 23.45673 24.67727 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 51 End = 78 Frequency = 1 [1] 0.02229817 0.02101637 0.02436648 0.02914089 0.02807193 0.03286927 [7] 0.03395601 0.03439266 0.03854523 0.03848520 0.03926020 0.04099910 [13] 0.04190418 0.04360323 0.04235979 0.04332374 0.04372402 0.04364365 [19] 0.04571465 0.04568965 0.04645787 0.04884734 0.04779905 0.04750181 [25] 0.04945034 0.04714122 0.04775941 0.04783032 > postscript(file="/var/www/html/rcomp/tmp/1q8cr1260298380.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/2mmag1260298380.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/3mt1d1260298380.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/4rtrq1260298380.tab") > > system("convert tmp/1q8cr1260298380.ps tmp/1q8cr1260298380.png") > system("convert tmp/2mmag1260298380.ps tmp/2mmag1260298380.png") > > > proc.time() user system elapsed 4.937 0.893 5.783