R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-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(236.422 + ,250.580 + ,279.515 + ,264.417 + ,283.706 + ,281.288 + ,271.146 + ,283.944 + ,269.155 + ,270.899 + ,276.507 + ,319.957 + ,250.746 + ,247.772 + ,280.449 + ,274.925 + ,296.013 + ,287.881 + ,279.098 + ,294.763 + ,261.924 + ,291.596 + ,287.537 + ,326.201 + ,255.598 + ,253.086 + ,285.261 + ,284.747 + ,300.402 + ,288.854 + ,295.433 + ,307.256 + ,273.189 + ,287.540 + ,290.705 + ,337.006 + ,268.335 + ,259.060 + ,293.703 + ,294.262 + ,312.404 + ,301.014 + ,309.942 + ,317.079 + ,293.912 + ,304.060 + ,301.299 + ,357.634 + ,281.493 + ,282.478 + ,319.111 + ,315.223 + ,328.445 + ,321.081 + ,328.040 + ,326.362 + ,313.566 + ,319.768 + ,324.315 + ,387.243 + ,293.308 + ,295.109 + ,339.190 + ,335.678 + ,345.401 + ,351.002 + ,351.889 + ,355.773 + ,333.363 + ,336.214 + ,343.910 + ,405.788 + ,318.682 + ,314.189 + ,362.141 + ,351.811 + ,373.727 + ,366.795 + ,362.393 + ,376.006 + ,346.423 + ,349.007 + ,357.224 + ,418.473 + ,329.169 + ,323.456 + ,374.439 + ,358.806 + ,391.816 + ,376.944 + ,372.665 + ,388.357 + ,354.241 + ,368.982 + ,378.233 + ,426.699 + ,343.241 + ,344.577 + ,373.623 + ,369.688 + ,398.816 + ,379.387 + ,384.666 + ,383.879 + ,351.578 + ,350.920 + ,336.629 + ,385.504 + ,311.330 + ,300.545 + ,329.718 + ,331.023 + ,348.944 + ,345.650 + ,349.260 + ,354.597 + ,325.769 + ,339.734 + ,340.543 + ,401.585 + ,315.998 + ,312.327 + ,362.217 + ,358.067 + ,367.321 + ,360.372 + ,363.830 + ,364.525 + ,347.945 + ,357.404 + ,368.182 + ,429.343) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '2' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '0.5' > par1 = '12' > 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 ma1 sma1 -0.8670 -0.4699 0.3799 -0.8165 s.e. 0.1834 0.0977 0.1978 0.1447 sigma^2 estimated as 0.03443: log likelihood = 21.68, aic = -33.35 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 121 End = 132 Frequency = 1 [1] 17.78830 17.67256 18.76486 18.58320 19.15573 18.94402 18.95631 19.16634 [9] 18.41613 18.65643 18.69648 20.12385 $se Time Series: Start = 121 End = 132 Frequency = 1 [1] 0.1863167 0.2093576 0.2265543 0.2646851 0.2820565 0.3020228 0.3240344 [8] 0.3404024 0.3581076 0.3750377 0.3902590 0.4056923 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 121 End = 132 Frequency = 1 [1] 17.42312 17.26222 18.32081 18.06442 18.60290 18.35206 18.32120 18.49915 [9] 17.71424 17.92135 17.93158 19.32869 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 121 End = 132 Frequency = 1 [1] 18.15348 18.08290 19.20891 19.10198 19.70856 19.53599 19.59142 19.83353 [9] 19.11802 19.39150 19.46139 20.91900 > 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] 236.4220 250.5800 279.5150 264.4170 283.7060 281.2880 271.1460 283.9440 [9] 269.1550 270.8990 276.5070 319.9570 250.7460 247.7720 280.4490 274.9250 [17] 296.0130 287.8810 279.0980 294.7630 261.9240 291.5960 287.5370 326.2010 [25] 255.5980 253.0860 285.2610 284.7470 300.4020 288.8540 295.4330 307.2560 [33] 273.1890 287.5400 290.7050 337.0060 268.3350 259.0600 293.7030 294.2620 [41] 312.4040 301.0140 309.9420 317.0790 293.9120 304.0600 301.2990 357.6340 [49] 281.4930 282.4780 319.1110 315.2230 328.4450 321.0810 328.0400 326.3620 [57] 313.5660 319.7680 324.3150 387.2430 293.3080 295.1090 339.1900 335.6780 [65] 345.4010 351.0020 351.8890 355.7730 333.3630 336.2140 343.9100 405.7880 [73] 318.6820 314.1890 362.1410 351.8110 373.7270 366.7950 362.3930 376.0060 [81] 346.4230 349.0070 357.2240 418.4730 329.1690 323.4560 374.4390 358.8060 [89] 391.8160 376.9440 372.6650 388.3570 354.2410 368.9820 378.2330 426.6990 [97] 343.2410 344.5770 373.6230 369.6880 398.8160 379.3870 384.6660 383.8790 [105] 351.5780 350.9200 336.6290 385.5040 311.3300 300.5450 329.7180 331.0230 [113] 348.9440 345.6500 349.2600 354.5970 325.7690 339.7340 340.5430 401.5850 [121] 316.4237 312.3193 352.1199 345.3353 366.9418 358.8760 359.3416 367.3486 [129] 339.1538 348.0623 349.5585 404.9692 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 121 End = 132 Frequency = 1 [1] 0.02116325 0.02396802 0.02443236 0.02888412 0.02987374 0.03238400 [7] 0.03476020 0.03613910 0.03963177 0.04099671 0.04260075 0.04111613 > postscript(file="/var/wessaorg/rcomp/tmp/1mniz1353764625.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/wessaorg/rcomp/tmp/2ov7t1353764626.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/32qxb1353764626.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/wessaorg/rcomp/tmp/4eue11353764626.tab") > > try(system("convert tmp/1mniz1353764625.ps tmp/1mniz1353764625.png",intern=TRUE)) character(0) > try(system("convert tmp/2ov7t1353764626.ps tmp/2ov7t1353764626.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.839 0.274 2.159