R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-pc-linux-gnu (32-bit) 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(100.21 + ,100.36 + ,100.62 + ,100.78 + ,100.93 + ,100.70 + ,100.00 + ,100.20 + ,99.68 + ,99.56 + ,100.06 + ,100.50 + ,99.30 + ,99.37 + ,99.20 + ,98.11 + ,97.60 + ,97.76 + ,98.06 + ,98.25 + ,98.50 + ,97.39 + ,98.09 + ,97.78 + ,98.12 + ,97.50 + ,97.30 + ,97.64 + ,96.88 + ,97.40 + ,98.27 + ,97.94 + ,98.61 + ,98.72 + ,98.62 + ,98.56 + ,98.06 + ,97.40 + ,97.76 + ,97.05 + ,97.85 + ,97.40 + ,97.27 + ,97.93 + ,98.60 + ,98.70 + ,98.88 + ,98.27 + ,97.85 + ,97.70 + ,96.97 + ,97.72 + ,97.66 + ,99.00 + ,98.86 + ,99.56 + ,100.19 + ,100.37 + ,100.01 + ,99.68 + ,99.78 + ,99.36 + ,99.21 + ,99.26 + ,99.26 + ,100.43 + ,101.50 + ,102.27 + ,102.69 + ,103.47 + ,104.02 + ,103.55 + ,103.77 + ,104.19 + ,103.64 + ,103.68 + ,105.39 + ,106.61 + ,108.12 + ,109.22 + ,110.17 + ,110.31 + ,111.06 + ,111.14 + ,111.39 + ,112.51 + ,111.28 + ,112.22 + ,113.19 + ,114.32 + ,115.34 + ,116.61 + ,117.83 + ,117.70 + ,118.51 + ,118.82 + ,119.49 + ,119.57 + ,120.00 + ,121.96 + ,121.45 + ,123.41 + ,124.44 + ,126.25 + ,127.41 + ,127.63 + ,129.19 + ,129.82 + ,130.45 + ,132.02 + ,132.72 + ,132.96 + ,135.06 + ,137.04 + ,137.83 + ,139.17 + ,140.35 + ,141.01 + ,141.89 + ,143.28 + ,142.90 + ,143.37 + ,145.03 + ,146.05 + ,147.39 + ,149.58 + ,151.02 + ,153.57 + ,155.60 + ,157.18 + ,158.77 + ,159.95 + ,161.34 + ,161.95 + ,163.36 + ,165.00 + ,166.65 + ,168.65 + ,170.29 + ,172.70 + ,173.79 + ,176.45 + ,177.58 + ,179.19 + ,181.01 + ,184.08 + ,185.63 + ,188.51 + ,190.18 + ,192.19 + ,193.47 + ,196.73 + ,200.39 + ,203.24 + ,205.53 + ,208.21 + ,208.88 + ,212.85 + ,216.41 + ,216.23 + ,219.27 + ,222.02 + ,224.89 + ,230.37 + ,232.29 + ,235.53 + ,236.92 + ,242.37 + ,242.75 + ,244.19 + ,247.94 + ,248.80 + ,250.18 + ,251.55 + ,254.40 + ,255.72 + ,257.69 + ,258.37 + ,258.22 + ,258.59 + ,257.45 + ,257.45 + ,256.73 + ,258.82 + ,257.99 + ,262.85 + ,262.58 + ,261.55 + ,261.25 + ,259.78 + ,256.26 + ,254.29 + ,248.50 + ,241.88 + ,238.53 + ,232.24 + ,232.46 + ,225.79 + ,221.63 + ,219.62 + ,215.94 + ,211.81 + ,205.57 + ,201.25 + ,194.70 + ,187.94 + ,185.61 + ,181.15 + ,186.50 + ,183.21 + ,182.61 + ,187.09 + ,189.10 + ,191.25 + ,190.74 + ,190.79) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '2' > par2 = '-1.0' > par1 = '0' > par1 <- 26 > 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 sar1 sma1 -0.1945 0.0539 0.1112 -0.9157 0.7935 -0.5786 s.e. 0.0881 0.0876 0.0791 0.0328 0.1076 0.1538 sigma^2 estimated as 1.953e-09: log likelihood = 1616.38, aic = -3218.77 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 191 End = 216 Frequency = 1 [1] 0.003849351 0.003843343 0.003856192 0.003853079 0.003850872 0.003848734 [7] 0.003850967 0.003833894 0.003832661 0.003829516 0.003829418 0.003834708 [13] 0.003840515 0.003838976 0.003852942 0.003855970 0.003859118 0.003862591 [19] 0.003869639 0.003861294 0.003865569 0.003868325 0.003873494 0.003882945 [25] 0.003892804 0.003896834 $se Time Series: Start = 191 End = 216 Frequency = 1 [1] 4.419072e-05 5.915016e-05 7.516052e-05 9.218530e-05 1.076423e-04 [6] 1.232519e-04 1.387808e-04 1.542244e-04 1.697886e-04 1.854604e-04 [11] 2.012838e-04 2.172929e-04 2.371412e-04 2.564192e-04 2.762134e-04 [16] 2.965050e-04 3.169154e-04 3.376397e-04 3.586310e-04 3.798769e-04 [21] 4.014030e-04 4.232029e-04 4.452806e-04 4.676392e-04 4.925952e-04 [26] 5.174264e-04 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 191 End = 216 Frequency = 1 [1] 0.003762737 0.003727409 0.003708877 0.003672395 0.003639893 0.003607161 [7] 0.003578956 0.003531614 0.003499875 0.003466013 0.003434902 0.003408814 [13] 0.003375719 0.003336394 0.003311564 0.003274820 0.003237964 0.003200817 [19] 0.003166722 0.003116735 0.003078819 0.003038847 0.003000744 0.002966372 [25] 0.002927318 0.002882678 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 191 End = 216 Frequency = 1 [1] 0.003935965 0.003959278 0.004003506 0.004033762 0.004061851 0.004090308 [7] 0.004122977 0.004136174 0.004165446 0.004193018 0.004223935 0.004260602 [13] 0.004305312 0.004341557 0.004394321 0.004437120 0.004480272 0.004524364 [19] 0.004572555 0.004605853 0.004652319 0.004697802 0.004746244 0.004799517 [25] 0.004858291 0.004910990 > 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] 100.2100 100.3600 100.6200 100.7800 100.9300 100.7000 100.0000 100.2000 [9] 99.6800 99.5600 100.0600 100.5000 99.3000 99.3700 99.2000 98.1100 [17] 97.6000 97.7600 98.0600 98.2500 98.5000 97.3900 98.0900 97.7800 [25] 98.1200 97.5000 97.3000 97.6400 96.8800 97.4000 98.2700 97.9400 [33] 98.6100 98.7200 98.6200 98.5600 98.0600 97.4000 97.7600 97.0500 [41] 97.8500 97.4000 97.2700 97.9300 98.6000 98.7000 98.8800 98.2700 [49] 97.8500 97.7000 96.9700 97.7200 97.6600 99.0000 98.8600 99.5600 [57] 100.1900 100.3700 100.0100 99.6800 99.7800 99.3600 99.2100 99.2600 [65] 99.2600 100.4300 101.5000 102.2700 102.6900 103.4700 104.0200 103.5500 [73] 103.7700 104.1900 103.6400 103.6800 105.3900 106.6100 108.1200 109.2200 [81] 110.1700 110.3100 111.0600 111.1400 111.3900 112.5100 111.2800 112.2200 [89] 113.1900 114.3200 115.3400 116.6100 117.8300 117.7000 118.5100 118.8200 [97] 119.4900 119.5700 120.0000 121.9600 121.4500 123.4100 124.4400 126.2500 [105] 127.4100 127.6300 129.1900 129.8200 130.4500 132.0200 132.7200 132.9600 [113] 135.0600 137.0400 137.8300 139.1700 140.3500 141.0100 141.8900 143.2800 [121] 142.9000 143.3700 145.0300 146.0500 147.3900 149.5800 151.0200 153.5700 [129] 155.6000 157.1800 158.7700 159.9500 161.3400 161.9500 163.3600 165.0000 [137] 166.6500 168.6500 170.2900 172.7000 173.7900 176.4500 177.5800 179.1900 [145] 181.0100 184.0800 185.6300 188.5100 190.1800 192.1900 193.4700 196.7300 [153] 200.3900 203.2400 205.5300 208.2100 208.8800 212.8500 216.4100 216.2300 [161] 219.2700 222.0200 224.8900 230.3700 232.2900 235.5300 236.9200 242.3700 [169] 242.7500 244.1900 247.9400 248.8000 250.1800 251.5500 254.4000 255.7200 [177] 257.6900 258.3700 258.2200 258.5900 257.4500 257.4500 256.7300 258.8200 [185] 257.9900 262.8500 262.5800 261.5500 261.2500 259.7800 259.7840 260.1901 [193] 259.3232 259.5327 259.6814 259.8257 259.6751 260.8314 260.9153 261.1296 [201] 261.1363 260.7761 260.3817 260.4862 259.5419 259.3381 259.1266 258.8936 [209] 258.4221 258.9805 258.6941 258.5098 258.1648 257.5365 256.8842 256.6186 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 191 End = 216 Frequency = 1 [1] 0.01174430 0.01586898 0.02026503 0.02510223 0.02957292 0.03416868 [7] 0.03877690 0.04366965 0.04851276 0.05350829 0.05859957 0.06374445 [13] 0.07024911 0.07685519 0.08340876 0.09054084 0.09787489 0.10548550 [19] 0.11324991 0.12188294 0.13037564 0.13926430 0.14839004 0.15764685 [25] 0.16827528 0.17949502 > postscript(file="/var/www/rcomp/tmp/1iyaq1292683237.ps",horizontal=F,onefile=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/rcomp/tmp/2wqpz1292683237.ps",horizontal=F,onefile=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/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/rcomp/tmp/3lr5a1292683237.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/rcomp/tmp/469lg1292683237.tab") > > try(system("convert tmp/1iyaq1292683237.ps tmp/1iyaq1292683237.png",intern=TRUE)) character(0) > try(system("convert tmp/2wqpz1292683237.ps tmp/2wqpz1292683237.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.250 0.420 1.675