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(2360,2214,2825,2355,2333,3016,2155,2172,2150,2533,2058,2160,2260,2498,2695,2799,2947,2930,2318,2540,2570,2669,2450,2842,3440,2678,2981,2260,2844,2546,2456,2295,2379,2479,2057,2280,2351,2276,2548,2311,2201,2725,2408,2139,1898,2537,2069,2063,2524,2437,2189,2793,2074,2622,2278,2144,2427,2139,1828,2072,1800) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > 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 -1.3458 0.2185 0.6178 0.96 -0.9544 -0.998 s.e. 0.2111 0.4200 0.2137 NaN 0.5350 NaN sigma^2 estimated as 97190: log likelihood = -145.88, aic = 305.76 Warning message: In sqrt(diag(x$var.coef)) : NaNs produced > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 34 End = 61 Frequency = 1 [1] 2474.076 2452.210 2874.248 3472.475 2838.532 2987.803 2501.813 2815.066 [9] 2837.808 2402.194 2609.125 2320.614 2783.874 2412.434 3155.226 3472.880 [17] 3070.636 3044.955 2671.693 2938.163 2940.404 2591.805 2648.247 2568.610 [25] 2771.648 2703.077 3110.459 3784.908 $se Time Series: Start = 34 End = 61 Frequency = 1 [1] 329.9159 380.9833 412.3419 419.4004 428.9785 429.2294 433.7076 432.3259 [9] 435.0209 433.1973 434.9238 433.2480 565.4728 606.9105 633.5366 641.5323 [17] 649.9491 651.2921 654.6143 654.6231 655.8704 656.1098 656.1463 657.1300 [25] 757.2394 801.5063 823.6084 835.1085 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 34 End = 61 Frequency = 1 [1] 1827.441 1705.482 2066.058 2650.451 1997.734 2146.514 1651.746 1967.707 [9] 1985.167 1553.128 1756.674 1471.448 1675.548 1222.889 1913.494 2215.477 [17] 1796.736 1768.423 1388.649 1655.101 1654.898 1305.830 1362.201 1280.635 [25] 1287.459 1132.124 1496.186 2148.096 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 34 End = 61 Frequency = 1 [1] 3120.711 3198.937 3682.438 4294.500 3679.330 3829.093 3351.880 3662.425 [9] 3690.449 3251.261 3461.576 3169.780 3892.201 3601.979 4396.957 4730.283 [17] 4344.536 4321.488 3954.737 4221.224 4225.910 3877.780 3934.294 3856.585 [25] 4255.837 4274.029 4724.732 5421.721 > 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] 2360.000 2214.000 2825.000 2355.000 2333.000 3016.000 2155.000 2172.000 [9] 2150.000 2533.000 2058.000 2160.000 2260.000 2498.000 2695.000 2799.000 [17] 2947.000 2930.000 2318.000 2540.000 2570.000 2669.000 2450.000 2842.000 [25] 3440.000 2678.000 2981.000 2260.000 2844.000 2546.000 2456.000 2295.000 [33] 2379.000 2474.076 2452.210 2874.248 3472.475 2838.532 2987.803 2501.813 [41] 2815.066 2837.808 2402.194 2609.125 2320.614 2783.874 2412.434 3155.226 [49] 3472.880 3070.636 3044.955 2671.693 2938.163 2940.404 2591.805 2648.247 [57] 2568.610 2771.648 2703.077 3110.459 3784.908 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 34 End = 61 Frequency = 1 [1] 0.1333491 0.1553633 0.1434608 0.1207785 0.1511269 0.1436605 0.1733573 [8] 0.1535758 0.1532947 0.1803340 0.1666934 0.1866954 0.2031244 0.2515760 [15] 0.2007896 0.1847263 0.2116659 0.2138922 0.2450185 0.2228002 0.2230545 [22] 0.2531478 0.2477662 0.2558310 0.2732091 0.2965163 0.2647868 0.2206417 > postscript(file="/var/www/html/rcomp/tmp/1qtb41260735824.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/2jfmw1260735824.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/38dzk1260735824.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/41v6l1260735824.tab") > try(system("convert tmp/1qtb41260735824.ps tmp/1qtb41260735824.png",intern=TRUE)) character(0) > try(system("convert tmp/2jfmw1260735824.ps tmp/2jfmw1260735824.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.134 0.322 1.266