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.3866 + ,1.3582 + ,1.3332 + ,1.3595 + ,1.3617 + ,1.3684 + ,1.3394 + ,1.3262 + ,1.3173 + ,1.3085 + ,1.327 + ,1.3182 + ,1.293 + ,1.291 + ,1.2984 + ,1.2795 + ,1.299 + ,1.3174 + ,1.326 + ,1.3111 + ,1.2816 + ,1.276 + ,1.2849 + ,1.2818 + ,1.2829 + ,1.2796 + ,1.3008 + ,1.2967 + ,1.2938 + ,1.2833 + ,1.2823 + ,1.2765 + ,1.2634 + ,1.2596 + ,1.2705 + ,1.2591 + ,1.2798 + ,1.2763 + ,1.2795 + ,1.2782 + ,1.2644 + ,1.2596 + ,1.2615 + ,1.2555 + ,1.2555 + ,1.2658 + ,1.2565 + ,1.2783 + ,1.2786 + ,1.2782 + ,1.2905 + ,1.3042 + ,1.2942 + ,1.313 + ,1.3671 + ,1.3549 + ,1.3558 + ,1.3507 + ,1.3494 + ,1.3607 + ,1.3295 + ,1.3193 + ,1.3308 + ,1.3246 + ,1.3392 + ,1.3425 + ,1.3496 + ,1.3255 + ,1.3231 + ,1.3273 + ,1.3276 + ,1.3173 + ,1.3196 + ,1.3058 + ,1.2966 + ,1.2932 + ,1.2947 + ,1.305 + ,1.3232 + ,1.3125 + ,1.2992 + ,1.3266 + ,1.3275 + ,1.3223 + ,1.3403 + ,1.3322 + ,1.3363 + ,1.3425 + ,1.3574 + ,1.3683 + ,1.3623 + ,1.3563 + ,1.3518 + ,1.3494 + ,1.3612 + ,1.369 + ,1.3771 + ,1.3972 + ,1.401 + ,1.3908 + ,1.3901 + ,1.3856 + ,1.4098 + ,1.422 + ,1.4238 + ,1.4207 + ,1.4095 + ,1.4177 + ,1.3866 + ,1.3959 + ,1.4102 + ,1.3969 + ,1.4004 + ,1.385 + ,1.389 + ,1.384 + ,1.392 + ,1.3932 + ,1.3858 + ,1.3978 + ,1.4029 + ,1.394 + ,1.4096 + ,1.4058 + ,1.4134 + ,1.4096 + ,1.4049 + ,1.4009 + ,1.3897 + ,1.4019 + ,1.3901 + ,1.399 + ,1.3901 + ,1.3975 + ,1.3991 + ,1.4089 + ,1.413 + ,1.409 + ,1.4217 + ,1.4223 + ,1.4191 + ,1.4229 + ,1.4227 + ,1.4269 + ,1.4229 + ,1.4104 + ,1.4053 + ,1.4138 + ,1.4303 + ,1.4384 + ,1.441 + ,1.437 + ,1.4357 + ,1.4202 + ,1.4166 + ,1.417 + ,1.4293 + ,1.4294 + ,1.4072 + ,1.4101 + ,1.4112 + ,1.4243 + ,1.433 + ,1.4323 + ,1.4324 + ,1.427 + ,1.4268 + ,1.4364 + ,1.4272 + ,1.4314 + ,1.422 + ,1.4335 + ,1.4262 + ,1.433 + ,1.4473 + ,1.4522 + ,1.4545 + ,1.4594 + ,1.4561 + ,1.4611 + ,1.4671 + ,1.4712 + ,1.4705 + ,1.4658 + ,1.478 + ,1.4783 + ,1.4768 + ,1.467 + ,1.465 + ,1.4549 + ,1.4643 + ,1.4539 + ,1.4537 + ,1.4616 + ,1.4722 + ,1.4694 + ,1.4763 + ,1.475 + ,1.4765 + ,1.4864 + ,1.4881 + ,1.4864 + ,1.4869 + ,1.4918 + ,1.4971 + ,1.4921 + ,1.5 + ,1.502 + ,1.5019 + ,1.4874 + ,1.4785 + ,1.4788 + ,1.48 + ,1.4772 + ,1.4658 + ,1.4761 + ,1.4867 + ,1.4862 + ,1.4984 + ,1.4966 + ,1.5037 + ,1.4922 + ,1.4868 + ,1.4965 + ,1.4875 + ,1.4957 + ,1.4863 + ,1.4815 + ,1.4968 + ,1.4969 + ,1.5083 + ,1.5071 + ,1.4918 + ,1.5023 + ,1.5074 + ,1.509 + ,1.512 + ,1.5068 + ,1.4787 + ,1.4774 + ,1.4768 + ,1.473 + ,1.4757 + ,1.4647 + ,1.4541 + ,1.456 + ,1.4343 + ,1.4337 + ,1.4368 + ,1.4279 + ,1.4276 + ,1.4398 + ,1.4405 + ,1.4433 + ,1.4338 + ,1.4406 + ,1.4389 + ,1.4442 + ,1.435 + ,1.4304 + ,1.4273 + ,1.4528 + ,1.4481 + ,1.4563 + ,1.4486 + ,1.4374 + ,1.4369 + ,1.4279 + ,1.4132 + ,1.4064 + ,1.4135 + ,1.4151 + ,1.4085 + ,1.4072 + ,1.3999 + ,1.3966 + ,1.3913 + ,1.3937 + ,1.3984 + ,1.3847 + ,1.3691 + ,1.3675 + ,1.376 + ,1.374 + ,1.3718 + ,1.3572 + ,1.3607 + ,1.3649 + ,1.3726 + ,1.3567 + ,1.3519 + ,1.3626 + ,1.3577 + ,1.3547 + ,1.3489 + ,1.357 + ,1.3525 + ,1.3548 + ,1.3641 + ,1.3668 + ,1.3582 + ,1.3662 + ,1.3557 + ,1.361 + ,1.3657 + ,1.3765 + ,1.3705 + ,1.3723 + ,1.3756 + ,1.366 + ,1.3548 + ,1.3471 + ,1.3519 + ,1.3338 + ,1.3356 + ,1.3353 + ,1.3471 + ,1.3482 + ,1.3479 + ,1.3468 + ,1.3396 + ,1.334 + ,1.3296 + ,1.3384 + ,1.3585 + ,1.3583 + ,1.3615 + ,1.3544 + ,1.3535 + ,1.3432 + ,1.3486 + ,1.3373 + ,1.3339 + ,1.3311 + ,1.3321 + ,1.329 + ,1.3245 + ,1.3256 + ,1.3315 + ,1.3238 + ,1.3089 + ,1.2924 + ,1.2727 + ,1.2746 + ,1.2969 + ,1.2698 + ,1.2686 + ,1.2587 + ,1.2492 + ,1.2349 + ,1.2428 + ,1.227 + ,1.2334 + ,1.2497 + ,1.236 + ,1.2223 + ,1.2309 + ,1.2255 + ,1.2384 + ,1.2307 + ,1.2155 + ,1.2218 + ,1.2268 + ,1.206 + ,1.1959 + ,1.1942) > par10 = 'FALSE' > par9 = '0' > par8 = '1' > par7 = '0' > par6 = '0' > par5 = '1' > par4 = '0' > par3 = '1' > par2 = '1.9' > par1 = '0' > par1 <- 30 #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 <- 5 #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: sar1 0.0797 s.e. 0.0558 sigma^2 estimated as 0.000689: log likelihood = 744.08, aic = -1484.17 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 337 End = 366 Frequency = 1 [1] 1.714481 1.713813 1.713264 1.713460 1.712853 1.712676 1.712622 1.712579 [9] 1.712594 1.712546 1.712532 1.712528 1.712524 1.712525 1.712521 1.712520 [17] 1.712520 1.712520 1.712520 1.712519 1.712519 1.712519 1.712519 1.712519 [25] 1.712519 1.712519 1.712519 1.712519 1.712519 1.712519 $se Time Series: Start = 337 End = 366 Frequency = 1 [1] 0.02624882 0.03712144 0.04546429 0.05249764 0.05869415 0.06517812 [7] 0.07107300 0.07651507 0.08159497 0.08637664 0.09095924 0.09532179 [13] 0.09949323 0.10349668 0.10735093 0.11107492 0.11467805 0.11817137 [19] 0.12156434 0.12486515 0.12808116 0.13121837 0.13428231 0.13727788 [25] 0.14020946 0.14308101 0.14589605 0.14865780 0.15136916 0.15403280 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 337 End = 366 Frequency = 1 [1] 1.663034 1.641055 1.624154 1.610565 1.597813 1.584927 1.573319 1.562609 [9] 1.552668 1.543248 1.534252 1.525697 1.517517 1.509672 1.502114 1.494813 [17] 1.487751 1.480904 1.474254 1.467784 1.461480 1.455331 1.449326 1.443455 [25] 1.437709 1.432081 1.426563 1.421150 1.415836 1.410615 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 337 End = 366 Frequency = 1 [1] 1.765929 1.786571 1.802374 1.816356 1.827894 1.840425 1.851925 1.862548 [9] 1.872520 1.881844 1.890812 1.899358 1.907531 1.915379 1.922929 1.930227 [17] 1.937289 1.944136 1.950786 1.957255 1.963558 1.969707 1.975713 1.981584 [25] 1.987330 1.992958 1.998476 2.003889 2.009203 2.014424 > 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.386600 1.358200 1.333200 1.359500 1.361700 1.368400 1.339400 1.326200 [9] 1.317300 1.308500 1.327000 1.318200 1.293000 1.291000 1.298400 1.279500 [17] 1.299000 1.317400 1.326000 1.311100 1.281600 1.276000 1.284900 1.281800 [25] 1.282900 1.279600 1.300800 1.296700 1.293800 1.283300 1.282300 1.276500 [33] 1.263400 1.259600 1.270500 1.259100 1.279800 1.276300 1.279500 1.278200 [41] 1.264400 1.259600 1.261500 1.255500 1.255500 1.265800 1.256500 1.278300 [49] 1.278600 1.278200 1.290500 1.304200 1.294200 1.313000 1.367100 1.354900 [57] 1.355800 1.350700 1.349400 1.360700 1.329500 1.319300 1.330800 1.324600 [65] 1.339200 1.342500 1.349600 1.325500 1.323100 1.327300 1.327600 1.317300 [73] 1.319600 1.305800 1.296600 1.293200 1.294700 1.305000 1.323200 1.312500 [81] 1.299200 1.326600 1.327500 1.322300 1.340300 1.332200 1.336300 1.342500 [89] 1.357400 1.368300 1.362300 1.356300 1.351800 1.349400 1.361200 1.369000 [97] 1.377100 1.397200 1.401000 1.390800 1.390100 1.385600 1.409800 1.422000 [105] 1.423800 1.420700 1.409500 1.417700 1.386600 1.395900 1.410200 1.396900 [113] 1.400400 1.385000 1.389000 1.384000 1.392000 1.393200 1.385800 1.397800 [121] 1.402900 1.394000 1.409600 1.405800 1.413400 1.409600 1.404900 1.400900 [129] 1.389700 1.401900 1.390100 1.399000 1.390100 1.397500 1.399100 1.408900 [137] 1.413000 1.409000 1.421700 1.422300 1.419100 1.422900 1.422700 1.426900 [145] 1.422900 1.410400 1.405300 1.413800 1.430300 1.438400 1.441000 1.437000 [153] 1.435700 1.420200 1.416600 1.417000 1.429300 1.429400 1.407200 1.410100 [161] 1.411200 1.424300 1.433000 1.432300 1.432400 1.427000 1.426800 1.436400 [169] 1.427200 1.431400 1.422000 1.433500 1.426200 1.433000 1.447300 1.452200 [177] 1.454500 1.459400 1.456100 1.461100 1.467100 1.471200 1.470500 1.465800 [185] 1.478000 1.478300 1.476800 1.467000 1.465000 1.454900 1.464300 1.453900 [193] 1.453700 1.461600 1.472200 1.469400 1.476300 1.475000 1.476500 1.486400 [201] 1.488100 1.486400 1.486900 1.491800 1.497100 1.492100 1.500000 1.502000 [209] 1.501900 1.487400 1.478500 1.478800 1.480000 1.477200 1.465800 1.476100 [217] 1.486700 1.486200 1.498400 1.496600 1.503700 1.492200 1.486800 1.496500 [225] 1.487500 1.495700 1.486300 1.481500 1.496800 1.496900 1.508300 1.507100 [233] 1.491800 1.502300 1.507400 1.509000 1.512000 1.506800 1.478700 1.477400 [241] 1.476800 1.473000 1.475700 1.464700 1.454100 1.456000 1.434300 1.433700 [249] 1.436800 1.427900 1.427600 1.439800 1.440500 1.443300 1.433800 1.440600 [257] 1.438900 1.444200 1.435000 1.430400 1.427300 1.452800 1.448100 1.456300 [265] 1.448600 1.437400 1.436900 1.427900 1.413200 1.406400 1.413500 1.415100 [273] 1.408500 1.407200 1.399900 1.396600 1.391300 1.393700 1.398400 1.384700 [281] 1.369100 1.367500 1.376000 1.374000 1.371800 1.357200 1.360700 1.364900 [289] 1.372600 1.356700 1.351900 1.362600 1.357700 1.354700 1.348900 1.357000 [297] 1.352500 1.354800 1.364100 1.366800 1.358200 1.366200 1.355700 1.361000 [305] 1.365700 1.376500 1.370500 1.372300 1.375600 1.366000 1.354800 1.347100 [313] 1.351900 1.333800 1.335600 1.335300 1.347100 1.348200 1.347900 1.346800 [321] 1.339600 1.334000 1.329600 1.338400 1.358500 1.358300 1.361500 1.354400 [329] 1.353500 1.343200 1.348600 1.337300 1.333900 1.331100 1.332100 1.329000 [337] 1.328091 1.327818 1.327595 1.327674 1.327427 1.327354 1.327333 1.327315 [345] 1.327321 1.327302 1.327296 1.327294 1.327293 1.327293 1.327292 1.327291 [353] 1.327291 1.327291 1.327291 1.327291 1.327291 1.327291 1.327291 1.327291 [361] 1.327291 1.327291 1.327291 1.327291 1.327291 1.327291 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 337 End = 366 Frequency = 1 [1] 0.00800149 0.01128778 0.01379887 0.01590264 0.01775740 0.01968819 [7] 0.02143709 0.02304709 0.02454529 0.02595300 0.02729856 0.02857657 [13] 0.02979605 0.03096401 0.03208639 0.03316882 0.03421426 0.03522612 [19] 0.03620728 0.03716029 0.03808737 0.03899038 0.03987101 0.04073077 [25] 0.04157099 0.04239289 0.04319755 0.04398596 0.04475900 0.04551749 > postscript(file="/var/www/html/rcomp/tmp/1qups1292887600.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/html/rcomp/tmp/2ev431292887600.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/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/33e1x1292887600.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/4pxhl1292887600.tab") > > try(system("convert tmp/1qups1292887600.ps tmp/1qups1292887600.png",intern=TRUE)) character(0) > try(system("convert tmp/2ev431292887600.ps tmp/2ev431292887600.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.729 0.366 1.610